| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <dlfcn.h> | 5 #include <dlfcn.h> |
| 6 | 6 |
| 7 #include "base/singleton.h" | 7 #include "base/singleton.h" |
| 8 #include "app/surface/io_surface_support_mac.h" | 8 #include "app/surface/io_surface_support_mac.h" |
| 9 | 9 |
| 10 typedef CFTypeRef (*IOSurfaceCreateProcPtr)(CFDictionaryRef properties); | 10 typedef CFTypeRef (*IOSurfaceCreateProcPtr)(CFDictionaryRef properties); |
| 11 typedef uint32 (*IOSurfaceGetIDProcPtr)(CFTypeRef io_surface); | 11 typedef uint32 (*IOSurfaceGetIDProcPtr)(CFTypeRef io_surface); |
| 12 typedef CFTypeRef (*IOSurfaceLookupProcPtr)(uint32 io_surface_id); | 12 typedef CFTypeRef (*IOSurfaceLookupProcPtr)(uint32 io_surface_id); |
| 13 typedef mach_port_t (*IOSurfaceCreateMachPortProcPtr)(CFTypeRef io_surface); | 13 typedef mach_port_t (*IOSurfaceCreateMachPortProcPtr)(CFTypeRef io_surface); |
| 14 typedef CFTypeRef (*IOSurfaceLookupFromMachPortProcPtr)(mach_port_t port); | 14 typedef CFTypeRef (*IOSurfaceLookupFromMachPortProcPtr)(mach_port_t port); |
| 15 typedef size_t (*IOSurfaceGetWidthPtr)(CFTypeRef io_surface); |
| 16 typedef size_t (*IOSurfaceGetHeightPtr)(CFTypeRef io_surface); |
| 15 typedef CGLError (*CGLTexImageIOSurface2DProcPtr)(CGLContextObj ctx, | 17 typedef CGLError (*CGLTexImageIOSurface2DProcPtr)(CGLContextObj ctx, |
| 16 GLenum target, | 18 GLenum target, |
| 17 GLenum internal_format, | 19 GLenum internal_format, |
| 18 GLsizei width, | 20 GLsizei width, |
| 19 GLsizei height, | 21 GLsizei height, |
| 20 GLenum format, | 22 GLenum format, |
| 21 GLenum type, | 23 GLenum type, |
| 22 CFTypeRef io_surface, | 24 CFTypeRef io_surface, |
| 23 GLuint plane); | 25 GLuint plane); |
| 24 | 26 |
| 25 class IOSurfaceSupportImpl : public IOSurfaceSupport { | 27 class IOSurfaceSupportImpl : public IOSurfaceSupport { |
| 26 public: | 28 public: |
| 27 static IOSurfaceSupportImpl* Initialize(); | 29 static IOSurfaceSupportImpl* Initialize(); |
| 28 | 30 |
| 29 bool InitializedSuccessfully() { | 31 bool InitializedSuccessfully() { |
| 30 return initialized_successfully_; | 32 return initialized_successfully_; |
| 31 } | 33 } |
| 32 | 34 |
| 33 virtual CFStringRef GetKIOSurfaceWidth(); | 35 virtual CFStringRef GetKIOSurfaceWidth(); |
| 34 virtual CFStringRef GetKIOSurfaceHeight(); | 36 virtual CFStringRef GetKIOSurfaceHeight(); |
| 35 virtual CFStringRef GetKIOSurfaceBytesPerElement(); | 37 virtual CFStringRef GetKIOSurfaceBytesPerElement(); |
| 36 virtual CFStringRef GetKIOSurfaceIsGlobal(); | 38 virtual CFStringRef GetKIOSurfaceIsGlobal(); |
| 37 | 39 |
| 38 virtual CFTypeRef IOSurfaceCreate(CFDictionaryRef properties); | 40 virtual CFTypeRef IOSurfaceCreate(CFDictionaryRef properties); |
| 39 virtual uint32 IOSurfaceGetID(CFTypeRef io_surface); | 41 virtual uint32 IOSurfaceGetID(CFTypeRef io_surface); |
| 40 virtual CFTypeRef IOSurfaceLookup(uint32 io_surface_id); | 42 virtual CFTypeRef IOSurfaceLookup(uint32 io_surface_id); |
| 41 virtual mach_port_t IOSurfaceCreateMachPort(CFTypeRef io_surface); | 43 virtual mach_port_t IOSurfaceCreateMachPort(CFTypeRef io_surface); |
| 42 virtual CFTypeRef IOSurfaceLookupFromMachPort(mach_port_t port); | 44 virtual CFTypeRef IOSurfaceLookupFromMachPort(mach_port_t port); |
| 43 | 45 |
| 46 virtual size_t IOSurfaceGetWidth(CFTypeRef io_surface); |
| 47 virtual size_t IOSurfaceGetHeight(CFTypeRef io_surface); |
| 48 |
| 44 virtual CGLError CGLTexImageIOSurface2D(CGLContextObj ctx, | 49 virtual CGLError CGLTexImageIOSurface2D(CGLContextObj ctx, |
| 45 GLenum target, | 50 GLenum target, |
| 46 GLenum internal_format, | 51 GLenum internal_format, |
| 47 GLsizei width, | 52 GLsizei width, |
| 48 GLsizei height, | 53 GLsizei height, |
| 49 GLenum format, | 54 GLenum format, |
| 50 GLenum type, | 55 GLenum type, |
| 51 CFTypeRef io_surface, | 56 CFTypeRef io_surface, |
| 52 GLuint plane); | 57 GLuint plane); |
| 53 | 58 |
| 54 private: | 59 private: |
| 55 IOSurfaceSupportImpl(); | 60 IOSurfaceSupportImpl(); |
| 56 ~IOSurfaceSupportImpl(); | 61 ~IOSurfaceSupportImpl(); |
| 57 | 62 |
| 58 void* iosurface_handle_; | 63 void* iosurface_handle_; |
| 59 void* opengl_handle_; | 64 void* opengl_handle_; |
| 60 CFStringRef k_io_surface_width_; | 65 CFStringRef k_io_surface_width_; |
| 61 CFStringRef k_io_surface_height_; | 66 CFStringRef k_io_surface_height_; |
| 62 CFStringRef k_io_surface_bytes_per_element_; | 67 CFStringRef k_io_surface_bytes_per_element_; |
| 63 CFStringRef k_io_surface_is_global_; | 68 CFStringRef k_io_surface_is_global_; |
| 64 IOSurfaceCreateProcPtr io_surface_create_; | 69 IOSurfaceCreateProcPtr io_surface_create_; |
| 65 IOSurfaceGetIDProcPtr io_surface_get_id_; | 70 IOSurfaceGetIDProcPtr io_surface_get_id_; |
| 66 IOSurfaceLookupProcPtr io_surface_lookup_; | 71 IOSurfaceLookupProcPtr io_surface_lookup_; |
| 67 IOSurfaceCreateMachPortProcPtr io_surface_create_mach_port_; | 72 IOSurfaceCreateMachPortProcPtr io_surface_create_mach_port_; |
| 68 IOSurfaceLookupFromMachPortProcPtr io_surface_lookup_from_mach_port_; | 73 IOSurfaceLookupFromMachPortProcPtr io_surface_lookup_from_mach_port_; |
| 74 IOSurfaceGetWidthPtr io_surface_get_width_; |
| 75 IOSurfaceGetHeightPtr io_surface_get_height_; |
| 69 CGLTexImageIOSurface2DProcPtr cgl_tex_image_io_surface_2d_; | 76 CGLTexImageIOSurface2DProcPtr cgl_tex_image_io_surface_2d_; |
| 70 bool initialized_successfully_; | 77 bool initialized_successfully_; |
| 71 | 78 |
| 72 friend struct DefaultSingletonTraits<IOSurfaceSupportImpl>; | 79 friend struct DefaultSingletonTraits<IOSurfaceSupportImpl>; |
| 73 DISALLOW_COPY_AND_ASSIGN(IOSurfaceSupportImpl); | 80 DISALLOW_COPY_AND_ASSIGN(IOSurfaceSupportImpl); |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 static Singleton<IOSurfaceSupportImpl> sole_instance_; | 83 static Singleton<IOSurfaceSupportImpl> sole_instance_; |
| 77 | 84 |
| 78 IOSurfaceSupportImpl* IOSurfaceSupportImpl::Initialize() { | 85 IOSurfaceSupportImpl* IOSurfaceSupportImpl::Initialize() { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 120 |
| 114 mach_port_t IOSurfaceSupportImpl::IOSurfaceCreateMachPort( | 121 mach_port_t IOSurfaceSupportImpl::IOSurfaceCreateMachPort( |
| 115 CFTypeRef io_surface) { | 122 CFTypeRef io_surface) { |
| 116 return io_surface_create_mach_port_(io_surface); | 123 return io_surface_create_mach_port_(io_surface); |
| 117 } | 124 } |
| 118 | 125 |
| 119 CFTypeRef IOSurfaceSupportImpl::IOSurfaceLookupFromMachPort(mach_port_t port) { | 126 CFTypeRef IOSurfaceSupportImpl::IOSurfaceLookupFromMachPort(mach_port_t port) { |
| 120 return io_surface_lookup_from_mach_port_(port); | 127 return io_surface_lookup_from_mach_port_(port); |
| 121 } | 128 } |
| 122 | 129 |
| 130 size_t IOSurfaceSupportImpl::IOSurfaceGetWidth(CFTypeRef io_surface) { |
| 131 return io_surface_get_width_(io_surface); |
| 132 } |
| 133 |
| 134 size_t IOSurfaceSupportImpl::IOSurfaceGetHeight(CFTypeRef io_surface) { |
| 135 return io_surface_get_height_(io_surface); |
| 136 } |
| 137 |
| 138 |
| 123 CGLError IOSurfaceSupportImpl::CGLTexImageIOSurface2D(CGLContextObj ctx, | 139 CGLError IOSurfaceSupportImpl::CGLTexImageIOSurface2D(CGLContextObj ctx, |
| 124 GLenum target, | 140 GLenum target, |
| 125 GLenum internal_format, | 141 GLenum internal_format, |
| 126 GLsizei width, | 142 GLsizei width, |
| 127 GLsizei height, | 143 GLsizei height, |
| 128 GLenum format, | 144 GLenum format, |
| 129 GLenum type, | 145 GLenum type, |
| 130 CFTypeRef io_surface, | 146 CFTypeRef io_surface, |
| 131 GLuint plane) { | 147 GLuint plane) { |
| 132 return cgl_tex_image_io_surface_2d_(ctx, | 148 return cgl_tex_image_io_surface_2d_(ctx, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 145 opengl_handle_(NULL), | 161 opengl_handle_(NULL), |
| 146 k_io_surface_width_(NULL), | 162 k_io_surface_width_(NULL), |
| 147 k_io_surface_height_(NULL), | 163 k_io_surface_height_(NULL), |
| 148 k_io_surface_bytes_per_element_(NULL), | 164 k_io_surface_bytes_per_element_(NULL), |
| 149 k_io_surface_is_global_(NULL), | 165 k_io_surface_is_global_(NULL), |
| 150 io_surface_create_(NULL), | 166 io_surface_create_(NULL), |
| 151 io_surface_get_id_(NULL), | 167 io_surface_get_id_(NULL), |
| 152 io_surface_lookup_(NULL), | 168 io_surface_lookup_(NULL), |
| 153 io_surface_create_mach_port_(NULL), | 169 io_surface_create_mach_port_(NULL), |
| 154 io_surface_lookup_from_mach_port_(NULL), | 170 io_surface_lookup_from_mach_port_(NULL), |
| 171 io_surface_get_width_(NULL), |
| 172 io_surface_get_height_(NULL), |
| 155 cgl_tex_image_io_surface_2d_(NULL), | 173 cgl_tex_image_io_surface_2d_(NULL), |
| 156 initialized_successfully_(false) { | 174 initialized_successfully_(false) { |
| 157 iosurface_handle_ = dlopen( | 175 iosurface_handle_ = dlopen( |
| 158 "/System/Library/Frameworks/IOSurface.framework/IOSurface", | 176 "/System/Library/Frameworks/IOSurface.framework/IOSurface", |
| 159 RTLD_LAZY | RTLD_LOCAL); | 177 RTLD_LAZY | RTLD_LOCAL); |
| 160 if (!iosurface_handle_) | 178 if (!iosurface_handle_) |
| 161 return; | 179 return; |
| 162 opengl_handle_ = dlopen( | 180 opengl_handle_ = dlopen( |
| 163 "/System/Library/Frameworks/OpenGL.framework/OpenGL", | 181 "/System/Library/Frameworks/OpenGL.framework/OpenGL", |
| 164 RTLD_LAZY | RTLD_LOCAL); | 182 RTLD_LAZY | RTLD_LOCAL); |
| 165 if (!opengl_handle_) { | 183 if (!opengl_handle_) { |
| 166 dlclose(iosurface_handle_); | 184 dlclose(iosurface_handle_); |
| 167 iosurface_handle_ = NULL; | 185 iosurface_handle_ = NULL; |
| 168 return; | 186 return; |
| 169 } | 187 } |
| 170 | 188 |
| 171 void* surface_width_ptr = dlsym(iosurface_handle_, "kIOSurfaceWidth"); | 189 void* surface_width_ptr = dlsym(iosurface_handle_, "kIOSurfaceWidth"); |
| 172 void* surface_height_ptr = dlsym(iosurface_handle_, "kIOSurfaceHeight"); | 190 void* surface_height_ptr = dlsym(iosurface_handle_, "kIOSurfaceHeight"); |
| 173 void* surface_bytes_per_element_ptr = | 191 void* surface_bytes_per_element_ptr = |
| 174 dlsym(iosurface_handle_, "kIOSurfaceBytesPerElement"); | 192 dlsym(iosurface_handle_, "kIOSurfaceBytesPerElement"); |
| 175 void* surface_is_global_ptr = | 193 void* surface_is_global_ptr = |
| 176 dlsym(iosurface_handle_, "kIOSurfaceIsGlobal"); | 194 dlsym(iosurface_handle_, "kIOSurfaceIsGlobal"); |
| 177 void* surface_create_ptr = dlsym(iosurface_handle_, "IOSurfaceCreate"); | 195 void* surface_create_ptr = dlsym(iosurface_handle_, "IOSurfaceCreate"); |
| 178 void* surface_get_id_ptr = dlsym(iosurface_handle_, "IOSurfaceGetID"); | 196 void* surface_get_id_ptr = dlsym(iosurface_handle_, "IOSurfaceGetID"); |
| 179 void* surface_lookup_ptr = dlsym(iosurface_handle_, "IOSurfaceLookup"); | 197 void* surface_lookup_ptr = dlsym(iosurface_handle_, "IOSurfaceLookup"); |
| 180 void* surface_create_mach_port_ptr = | 198 void* surface_create_mach_port_ptr = |
| 181 dlsym(iosurface_handle_, "IOSurfaceCreateMachPort"); | 199 dlsym(iosurface_handle_, "IOSurfaceCreateMachPort"); |
| 182 void* surface_lookup_from_mach_port_ptr = | 200 void* surface_lookup_from_mach_port_ptr = |
| 183 dlsym(iosurface_handle_, "IOSurfaceLookupFromMachPort"); | 201 dlsym(iosurface_handle_, "IOSurfaceLookupFromMachPort"); |
| 202 void* io_surface_get_width_ptr = |
| 203 dlsym(iosurface_handle_, "IOSurfaceGetWidth"); |
| 204 void* io_surface_get_height_ptr = |
| 205 dlsym(iosurface_handle_, "IOSurfaceGetHeight"); |
| 184 void* tex_image_io_surface_2d_ptr = | 206 void* tex_image_io_surface_2d_ptr = |
| 185 dlsym(opengl_handle_, "CGLTexImageIOSurface2D"); | 207 dlsym(opengl_handle_, "CGLTexImageIOSurface2D"); |
| 186 if (!surface_width_ptr || | 208 if (!surface_width_ptr || |
| 187 !surface_height_ptr || | 209 !surface_height_ptr || |
| 188 !surface_bytes_per_element_ptr || | 210 !surface_bytes_per_element_ptr || |
| 189 !surface_is_global_ptr || | 211 !surface_is_global_ptr || |
| 190 !surface_create_ptr || | 212 !surface_create_ptr || |
| 191 !surface_get_id_ptr || | 213 !surface_get_id_ptr || |
| 192 !surface_lookup_ptr || | 214 !surface_lookup_ptr || |
| 193 !surface_create_mach_port_ptr || | 215 !surface_create_mach_port_ptr || |
| 194 !surface_lookup_from_mach_port_ptr || | 216 !surface_lookup_from_mach_port_ptr || |
| 217 !io_surface_get_width_ptr || |
| 218 !io_surface_get_height_ptr || |
| 195 !tex_image_io_surface_2d_ptr) { | 219 !tex_image_io_surface_2d_ptr) { |
| 196 dlclose(iosurface_handle_); | 220 dlclose(iosurface_handle_); |
| 197 iosurface_handle_ = NULL; | 221 iosurface_handle_ = NULL; |
| 198 dlclose(opengl_handle_); | 222 dlclose(opengl_handle_); |
| 199 opengl_handle_ = NULL; | 223 opengl_handle_ = NULL; |
| 200 return; | 224 return; |
| 201 } | 225 } |
| 202 | 226 |
| 203 k_io_surface_width_ = *static_cast<CFStringRef*>(surface_width_ptr); | 227 k_io_surface_width_ = *static_cast<CFStringRef*>(surface_width_ptr); |
| 204 k_io_surface_height_ = *static_cast<CFStringRef*>(surface_height_ptr); | 228 k_io_surface_height_ = *static_cast<CFStringRef*>(surface_height_ptr); |
| 205 k_io_surface_bytes_per_element_ = | 229 k_io_surface_bytes_per_element_ = |
| 206 *static_cast<CFStringRef*>(surface_bytes_per_element_ptr); | 230 *static_cast<CFStringRef*>(surface_bytes_per_element_ptr); |
| 207 k_io_surface_is_global_ = *static_cast<CFStringRef*>(surface_is_global_ptr); | 231 k_io_surface_is_global_ = *static_cast<CFStringRef*>(surface_is_global_ptr); |
| 208 io_surface_create_ = reinterpret_cast<IOSurfaceCreateProcPtr>( | 232 io_surface_create_ = reinterpret_cast<IOSurfaceCreateProcPtr>( |
| 209 surface_create_ptr); | 233 surface_create_ptr); |
| 210 io_surface_get_id_ = | 234 io_surface_get_id_ = |
| 211 reinterpret_cast<IOSurfaceGetIDProcPtr>(surface_get_id_ptr); | 235 reinterpret_cast<IOSurfaceGetIDProcPtr>(surface_get_id_ptr); |
| 212 io_surface_lookup_ = | 236 io_surface_lookup_ = |
| 213 reinterpret_cast<IOSurfaceLookupProcPtr>(surface_lookup_ptr); | 237 reinterpret_cast<IOSurfaceLookupProcPtr>(surface_lookup_ptr); |
| 214 io_surface_create_mach_port_ = | 238 io_surface_create_mach_port_ = |
| 215 reinterpret_cast<IOSurfaceCreateMachPortProcPtr>( | 239 reinterpret_cast<IOSurfaceCreateMachPortProcPtr>( |
| 216 surface_create_mach_port_ptr); | 240 surface_create_mach_port_ptr); |
| 217 io_surface_lookup_from_mach_port_ = | 241 io_surface_lookup_from_mach_port_ = |
| 218 reinterpret_cast<IOSurfaceLookupFromMachPortProcPtr>( | 242 reinterpret_cast<IOSurfaceLookupFromMachPortProcPtr>( |
| 219 surface_lookup_from_mach_port_ptr); | 243 surface_lookup_from_mach_port_ptr); |
| 244 io_surface_get_width_ = |
| 245 reinterpret_cast<IOSurfaceGetWidthPtr>( |
| 246 io_surface_get_width_ptr); |
| 247 io_surface_get_height_ = |
| 248 reinterpret_cast<IOSurfaceGetHeightPtr>( |
| 249 io_surface_get_height_ptr); |
| 220 cgl_tex_image_io_surface_2d_ = | 250 cgl_tex_image_io_surface_2d_ = |
| 221 reinterpret_cast<CGLTexImageIOSurface2DProcPtr>( | 251 reinterpret_cast<CGLTexImageIOSurface2DProcPtr>( |
| 222 tex_image_io_surface_2d_ptr); | 252 tex_image_io_surface_2d_ptr); |
| 223 initialized_successfully_ = true; | 253 initialized_successfully_ = true; |
| 224 } | 254 } |
| 225 | 255 |
| 226 IOSurfaceSupportImpl::~IOSurfaceSupportImpl() { | 256 IOSurfaceSupportImpl::~IOSurfaceSupportImpl() { |
| 227 if (iosurface_handle_) | 257 if (iosurface_handle_) |
| 228 dlclose(iosurface_handle_); | 258 dlclose(iosurface_handle_); |
| 229 if (opengl_handle_) | 259 if (opengl_handle_) |
| 230 dlclose(opengl_handle_); | 260 dlclose(opengl_handle_); |
| 231 } | 261 } |
| 232 | 262 |
| 233 IOSurfaceSupport* IOSurfaceSupport::Initialize() { | 263 IOSurfaceSupport* IOSurfaceSupport::Initialize() { |
| 234 return IOSurfaceSupportImpl::Initialize(); | 264 return IOSurfaceSupportImpl::Initialize(); |
| 235 } | 265 } |
| 236 | 266 |
| 237 IOSurfaceSupport::IOSurfaceSupport() { | 267 IOSurfaceSupport::IOSurfaceSupport() { |
| 238 } | 268 } |
| 239 | 269 |
| 240 IOSurfaceSupport::~IOSurfaceSupport() { | 270 IOSurfaceSupport::~IOSurfaceSupport() { |
| 241 } | 271 } |
| 242 | 272 |
| OLD | NEW |