github.com/ckxng/wakeup@v0.0.0-20190105202853-90356a5f5a15/include/internal/cef_linux.h (about) 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 // Atomic increment and decrement. 41 inline long CefAtomicIncrement(long volatile *pDest) { // NOLINT(runtime/int) 42 return __sync_add_and_fetch(pDest, 1); 43 } 44 inline long CefAtomicDecrement(long volatile *pDest) { // NOLINT(runtime/int) 45 return __sync_sub_and_fetch(pDest, 1); 46 } 47 48 // Critical section wrapper. 49 class CefCriticalSection { 50 public: 51 CefCriticalSection() { 52 pthread_mutexattr_init(&attr_); 53 pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE); 54 pthread_mutex_init(&lock_, &attr_); 55 } 56 virtual ~CefCriticalSection() { 57 pthread_mutex_destroy(&lock_); 58 pthread_mutexattr_destroy(&attr_); 59 } 60 void Lock() { 61 pthread_mutex_lock(&lock_); 62 } 63 void Unlock() { 64 pthread_mutex_unlock(&lock_); 65 } 66 67 pthread_mutex_t lock_; 68 pthread_mutexattr_t attr_; 69 }; 70 71 // Handle types. 72 #define CefCursorHandle cef_cursor_handle_t 73 #define CefEventHandle cef_event_handle_t 74 #define CefWindowHandle cef_window_handle_t 75 #define CefTextInputContext cef_text_input_context_t 76 77 struct CefMainArgsTraits { 78 typedef cef_main_args_t struct_type; 79 80 static inline void init(struct_type* s) {} 81 static inline void clear(struct_type* s) {} 82 83 static inline void set(const struct_type* src, struct_type* target, 84 bool copy) { 85 target->argc = src->argc; 86 target->argv = src->argv; 87 } 88 }; 89 90 // Class representing CefExecuteProcess arguments. 91 class CefMainArgs : public CefStructBase<CefMainArgsTraits> { 92 public: 93 typedef CefStructBase<CefMainArgsTraits> parent; 94 95 CefMainArgs() : parent() {} 96 explicit CefMainArgs(const cef_main_args_t& r) : parent(r) {} 97 explicit CefMainArgs(const CefMainArgs& r) : parent(r) {} 98 CefMainArgs(int argc_arg, char** argv_arg) : parent() { 99 argc = argc_arg; 100 argv = argv_arg; 101 } 102 }; 103 104 struct CefWindowInfoTraits { 105 typedef cef_window_info_t struct_type; 106 107 static inline void init(struct_type* s) {} 108 static inline void clear(struct_type* s) {} 109 110 static inline void set(const struct_type* src, struct_type* target, 111 bool copy) { 112 target->parent_widget = src->parent_widget; 113 target->window_rendering_disabled = src->window_rendering_disabled; 114 target->transparent_painting = src->transparent_painting; 115 target->widget = src->widget; 116 } 117 }; 118 119 // Class representing window information. 120 class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> { 121 public: 122 typedef CefStructBase<CefWindowInfoTraits> parent; 123 124 CefWindowInfo() : parent() {} 125 explicit CefWindowInfo(const cef_window_info_t& r) : parent(r) {} 126 explicit CefWindowInfo(const CefWindowInfo& r) : parent(r) {} 127 128 void SetAsChild(CefWindowHandle ParentWidget) { 129 parent_widget = ParentWidget; 130 } 131 132 void SetTransparentPainting(bool transparentPainting) { 133 transparent_painting = transparentPainting; 134 } 135 136 void SetAsOffScreen(CefWindowHandle ParentWidget) { 137 window_rendering_disabled = true; 138 parent_widget = ParentWidget; 139 } 140 }; 141 142 #endif // OS_LINUX 143 144 #endif // CEF_INCLUDE_INTERNAL_CEF_LINUX_H_