|
| 1 | +// Copyright (c) 2010 Marshall A. Greenblatt. All rights reserved. |
| 2 | +// |
| 3 | +// Redistribution and use in source and binary forms, with or without |
| 4 | +// modification, are permitted provided that the following conditions are |
| 5 | +// met: |
| 6 | +// |
| 7 | +// * Redistributions of source code must retain the above copyright |
| 8 | +// notice, this list of conditions and the following disclaimer. |
| 9 | +// * Redistributions in binary form must reproduce the above |
| 10 | +// copyright notice, this list of conditions and the following disclaimer |
| 11 | +// in the documentation and/or other materials provided with the |
| 12 | +// distribution. |
| 13 | +// * Neither the name of Google Inc. nor the name Chromium Embedded |
| 14 | +// Framework nor the names of its contributors may be used to endorse |
| 15 | +// or promote products derived from this software without specific prior |
| 16 | +// written permission. |
| 17 | +// |
| 18 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | + |
| 30 | + |
| 31 | +#ifndef CEF_INCLUDE_INTERNAL_CEF_LINUX_H_ |
| 32 | +#define CEF_INCLUDE_INTERNAL_CEF_LINUX_H_ |
| 33 | +#pragma once |
| 34 | + |
| 35 | +#if defined(OS_LINUX) |
| 36 | +#include <pthread.h> |
| 37 | +#include "include/internal/cef_types_linux.h" |
| 38 | +#include "include/internal/cef_types_wrappers.h" |
| 39 | + |
| 40 | +/// |
| 41 | +// Atomic increment and decrement. |
| 42 | +/// |
| 43 | +inline long CefAtomicIncrement(long volatile *pDest) { // NOLINT(runtime/int) |
| 44 | + return __sync_add_and_fetch(pDest, 1); |
| 45 | +} |
| 46 | +inline long CefAtomicDecrement(long volatile *pDest) { // NOLINT(runtime/int) |
| 47 | + return __sync_sub_and_fetch(pDest, 1); |
| 48 | +} |
| 49 | + |
| 50 | +/// |
| 51 | +// Critical section wrapper. |
| 52 | +/// |
| 53 | +class CefCriticalSection { |
| 54 | + public: |
| 55 | + CefCriticalSection() { |
| 56 | + pthread_mutexattr_init(&attr_); |
| 57 | + pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE); |
| 58 | + pthread_mutex_init(&lock_, &attr_); |
| 59 | + } |
| 60 | + virtual ~CefCriticalSection() { |
| 61 | + pthread_mutex_destroy(&lock_); |
| 62 | + pthread_mutexattr_destroy(&attr_); |
| 63 | + } |
| 64 | + void Lock() { |
| 65 | + pthread_mutex_lock(&lock_); |
| 66 | + } |
| 67 | + void Unlock() { |
| 68 | + pthread_mutex_unlock(&lock_); |
| 69 | + } |
| 70 | + |
| 71 | + pthread_mutex_t lock_; |
| 72 | + pthread_mutexattr_t attr_; |
| 73 | +}; |
| 74 | + |
| 75 | +/// |
| 76 | +// Handle types. |
| 77 | +/// |
| 78 | +#define CefWindowHandle cef_window_handle_t |
| 79 | +#define CefCursorHandle cef_cursor_handle_t |
| 80 | + |
| 81 | + |
| 82 | +struct CefWindowInfoTraits { |
| 83 | + typedef cef_window_info_t struct_type; |
| 84 | + |
| 85 | + static inline void init(struct_type* s) {} |
| 86 | + static inline void clear(struct_type* s) {} |
| 87 | + |
| 88 | + static inline void set(const struct_type* src, struct_type* target, |
| 89 | + bool copy) { |
| 90 | + target->m_Widget = src->m_Widget; |
| 91 | + target->m_ParentWidget = src->m_ParentWidget; |
| 92 | + } |
| 93 | +}; |
| 94 | + |
| 95 | +/// |
| 96 | +// Class representing window information. |
| 97 | +/// |
| 98 | +class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> { |
| 99 | + public: |
| 100 | + typedef CefStructBase<CefWindowInfoTraits> parent; |
| 101 | + |
| 102 | + CefWindowInfo() : parent() {} |
| 103 | + explicit CefWindowInfo(const cef_window_info_t& r) : parent(r) {} |
| 104 | + explicit CefWindowInfo(const CefWindowInfo& r) : parent(r) {} |
| 105 | + |
| 106 | + void SetAsChild(CefWindowHandle ParentWidget) { |
| 107 | + m_ParentWidget = ParentWidget; |
| 108 | + } |
| 109 | +}; |
| 110 | + |
| 111 | + |
| 112 | +struct CefPrintInfoTraits { |
| 113 | + typedef cef_print_info_t struct_type; |
| 114 | + |
| 115 | + static inline void init(struct_type* s) {} |
| 116 | + static inline void clear(struct_type* s) {} |
| 117 | + |
| 118 | + static inline void set(const struct_type* src, struct_type* target, |
| 119 | + bool copy) { |
| 120 | + target->m_Scale = src->m_Scale; |
| 121 | + } |
| 122 | +}; |
| 123 | + |
| 124 | +/// |
| 125 | +// Class representing print context information. |
| 126 | +/// |
| 127 | +typedef CefStructBase<CefPrintInfoTraits> CefPrintInfo; |
| 128 | + |
| 129 | + |
| 130 | +struct CefKeyInfoTraits { |
| 131 | + typedef cef_key_info_t struct_type; |
| 132 | + |
| 133 | + static inline void init(struct_type* s) {} |
| 134 | + static inline void clear(struct_type* s) {} |
| 135 | + |
| 136 | + static inline void set(const struct_type* src, struct_type* target, |
| 137 | + bool copy) { |
| 138 | + target->key = src->key; |
| 139 | + } |
| 140 | +}; |
| 141 | + |
| 142 | +/// |
| 143 | +// Class representing key information. |
| 144 | +/// |
| 145 | +typedef CefStructBase<CefKeyInfoTraits> CefKeyInfo; |
| 146 | + |
| 147 | +#endif // OS_LINUX |
| 148 | + |
| 149 | +#endif // CEF_INCLUDE_INTERNAL_CEF_LINUX_H_ |
0 commit comments