diff options
author | ccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-04 09:25:53 +0000 |
---|---|---|
committer | ccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-04 09:25:53 +0000 |
commit | c3a6b4a7ad8dfff007c880035b256a77c5cd923b (patch) | |
tree | b6220d00432ccef4c19b2843d04100527dec4633 | |
parent | 391bbe5ceb83b7df4a856838d20dd10a13dd6954 (diff) | |
download | chromium_src-c3a6b4a7ad8dfff007c880035b256a77c5cd923b.zip chromium_src-c3a6b4a7ad8dfff007c880035b256a77c5cd923b.tar.gz chromium_src-c3a6b4a7ad8dfff007c880035b256a77c5cd923b.tar.bz2 |
Remove IOSurfaceSupport
Link against IOSurface.framework instead -- this is an option starting in 10.6.
BUG=314190
Review URL: https://codereview.chromium.org/301973010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274746 0039d316-1c4b-4281-b951-d872f2087c98
26 files changed, 120 insertions, 658 deletions
diff --git a/chrome/test/gpu/gpu_feature_browsertest.cc b/chrome/test/gpu/gpu_feature_browsertest.cc index c2ebe8b..2bea73f 100644 --- a/chrome/test/gpu/gpu_feature_browsertest.cc +++ b/chrome/test/gpu/gpu_feature_browsertest.cc @@ -26,10 +26,6 @@ #include "net/base/filename_util.h" #include "ui/gl/gl_implementation.h" -#if defined(OS_MACOSX) -#include "ui/gl/io_surface_support_mac.h" -#endif - #if defined(OS_WIN) #include "base/win/windows_version.h" #endif @@ -118,11 +114,6 @@ class GpuFeatureTest : public InProcessBrowserTest { if (gfx::GetGLImplementation() != gfx::kGLImplementationOSMesaGL) return; #endif -#if defined(OS_MACOSX) - // Bypass tests on Mac OSX 10.5 bots (IOSurfaceSupport is now required). - if (!IOSurfaceSupport::Initialize()) - return; -#endif ASSERT_TRUE(tracing::BeginTracing(category_patterns_)); @@ -431,9 +422,6 @@ IN_PROC_BROWSER_TEST_F(GpuFeatureTest, MAYBE_RafNoDamage) { #if defined(OS_MACOSX) IN_PROC_BROWSER_TEST_F(GpuFeatureTest, IOSurfaceReuse) { - if (!IOSurfaceSupport::Initialize()) - return; - if (gpu::GPUTestBotConfig::GpuBlacklistedOnBot()) return; diff --git a/content/browser/renderer_host/compositing_iosurface_mac.h b/content/browser/renderer_host/compositing_iosurface_mac.h index b1984d1..d632f52 100644 --- a/content/browser/renderer_host/compositing_iosurface_mac.h +++ b/content/browser/renderer_host/compositing_iosurface_mac.h @@ -10,6 +10,7 @@ #include <vector> #import <Cocoa/Cocoa.h> +#include <IOSurface/IOSurfaceAPI.h> #include <QuartzCore/QuartzCore.h> #include "base/callback.h" @@ -25,7 +26,6 @@ #include "ui/gfx/rect_conversions.h" #include "ui/gfx/size.h" -class IOSurfaceSupport; class SkBitmap; namespace gfx { @@ -46,7 +46,7 @@ class RenderWidgetHostViewMac; class CompositingIOSurfaceMac : public base::RefCounted<CompositingIOSurfaceMac> { public: - // Returns NULL if IOSurface support is missing or GL APIs fail. + // Returns NULL if IOSurface or GL API calls fail. static scoped_refptr<CompositingIOSurfaceMac> Create(); // Set IOSurface that will be drawn on the next NSView drawRect. @@ -204,7 +204,6 @@ class CompositingIOSurfaceMac }; CompositingIOSurfaceMac( - IOSurfaceSupport* io_surface_support, const scoped_refptr<CompositingIOSurfaceContext>& context); ~CompositingIOSurfaceMac(); @@ -273,9 +272,6 @@ class CompositingIOSurfaceMac gfx::Rect IntersectWithIOSurface(const gfx::Rect& rect) const; - // Cached pointer to IOSurfaceSupport Singleton. - IOSurfaceSupport* io_surface_support_; - // Offscreen context used for all operations other than drawing to the // screen. This is in the same share group as the contexts used for // drawing, and is the same for all IOSurfaces in all windows. @@ -283,7 +279,7 @@ class CompositingIOSurfaceMac // IOSurface data. uint64 io_surface_handle_; - base::ScopedCFTypeRef<CFTypeRef> io_surface_; + base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; // The width and height of the io surface. gfx::Size pixel_io_surface_size_; // In pixels. diff --git a/content/browser/renderer_host/compositing_iosurface_mac.mm b/content/browser/renderer_host/compositing_iosurface_mac.mm index e6fae6b..5280fd5 100644 --- a/content/browser/renderer_host/compositing_iosurface_mac.mm +++ b/content/browser/renderer_host/compositing_iosurface_mac.mm @@ -4,6 +4,7 @@ #include "content/browser/renderer_host/compositing_iosurface_mac.h" +#include <OpenGL/CGLIOSurface.h> #include <OpenGL/CGLRenderers.h> #include <OpenGL/OpenGL.h> @@ -28,7 +29,6 @@ #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" #include "ui/gfx/size_conversions.h" #include "ui/gl/gl_context.h" -#include "ui/gl/io_surface_support_mac.h" #ifdef NDEBUG #define CHECK_GL_ERROR() @@ -218,12 +218,6 @@ void CompositingIOSurfaceMac::CopyContext::PrepareForAsynchronousReadback() { // static scoped_refptr<CompositingIOSurfaceMac> CompositingIOSurfaceMac::Create() { - IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); - if (!io_surface_support) { - LOG(ERROR) << "No IOSurface support"; - return NULL; - } - scoped_refptr<CompositingIOSurfaceContext> offscreen_context = CompositingIOSurfaceContext::Get( CompositingIOSurfaceContext::kOffscreenContextWindowNumber); @@ -232,15 +226,12 @@ scoped_refptr<CompositingIOSurfaceMac> CompositingIOSurfaceMac::Create() { return NULL; } - return new CompositingIOSurfaceMac(io_surface_support, - offscreen_context); + return new CompositingIOSurfaceMac(offscreen_context); } CompositingIOSurfaceMac::CompositingIOSurfaceMac( - IOSurfaceSupport* io_surface_support, const scoped_refptr<CompositingIOSurfaceContext>& offscreen_context) - : io_surface_support_(io_surface_support), - offscreen_context_(offscreen_context), + : offscreen_context_(offscreen_context), io_surface_handle_(0), scale_factor_(1.f), texture_(0), @@ -493,8 +484,7 @@ bool CompositingIOSurfaceMac::MapIOSurfaceToTextureWithContextCurrent( if (io_surface_ && io_surface_handle == io_surface_handle_) return true; - io_surface_.reset(io_surface_support_->IOSurfaceLookup( - static_cast<uint32>(io_surface_handle))); + io_surface_.reset(IOSurfaceLookup(static_cast<uint32>(io_surface_handle))); // Can fail if IOSurface with that ID was already released by the gpu // process. if (!io_surface_) { @@ -506,9 +496,8 @@ bool CompositingIOSurfaceMac::MapIOSurfaceToTextureWithContextCurrent( // Actual IOSurface size is rounded up to reduce reallocations during window // resize. Get the actual size to properly map the texture. - gfx::Size rounded_size( - io_surface_support_->IOSurfaceGetWidth(io_surface_), - io_surface_support_->IOSurfaceGetHeight(io_surface_)); + gfx::Size rounded_size(IOSurfaceGetWidth(io_surface_), + IOSurfaceGetHeight(io_surface_)); glGenTextures(1, &texture_); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); @@ -516,7 +505,7 @@ bool CompositingIOSurfaceMac::MapIOSurfaceToTextureWithContextCurrent( glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_AND_SAVE_GL_ERROR(); GLuint plane = 0; - CGLError cgl_error = io_surface_support_->CGLTexImageIOSurface2D( + CGLError cgl_error = CGLTexImageIOSurface2D( current_context->cgl_context(), GL_TEXTURE_RECTANGLE_ARB, GL_RGBA, diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 23b52ec..8ed6424 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -161,7 +161,6 @@ #if defined(OS_MACOSX) #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" -#include "ui/gl/io_surface_support_mac.h" #endif #if defined(OS_WIN) @@ -2172,44 +2171,38 @@ void RenderProcessHostImpl::OnAllocateGpuMemoryBuffer(uint32 width, // GpuMemoryBufferImplIOSurface. crbug.com/325045, crbug.com/323304 if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(internalformat, usage)) { - IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); - if (io_surface_support) { - base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; - properties.reset( - CFDictionaryCreateMutable(kCFAllocatorDefault, - 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks)); - AddIntegerValue( - properties, io_surface_support->GetKIOSurfaceWidth(), width); - AddIntegerValue( - properties, io_surface_support->GetKIOSurfaceHeight(), height); - AddIntegerValue(properties, - io_surface_support->GetKIOSurfaceBytesPerElement(), - GpuMemoryBufferImpl::BytesPerPixel(internalformat)); - AddIntegerValue( - properties, - io_surface_support->GetKIOSurfacePixelFormat(), - GpuMemoryBufferImplIOSurface::PixelFormat(internalformat)); - // TODO(reveman): Remove this when using a mach_port_t to transfer - // IOSurface to renderer process. crbug.com/323304 - AddBooleanValue( - properties, io_surface_support->GetKIOSurfaceIsGlobal(), true); - - base::ScopedCFTypeRef<CFTypeRef> io_surface( - io_surface_support->IOSurfaceCreate(properties)); - if (io_surface) { - gfx::GpuMemoryBufferHandle handle; - handle.type = gfx::IO_SURFACE_BUFFER; - handle.io_surface_id = io_surface_support->IOSurfaceGetID(io_surface); - - // TODO(reveman): This makes the assumption that the renderer will - // grab a reference to the surface before sending another message. - // crbug.com/325045 - last_io_surface_ = io_surface; - GpuMemoryBufferAllocated(reply, handle); - return; - } + base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; + properties.reset( + CFDictionaryCreateMutable(kCFAllocatorDefault, + 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks)); + AddIntegerValue(properties, kIOSurfaceWidth, width); + AddIntegerValue(properties, kIOSurfaceHeight, height); + AddIntegerValue(properties, + kIOSurfaceBytesPerElement, + GpuMemoryBufferImpl::BytesPerPixel(internalformat)); + AddIntegerValue( + properties, + kIOSurfacePixelFormat, + GpuMemoryBufferImplIOSurface::PixelFormat(internalformat)); + // TODO(reveman): Remove this when using a mach_port_t to transfer + // IOSurface to renderer process. crbug.com/323304 + AddBooleanValue( + properties, kIOSurfaceIsGlobal, true); + + base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); + if (io_surface) { + gfx::GpuMemoryBufferHandle handle; + handle.type = gfx::IO_SURFACE_BUFFER; + handle.io_surface_id = IOSurfaceGetID(io_surface); + + // TODO(reveman): This makes the assumption that the renderer will + // grab a reference to the surface before sending another message. + // crbug.com/325045 + last_io_surface_ = io_surface; + GpuMemoryBufferAllocated(reply, handle); + return; } } #endif diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h index 89b7255..e2c7b24 100644 --- a/content/browser/renderer_host/render_process_host_impl.h +++ b/content/browser/renderer_host/render_process_host_impl.h @@ -23,6 +23,7 @@ #include "mojo/public/cpp/bindings/interface_ptr.h" #if defined(OS_MACOSX) +#include <IOSurface/IOSurfaceAPI.h> #include "base/mac/scoped_cftyperef.h" #endif @@ -451,7 +452,7 @@ class CONTENT_EXPORT RenderProcessHostImpl base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_; #if defined(OS_MACOSX) - base::ScopedCFTypeRef<CFTypeRef> last_io_surface_; + base::ScopedCFTypeRef<IOSurfaceRef> last_io_surface_; #endif DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); diff --git a/content/browser/renderer_host/render_widget_helper_mac.mm b/content/browser/renderer_host/render_widget_helper_mac.mm index 4662782..4a16293 100644 --- a/content/browser/renderer_host/render_widget_helper_mac.mm +++ b/content/browser/renderer_host/render_widget_helper_mac.mm @@ -5,6 +5,7 @@ #include "content/browser/renderer_host/render_widget_helper.h" #import <Cocoa/Cocoa.h> +#include <IOSurface/IOSurfaceAPI.h> #include "base/bind.h" #include "content/browser/compositor/browser_compositor_view_mac.h" @@ -15,6 +16,7 @@ namespace { void OnNativeSurfaceBuffersSwappedOnUIThread( + base::ScopedCFTypeRef<IOSurfaceRef> io_surface, const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); gfx::AcceleratedWidget native_widget = @@ -39,20 +41,21 @@ void RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnIOThread( // and a potential deadlock. // TODO(ccameron): This immediate ack circumvents GPU back-pressure that // is necessary to throttle renderers. Fix that. - // TODO(ccameron): It is possible that the IOSurface will be deleted or - // reused soon as it is acked. Take out a reference to the IOSurface here, - // to ensure the IOSurface does not disappear before routing to the UI - // thread. AcceleratedSurfaceMsg_BufferPresented_Params ack_params; ack_params.sync_point = 0; ack_params.renderer_id = 0; gpu_process_host->Send(new AcceleratedSurfaceMsg_BufferPresented( params.route_id, ack_params)); + // Open the IOSurface handle before returning, to ensure that it is not + // closed as soon as the frame is acknowledged. + base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceLookup( + static_cast<uint32>(params.surface_handle))); + BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - base::Bind(&OnNativeSurfaceBuffersSwappedOnUIThread, params)); + base::Bind(&OnNativeSurfaceBuffersSwappedOnUIThread, io_surface, params)); } } // namespace content diff --git a/content/browser/renderer_host/render_widget_host_view_browsertest.cc b/content/browser/renderer_host/render_widget_host_view_browsertest.cc index 1c85aa7..e054f21 100644 --- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc +++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc @@ -33,10 +33,6 @@ #include "ui/gfx/switches.h" #include "ui/gl/gl_switches.h" -#if defined(OS_MACOSX) -#include "ui/gl/io_surface_support_mac.h" -#endif - #if defined(OS_WIN) #include "base/win/windows_version.h" #include "ui/gfx/win/dpi.h" @@ -223,10 +219,6 @@ class CompositingRenderWidgetHostViewBrowserTest } virtual bool SetUpSourceSurface(const char* wait_message) OVERRIDE { -#if defined(OS_MACOSX) - CHECK(IOSurfaceSupport::Initialize()); -#endif - content::DOMMessageQueue message_queue; NavigateToURL(shell(), TestUrl()); if (wait_message != NULL) { diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index 93e6414..8959bf3 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -74,7 +74,6 @@ #include "ui/gfx/screen.h" #include "ui/gfx/size_conversions.h" #include "ui/gl/gl_switches.h" -#include "ui/gl/io_surface_support_mac.h" using content::BrowserAccessibility; using content::BrowserAccessibilityManager; diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 67cf02f..1153590 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -103,7 +103,6 @@ #if defined(OS_MACOSX) #include "base/mac/foundation_util.h" -#include "ui/gl/io_surface_support_mac.h" #endif // Cross-Site Navigations diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc index 62732a1..06cb7ed 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc +++ b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc @@ -6,17 +6,13 @@ #include "base/logging.h" #include "ui/gl/gl_bindings.h" -#include "ui/gl/io_surface_support_mac.h" namespace content { GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( const gfx::Size& size, unsigned internalformat) - : GpuMemoryBufferImpl(size, internalformat), - io_surface_support_(IOSurfaceSupport::Initialize()) { - CHECK(io_surface_support_); -} + : GpuMemoryBufferImpl(size, internalformat) {} GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {} @@ -61,7 +57,7 @@ uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) { bool GpuMemoryBufferImplIOSurface::InitializeFromHandle( gfx::GpuMemoryBufferHandle handle) { DCHECK(IsFormatSupported(internalformat_)); - io_surface_.reset(io_surface_support_->IOSurfaceLookup(handle.io_surface_id)); + io_surface_.reset(IOSurfaceLookup(handle.io_surface_id)); if (!io_surface_) { VLOG(1) << "IOSurface lookup failed"; return false; @@ -72,25 +68,25 @@ bool GpuMemoryBufferImplIOSurface::InitializeFromHandle( void* GpuMemoryBufferImplIOSurface::Map() { DCHECK(!mapped_); - io_surface_support_->IOSurfaceLock(io_surface_, 0, NULL); + IOSurfaceLock(io_surface_, 0, NULL); mapped_ = true; - return io_surface_support_->IOSurfaceGetBaseAddress(io_surface_); + return IOSurfaceGetBaseAddress(io_surface_); } void GpuMemoryBufferImplIOSurface::Unmap() { DCHECK(mapped_); - io_surface_support_->IOSurfaceUnlock(io_surface_, 0, NULL); + IOSurfaceUnlock(io_surface_, 0, NULL); mapped_ = false; } uint32 GpuMemoryBufferImplIOSurface::GetStride() const { - return io_surface_support_->IOSurfaceGetBytesPerRow(io_surface_); + return IOSurfaceGetBytesPerRow(io_surface_); } gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { gfx::GpuMemoryBufferHandle handle; handle.type = gfx::IO_SURFACE_BUFFER; - handle.io_surface_id = io_surface_support_->IOSurfaceGetID(io_surface_); + handle.io_surface_id = IOSurfaceGetID(io_surface_); return handle; } diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h index 9f552bc..24bdcf7 100644 --- a/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h +++ b/content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h @@ -5,11 +5,11 @@ #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_IO_SURFACE_H_ #define CONTENT_COMMON_GPU_CLIENT_GPU_MEMORY_BUFFER_IMPL_IO_SURFACE_H_ +#include <IOSurface/IOSurfaceAPI.h> + #include "base/mac/scoped_cftyperef.h" #include "content/common/gpu/client/gpu_memory_buffer_impl.h" -class IOSurfaceSupport; - namespace content { // Implementation of GPU memory buffer based on IO surfaces. @@ -32,8 +32,7 @@ class GpuMemoryBufferImplIOSurface : public GpuMemoryBufferImpl { virtual gfx::GpuMemoryBufferHandle GetHandle() const OVERRIDE; private: - IOSurfaceSupport* io_surface_support_; - base::ScopedCFTypeRef<CFTypeRef> io_surface_; + base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImplIOSurface); }; diff --git a/content/common/gpu/image_transport_surface_mac.cc b/content/common/gpu/image_transport_surface_mac.cc index 4aebcf2..8341716 100644 --- a/content/common/gpu/image_transport_surface_mac.cc +++ b/content/common/gpu/image_transport_surface_mac.cc @@ -14,7 +14,9 @@ #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_surface_cgl.h" #include "ui/gl/gl_surface_osmesa.h" -#include "ui/gl/io_surface_support_mac.h" + +// Note that this must be included after gl_bindings.h to avoid conflicts. +#include <OpenGL/CGLIOSurface.h> namespace content { namespace { @@ -84,7 +86,7 @@ class IOSurfaceImageTransportSurface GLuint texture_id_; GLuint depth_stencil_renderbuffer_id_; - base::ScopedCFTypeRef<CFTypeRef> io_surface_; + base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; // The id of |io_surface_| or 0 if that's NULL. uint64 io_surface_handle_; @@ -383,8 +385,6 @@ void IOSurfaceImageTransportSurface::CreateIOSurface() { glGenFramebuffersEXT(1, &fbo_id_); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id_); - IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); - glGenTextures(1, &texture_id_); // GL_TEXTURE_RECTANGLE_ARB is the best supported render target on @@ -441,25 +441,25 @@ void IOSurfaceImageTransportSurface::CreateIOSurface() { &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); AddIntegerValue(properties, - io_surface_support->GetKIOSurfaceWidth(), + kIOSurfaceWidth, rounded_size_.width()); AddIntegerValue(properties, - io_surface_support->GetKIOSurfaceHeight(), + kIOSurfaceHeight, rounded_size_.height()); AddIntegerValue(properties, - io_surface_support->GetKIOSurfaceBytesPerElement(), 4); + kIOSurfaceBytesPerElement, 4); AddBooleanValue(properties, - io_surface_support->GetKIOSurfaceIsGlobal(), true); + kIOSurfaceIsGlobal, true); // I believe we should be able to unreference the IOSurfaces without // synchronizing with the browser process because they are // ultimately reference counted by the operating system. - io_surface_.reset(io_surface_support->IOSurfaceCreate(properties)); - io_surface_handle_ = io_surface_support->IOSurfaceGetID(io_surface_); + io_surface_.reset(IOSurfaceCreate(properties)); + io_surface_handle_ = IOSurfaceGetID(io_surface_); // Don't think we need to identify a plane. GLuint plane = 0; CGLError cglerror = - io_surface_support->CGLTexImageIOSurface2D( + CGLTexImageIOSurface2D( static_cast<CGLContextObj>(context_->GetHandle()), target, GL_RGBA, @@ -517,15 +517,10 @@ scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateNativeSurface( const gfx::GLSurfaceHandle& surface_handle) { DCHECK(surface_handle.transport_type == gfx::NATIVE_DIRECT || surface_handle.transport_type == gfx::NATIVE_TRANSPORT); - IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); switch (gfx::GetGLImplementation()) { case gfx::kGLImplementationDesktopGL: case gfx::kGLImplementationAppleGL: - if (!io_surface_support) { - DLOG(WARNING) << "No IOSurface support"; - return scoped_refptr<gfx::GLSurface>(); - } return scoped_refptr<gfx::GLSurface>(new IOSurfaceImageTransportSurface( manager, stub, surface_handle.handle)); diff --git a/content/common/sandbox_mac.mm b/content/common/sandbox_mac.mm index 94c3c3d..f4ea8d5 100644 --- a/content/common/sandbox_mac.mm +++ b/content/common/sandbox_mac.mm @@ -37,7 +37,6 @@ extern "C" { #include "third_party/icu/source/common/unicode/uchar.h" #include "ui/base/layout.h" #include "ui/gl/gl_surface.h" -#include "ui/gl/io_surface_support_mac.h" namespace content { namespace { @@ -306,11 +305,7 @@ void Sandbox::SandboxWarmup(int sandbox_type) { { // IOSurfaceLookup() - 10.7 // Needed by zero-copy texture update framework - crbug.com/323338 - IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); - if (io_surface_support) { - base::ScopedCFTypeRef<CFTypeRef> io_surface( - io_surface_support->IOSurfaceLookup(0)); - } + base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceLookup(0)); } // Process-type dependent warm-up. diff --git a/content/content_common.gypi b/content/content_common.gypi index 4a32f63..4735b7c 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -572,6 +572,7 @@ ], 'link_settings': { 'libraries': [ + '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', '$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework', ], }, diff --git a/content/plugin/webplugin_accelerated_surface_proxy_mac.cc b/content/plugin/webplugin_accelerated_surface_proxy_mac.cc index 3397b41..f011313 100644 --- a/content/plugin/webplugin_accelerated_surface_proxy_mac.cc +++ b/content/plugin/webplugin_accelerated_surface_proxy_mac.cc @@ -10,7 +10,6 @@ #include "base/command_line.h" #include "content/plugin/webplugin_proxy.h" #include "content/public/common/content_switches.h" -#include "ui/gl/io_surface_support_mac.h" #include "ui/surface/accelerated_surface_mac.h" #include "ui/surface/transport_dib.h" @@ -24,10 +23,6 @@ WebPluginAcceleratedSurfaceProxy* WebPluginAcceleratedSurfaceProxy::Create( DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableCoreAnimationPlugins)); - // Require IOSurface support for drawing Core Animation plugins. - if (!IOSurfaceSupport::Initialize()) - return NULL; - AcceleratedSurface* surface = new AcceleratedSurface; // It's possible for OpenGL to fail to initialize (e.g., if an incompatible // mode is forced via flags), so handle that gracefully. diff --git a/gpu/command_buffer/service/feature_info.cc b/gpu/command_buffer/service/feature_info.cc index 46f4d2e..94eb4cc 100644 --- a/gpu/command_buffer/service/feature_info.cc +++ b/gpu/command_buffer/service/feature_info.cc @@ -16,10 +16,6 @@ #include "gpu/command_buffer/service/gpu_switches.h" #include "ui/gl/gl_implementation.h" -#if defined(OS_MACOSX) -#include "ui/gl/io_surface_support_mac.h" -#endif - namespace gpu { namespace gles2 { @@ -670,9 +666,7 @@ void FeatureInfo::InitializeFeatures() { } #if defined(OS_MACOSX) - if (IOSurfaceSupport::Initialize()) { - AddExtensionString("GL_CHROMIUM_iosurface"); - } + AddExtensionString("GL_CHROMIUM_iosurface"); #endif // TODO(gman): Add support for these extensions. diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 19aadf2..9468126 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -65,7 +65,9 @@ #include "ui/gl/gl_surface.h" #if defined(OS_MACOSX) -#include "ui/gl/io_surface_support_mac.h" +#include <IOSurface/IOSurfaceAPI.h> +// Note that this must be included after gl_bindings.h to avoid conflicts. +#include <OpenGL/CGLIOSurface.h> #endif #if defined(OS_WIN) @@ -1760,7 +1762,7 @@ class GLES2DecoderImpl : public GLES2Decoder, bool service_logging_; #if defined(OS_MACOSX) - typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; + typedef std::map<GLuint, IOSurfaceRef> TextureToIOSurfaceMap; TextureToIOSurfaceMap texture_to_io_surface_map_; #endif @@ -9751,7 +9753,7 @@ void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { texture_id); if (it != texture_to_io_surface_map_.end()) { // Found a previous IOSurface bound to this texture; release it. - CFTypeRef surface = it->second; + IOSurfaceRef surface = it->second; CFRelease(surface); texture_to_io_surface_map_.erase(it); } @@ -9769,14 +9771,6 @@ void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( return; } - IOSurfaceSupport* surface_support = IOSurfaceSupport::Initialize(); - if (!surface_support) { - LOCAL_SET_GL_ERROR( - GL_INVALID_OPERATION, - "glTexImageIOSurface2DCHROMIUM", "only supported on 10.6."); - return; - } - if (target != GL_TEXTURE_RECTANGLE_ARB) { // This might be supported in the future, and if we could require // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we @@ -9805,7 +9799,7 @@ void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( // plugin process might allocate and release an IOSurface before // this process gets a chance to look it up. Hold on to any old // IOSurface in this case. - CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); + IOSurfaceRef surface = IOSurfaceLookup(io_surface_id); if (!surface) { LOCAL_SET_GL_ERROR( GL_INVALID_OPERATION, @@ -9823,7 +9817,7 @@ void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( CGLContextObj context = static_cast<CGLContextObj>(context_->GetHandle()); - CGLError err = surface_support->CGLTexImageIOSurface2D( + CGLError err = CGLTexImageIOSurface2D( context, target, GL_RGBA, diff --git a/ui/gl/BUILD.gn b/ui/gl/BUILD.gn index 5bd1aee..8ebb127 100644 --- a/ui/gl/BUILD.gn +++ b/ui/gl/BUILD.gn @@ -87,8 +87,6 @@ component("gl") { "gl_version_info.h", "gpu_switching_manager.cc", "gpu_switching_manager.h", - "io_surface_support_mac.cc", - "io_surface_support_mac.h", "scoped_binders.cc", "scoped_binders.h", "scoped_make_current.cc", diff --git a/ui/gl/gl.gyp b/ui/gl/gl.gyp index 68c58f3..a050064 100644 --- a/ui/gl/gl.gyp +++ b/ui/gl/gl.gyp @@ -114,8 +114,6 @@ 'gl_version_info.h', 'gpu_switching_manager.cc', 'gpu_switching_manager.h', - 'io_surface_support_mac.cc', - 'io_surface_support_mac.h', 'scoped_binders.cc', 'scoped_binders.h', 'scoped_make_current.cc', @@ -268,6 +266,7 @@ ], 'link_settings': { 'libraries': [ + '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', ], }, diff --git a/ui/gl/gl_image_io_surface.cc b/ui/gl/gl_image_io_surface.cc index e20c739..566b05e 100644 --- a/ui/gl/gl_image_io_surface.cc +++ b/ui/gl/gl_image_io_surface.cc @@ -6,19 +6,19 @@ #include "ui/gl/gl_bindings.h" #include "ui/gl/gl_context.h" -#include "ui/gl/io_surface_support_mac.h" + +// Note that this must be included after gl_bindings.h to avoid conflicts. +#include <OpenGL/CGLIOSurface.h> namespace gfx { GLImageIOSurface::GLImageIOSurface(gfx::Size size) - : io_surface_support_(IOSurfaceSupport::Initialize()), size_(size) { - CHECK(io_surface_support_); -} + : size_(size) {} GLImageIOSurface::~GLImageIOSurface() { Destroy(); } bool GLImageIOSurface::Initialize(gfx::GpuMemoryBufferHandle buffer) { - io_surface_.reset(io_surface_support_->IOSurfaceLookup(buffer.io_surface_id)); + io_surface_.reset(IOSurfaceLookup(buffer.io_surface_id)); if (!io_surface_) { LOG(ERROR) << "IOSurface lookup failed"; return false; @@ -41,16 +41,15 @@ bool GLImageIOSurface::BindTexImage(unsigned target) { static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); DCHECK(io_surface_); - CGLError cgl_error = - io_surface_support_->CGLTexImageIOSurface2D(cgl_context, - target, - GL_RGBA, - size_.width(), - size_.height(), - GL_BGRA, - GL_UNSIGNED_INT_8_8_8_8_REV, - io_surface_.get(), - 0); + CGLError cgl_error = CGLTexImageIOSurface2D(cgl_context, + target, + GL_RGBA, + size_.width(), + size_.height(), + GL_BGRA, + GL_UNSIGNED_INT_8_8_8_8_REV, + io_surface_.get(), + 0); if (cgl_error != kCGLNoError) { LOG(ERROR) << "Error in CGLTexImageIOSurface2D"; return false; diff --git a/ui/gl/gl_image_io_surface.h b/ui/gl/gl_image_io_surface.h index 79bf41c..7825e7d 100644 --- a/ui/gl/gl_image_io_surface.h +++ b/ui/gl/gl_image_io_surface.h @@ -5,11 +5,11 @@ #ifndef UI_GL_GL_IMAGE_IO_SURFACE_H_ #define UI_GL_GL_IMAGE_IO_SURFACE_H_ +#include <IOSurface/IOSurfaceAPI.h> + #include "base/mac/scoped_cftyperef.h" #include "ui/gl/gl_image.h" -class IOSurfaceSupport; - namespace gfx { class GL_EXPORT GLImageIOSurface : public GLImage { @@ -32,8 +32,7 @@ class GL_EXPORT GLImageIOSurface : public GLImage { virtual ~GLImageIOSurface(); private: - IOSurfaceSupport* io_surface_support_; - base::ScopedCFTypeRef<CFTypeRef> io_surface_; + base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; gfx::Size size_; DISALLOW_COPY_AND_ASSIGN(GLImageIOSurface); diff --git a/ui/gl/io_surface_support_mac.cc b/ui/gl/io_surface_support_mac.cc deleted file mode 100644 index a7aeae8..0000000 --- a/ui/gl/io_surface_support_mac.cc +++ /dev/null @@ -1,379 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <dlfcn.h> - -#include "base/memory/singleton.h" -#include "ui/gl/io_surface_support_mac.h" - -typedef CFTypeRef (*IOSurfaceCreateProcPtr)(CFDictionaryRef properties); -typedef uint32 (*IOSurfaceGetIDProcPtr)(CFTypeRef io_surface); -typedef CFTypeRef (*IOSurfaceLookupProcPtr)(uint32 io_surface_id); -typedef mach_port_t (*IOSurfaceCreateMachPortProcPtr)(CFTypeRef io_surface); -typedef CFTypeRef (*IOSurfaceLookupFromMachPortProcPtr)(mach_port_t port); -typedef size_t (*IOSurfaceGetWidthPtr)(CFTypeRef io_surface); -typedef size_t (*IOSurfaceGetHeightPtr)(CFTypeRef io_surface); -typedef size_t (*IOSurfaceGetBytesPerRowPtr)(CFTypeRef io_surface); -typedef void* (*IOSurfaceGetBaseAddressPtr)(CFTypeRef io_surface); -typedef IOReturn (*IOSurfaceLockPtr)(CFTypeRef io_surface, - uint32 options, - uint32* seed); -typedef IOReturn (*IOSurfaceUnlockPtr)(CFTypeRef io_surface, - uint32 options, - uint32* seed); - -typedef CGLError (*CGLTexImageIOSurface2DProcPtr)(CGLContextObj ctx, - GLenum target, - GLenum internal_format, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - CFTypeRef io_surface, - GLuint plane); -typedef CFTypeRef (*CVPixelBufferGetIOSurfaceProcPtr)( - CVPixelBufferRef pixel_buffer); - -class IOSurfaceSupportImpl : public IOSurfaceSupport { - public: - static IOSurfaceSupportImpl* GetInstance(); - - bool InitializedSuccessfully() { - return initialized_successfully_; - } - - virtual CFStringRef GetKIOSurfaceWidth() OVERRIDE; - virtual CFStringRef GetKIOSurfaceHeight() OVERRIDE; - virtual CFStringRef GetKIOSurfaceBytesPerElement() OVERRIDE; - virtual CFStringRef GetKIOSurfacePixelFormat() OVERRIDE; - virtual CFStringRef GetKIOSurfaceIsGlobal() OVERRIDE; - - virtual CFTypeRef IOSurfaceCreate(CFDictionaryRef properties) OVERRIDE; - virtual uint32 IOSurfaceGetID(CFTypeRef io_surface) OVERRIDE; - virtual CFTypeRef IOSurfaceLookup(uint32 io_surface_id) OVERRIDE; - virtual mach_port_t IOSurfaceCreateMachPort(CFTypeRef io_surface) OVERRIDE; - virtual CFTypeRef IOSurfaceLookupFromMachPort(mach_port_t port) OVERRIDE; - - virtual size_t IOSurfaceGetWidth(CFTypeRef io_surface) OVERRIDE; - virtual size_t IOSurfaceGetHeight(CFTypeRef io_surface) OVERRIDE; - virtual size_t IOSurfaceGetBytesPerRow(CFTypeRef io_surface) OVERRIDE; - virtual void* IOSurfaceGetBaseAddress(CFTypeRef io_surface) OVERRIDE; - - virtual IOReturn IOSurfaceLock(CFTypeRef io_surface, - uint32 options, - uint32* seed) OVERRIDE; - virtual IOReturn IOSurfaceUnlock(CFTypeRef io_surface, - uint32 options, - uint32* seed) OVERRIDE; - - virtual CGLError CGLTexImageIOSurface2D(CGLContextObj ctx, - GLenum target, - GLenum internal_format, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - CFTypeRef io_surface, - GLuint plane) OVERRIDE; - - virtual CFTypeRef CVPixelBufferGetIOSurface( - CVPixelBufferRef pixel_buffer) OVERRIDE; - - private: - IOSurfaceSupportImpl(); - virtual ~IOSurfaceSupportImpl(); - - void CloseLibraryHandles(); - - void* iosurface_handle_; - void* opengl_handle_; - void* core_video_handle_; - CFStringRef k_io_surface_width_; - CFStringRef k_io_surface_height_; - CFStringRef k_io_surface_bytes_per_element_; - CFStringRef k_io_surface_pixel_format_; - CFStringRef k_io_surface_is_global_; - IOSurfaceCreateProcPtr io_surface_create_; - IOSurfaceGetIDProcPtr io_surface_get_id_; - IOSurfaceLookupProcPtr io_surface_lookup_; - IOSurfaceCreateMachPortProcPtr io_surface_create_mach_port_; - IOSurfaceLookupFromMachPortProcPtr io_surface_lookup_from_mach_port_; - IOSurfaceGetWidthPtr io_surface_get_width_; - IOSurfaceGetHeightPtr io_surface_get_height_; - IOSurfaceGetBytesPerRowPtr io_surface_get_bytes_per_row_; - IOSurfaceGetBaseAddressPtr io_surface_get_base_address_; - IOSurfaceLockPtr io_surface_lock_; - IOSurfaceUnlockPtr io_surface_unlock_; - CGLTexImageIOSurface2DProcPtr cgl_tex_image_io_surface_2d_; - CVPixelBufferGetIOSurfaceProcPtr cv_pixel_buffer_get_io_surface_; - bool initialized_successfully_; - - friend struct DefaultSingletonTraits<IOSurfaceSupportImpl>; - DISALLOW_COPY_AND_ASSIGN(IOSurfaceSupportImpl); -}; - -IOSurfaceSupportImpl* IOSurfaceSupportImpl::GetInstance() { - IOSurfaceSupportImpl* impl = Singleton<IOSurfaceSupportImpl>::get(); - if (impl->InitializedSuccessfully()) - return impl; - return NULL; -} - -CFStringRef IOSurfaceSupportImpl::GetKIOSurfaceWidth() { - return k_io_surface_width_; -} - -CFStringRef IOSurfaceSupportImpl::GetKIOSurfaceHeight() { - return k_io_surface_height_; -} - -CFStringRef IOSurfaceSupportImpl::GetKIOSurfaceBytesPerElement() { - return k_io_surface_bytes_per_element_; -} - -CFStringRef IOSurfaceSupportImpl::GetKIOSurfacePixelFormat() { - return k_io_surface_pixel_format_; -} - -CFStringRef IOSurfaceSupportImpl::GetKIOSurfaceIsGlobal() { - return k_io_surface_is_global_; -} - -CFTypeRef IOSurfaceSupportImpl::IOSurfaceCreate(CFDictionaryRef properties) { - return io_surface_create_(properties); -} - -uint32 IOSurfaceSupportImpl::IOSurfaceGetID( - CFTypeRef io_surface) { - return io_surface_get_id_(io_surface); -} - -CFTypeRef IOSurfaceSupportImpl::IOSurfaceLookup(uint32 io_surface_id) { - return io_surface_lookup_(io_surface_id); -} - -mach_port_t IOSurfaceSupportImpl::IOSurfaceCreateMachPort( - CFTypeRef io_surface) { - return io_surface_create_mach_port_(io_surface); -} - -CFTypeRef IOSurfaceSupportImpl::IOSurfaceLookupFromMachPort(mach_port_t port) { - return io_surface_lookup_from_mach_port_(port); -} - -size_t IOSurfaceSupportImpl::IOSurfaceGetWidth(CFTypeRef io_surface) { - return io_surface_get_width_(io_surface); -} - -size_t IOSurfaceSupportImpl::IOSurfaceGetHeight(CFTypeRef io_surface) { - return io_surface_get_height_(io_surface); -} - -size_t IOSurfaceSupportImpl::IOSurfaceGetBytesPerRow(CFTypeRef io_surface) { - return io_surface_get_bytes_per_row_(io_surface); -} - -void* IOSurfaceSupportImpl::IOSurfaceGetBaseAddress(CFTypeRef io_surface) { - return io_surface_get_base_address_(io_surface); -} - -IOReturn IOSurfaceSupportImpl::IOSurfaceLock(CFTypeRef io_surface, - uint32 options, - uint32* seed) { - return io_surface_lock_(io_surface, options, seed); -} - -IOReturn IOSurfaceSupportImpl::IOSurfaceUnlock(CFTypeRef io_surface, - uint32 options, - uint32* seed) { - return io_surface_unlock_(io_surface, options, seed); -} - -CGLError IOSurfaceSupportImpl::CGLTexImageIOSurface2D(CGLContextObj ctx, - GLenum target, - GLenum internal_format, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - CFTypeRef io_surface, - GLuint plane) { - return cgl_tex_image_io_surface_2d_(ctx, - target, - internal_format, - width, - height, - format, - type, - io_surface, - plane); -} - -CFTypeRef IOSurfaceSupportImpl::CVPixelBufferGetIOSurface( - CVPixelBufferRef pixel_buffer) { - return cv_pixel_buffer_get_io_surface_(pixel_buffer); -} - -IOSurfaceSupportImpl::IOSurfaceSupportImpl() - : iosurface_handle_(NULL), - opengl_handle_(NULL), - core_video_handle_(NULL), - k_io_surface_width_(NULL), - k_io_surface_height_(NULL), - k_io_surface_bytes_per_element_(NULL), - k_io_surface_pixel_format_(NULL), - k_io_surface_is_global_(NULL), - io_surface_create_(NULL), - io_surface_get_id_(NULL), - io_surface_lookup_(NULL), - io_surface_create_mach_port_(NULL), - io_surface_lookup_from_mach_port_(NULL), - io_surface_get_width_(NULL), - io_surface_get_height_(NULL), - io_surface_get_bytes_per_row_(NULL), - io_surface_get_base_address_(NULL), - io_surface_lock_(NULL), - io_surface_unlock_(NULL), - cgl_tex_image_io_surface_2d_(NULL), - cv_pixel_buffer_get_io_surface_(NULL), - initialized_successfully_(false) { - iosurface_handle_ = dlopen( - "/System/Library/Frameworks/IOSurface.framework/IOSurface", - RTLD_LAZY | RTLD_LOCAL); - opengl_handle_ = dlopen( - "/System/Library/Frameworks/OpenGL.framework/OpenGL", - RTLD_LAZY | RTLD_LOCAL); - core_video_handle_ = dlopen( - "/System/Library/Frameworks/CoreVideo.framework/CoreVideo", - RTLD_LAZY | RTLD_LOCAL); - if (!iosurface_handle_ || - !opengl_handle_ || - !core_video_handle_) { - CloseLibraryHandles(); - return; - } - - void* surface_width_ptr = dlsym(iosurface_handle_, "kIOSurfaceWidth"); - void* surface_height_ptr = dlsym(iosurface_handle_, "kIOSurfaceHeight"); - void* surface_bytes_per_element_ptr = - dlsym(iosurface_handle_, "kIOSurfaceBytesPerElement"); - void* surface_pixel_format_ptr = - dlsym(iosurface_handle_, "kIOSurfacePixelFormat"); - void* surface_is_global_ptr = - dlsym(iosurface_handle_, "kIOSurfaceIsGlobal"); - void* surface_create_ptr = dlsym(iosurface_handle_, "IOSurfaceCreate"); - void* surface_get_id_ptr = dlsym(iosurface_handle_, "IOSurfaceGetID"); - void* surface_lookup_ptr = dlsym(iosurface_handle_, "IOSurfaceLookup"); - void* surface_create_mach_port_ptr = - dlsym(iosurface_handle_, "IOSurfaceCreateMachPort"); - void* surface_lookup_from_mach_port_ptr = - dlsym(iosurface_handle_, "IOSurfaceLookupFromMachPort"); - void* io_surface_get_width_ptr = - dlsym(iosurface_handle_, "IOSurfaceGetWidth"); - void* io_surface_get_height_ptr = - dlsym(iosurface_handle_, "IOSurfaceGetHeight"); - void* io_surface_get_bytes_per_row_ptr = - dlsym(iosurface_handle_, "IOSurfaceGetBytesPerRow"); - void* io_surface_get_base_address_ptr = - dlsym(iosurface_handle_, "IOSurfaceGetBaseAddress"); - void* io_surface_lock_ptr = dlsym(iosurface_handle_, "IOSurfaceLock"); - void* io_surface_unlock_ptr = dlsym(iosurface_handle_, "IOSurfaceUnlock"); - void* tex_image_io_surface_2d_ptr = - dlsym(opengl_handle_, "CGLTexImageIOSurface2D"); - void* cv_pixel_buffer_get_io_surface = - dlsym(core_video_handle_, "CVPixelBufferGetIOSurface"); - if (!surface_width_ptr || - !surface_height_ptr || - !surface_bytes_per_element_ptr || - !surface_pixel_format_ptr || - !surface_is_global_ptr || - !surface_create_ptr || - !surface_get_id_ptr || - !surface_lookup_ptr || - !surface_create_mach_port_ptr || - !surface_lookup_from_mach_port_ptr || - !io_surface_get_width_ptr || - !io_surface_get_height_ptr || - !io_surface_get_bytes_per_row_ptr || - !io_surface_get_base_address_ptr || - !io_surface_lock_ptr || - !io_surface_unlock_ptr || - !tex_image_io_surface_2d_ptr || - !cv_pixel_buffer_get_io_surface) { - CloseLibraryHandles(); - return; - } - - k_io_surface_width_ = *static_cast<CFStringRef*>(surface_width_ptr); - k_io_surface_height_ = *static_cast<CFStringRef*>(surface_height_ptr); - k_io_surface_bytes_per_element_ = - *static_cast<CFStringRef*>(surface_bytes_per_element_ptr); - k_io_surface_pixel_format_ = - *static_cast<CFStringRef*>(surface_pixel_format_ptr); - k_io_surface_is_global_ = *static_cast<CFStringRef*>(surface_is_global_ptr); - io_surface_create_ = reinterpret_cast<IOSurfaceCreateProcPtr>( - surface_create_ptr); - io_surface_get_id_ = - reinterpret_cast<IOSurfaceGetIDProcPtr>(surface_get_id_ptr); - io_surface_lookup_ = - reinterpret_cast<IOSurfaceLookupProcPtr>(surface_lookup_ptr); - io_surface_create_mach_port_ = - reinterpret_cast<IOSurfaceCreateMachPortProcPtr>( - surface_create_mach_port_ptr); - io_surface_lookup_from_mach_port_ = - reinterpret_cast<IOSurfaceLookupFromMachPortProcPtr>( - surface_lookup_from_mach_port_ptr); - io_surface_get_width_ = - reinterpret_cast<IOSurfaceGetWidthPtr>( - io_surface_get_width_ptr); - io_surface_get_height_ = - reinterpret_cast<IOSurfaceGetHeightPtr>( - io_surface_get_height_ptr); - io_surface_get_bytes_per_row_ = - reinterpret_cast<IOSurfaceGetBytesPerRowPtr>( - io_surface_get_bytes_per_row_ptr); - io_surface_get_base_address_ = - reinterpret_cast<IOSurfaceGetBaseAddressPtr>( - io_surface_get_base_address_ptr); - io_surface_lock_ = reinterpret_cast<IOSurfaceLockPtr>(io_surface_lock_ptr); - io_surface_unlock_ = reinterpret_cast<IOSurfaceUnlockPtr>( - io_surface_unlock_ptr); - cgl_tex_image_io_surface_2d_ = - reinterpret_cast<CGLTexImageIOSurface2DProcPtr>( - tex_image_io_surface_2d_ptr); - cv_pixel_buffer_get_io_surface_ = - reinterpret_cast<CVPixelBufferGetIOSurfaceProcPtr>( - cv_pixel_buffer_get_io_surface); - initialized_successfully_ = true; -} - -IOSurfaceSupportImpl::~IOSurfaceSupportImpl() { - CloseLibraryHandles(); -} - -void IOSurfaceSupportImpl::CloseLibraryHandles() { - if (iosurface_handle_) { - dlclose(iosurface_handle_); - iosurface_handle_ = NULL; - } - if (opengl_handle_) { - dlclose(opengl_handle_); - opengl_handle_ = NULL; - } - if (core_video_handle_) { - dlclose(core_video_handle_); - core_video_handle_ = NULL; - } -} - -IOSurfaceSupport* IOSurfaceSupport::Initialize() { - return IOSurfaceSupportImpl::GetInstance(); -} - -IOSurfaceSupport::IOSurfaceSupport() { -} - -IOSurfaceSupport::~IOSurfaceSupport() { -} - diff --git a/ui/gl/io_surface_support_mac.h b/ui/gl/io_surface_support_mac.h deleted file mode 100644 index d8699c8..0000000 --- a/ui/gl/io_surface_support_mac.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_GL_IO_SURFACE_SUPPORT_MAC_H_ -#define UI_GL_IO_SURFACE_SUPPORT_MAC_H_ - -#include <CoreFoundation/CoreFoundation.h> -#include <CoreVideo/CoreVideo.h> -#include <mach/mach.h> -#include <OpenGL/OpenGL.h> - -#include "base/basictypes.h" -#include "ui/gl/gl_export.h" - -// This Mac OS X-specific class provides dynamically-linked access to -// IOSurface.framework, which is only available on 10.6 and later. -// Since Chromium is built on 10.5 we must dynamically look up all of -// the entry points we need in this framework. - -// See IOSurface/IOSurfaceAPI.h and OpenGL/CGLIOSurface.h on 10.6 for -// documentation of the fields and methods of this class. - -class GL_EXPORT IOSurfaceSupport { - public: - // Returns an instance of the IOSurfaceSupport class if the - // operating system supports it, NULL otherwise. It is safe to call - // this multiple times. - static IOSurfaceSupport* Initialize(); - - virtual CFStringRef GetKIOSurfaceWidth() = 0; - virtual CFStringRef GetKIOSurfaceHeight() = 0; - virtual CFStringRef GetKIOSurfaceBytesPerElement() = 0; - virtual CFStringRef GetKIOSurfacePixelFormat() = 0; - virtual CFStringRef GetKIOSurfaceIsGlobal() = 0; - - virtual CFTypeRef IOSurfaceCreate(CFDictionaryRef properties) = 0; - - // The following two APIs assume the IOSurface was created with the - // kIOSurfaceIsGlobal key set to true - virtual uint32 IOSurfaceGetID(CFTypeRef io_surface) = 0; - virtual CFTypeRef IOSurfaceLookup(uint32 io_surface_id) = 0; - - // The following two APIs are more robust and secure, but - // unfortunately it looks like it will be a lot of work to correctly - // transmit a mach port from process to process (possibly requiring - // a side channel for or extension of the Chrome IPC mechanism) - virtual mach_port_t IOSurfaceCreateMachPort(CFTypeRef io_surface) = 0; - virtual CFTypeRef IOSurfaceLookupFromMachPort(mach_port_t port) = 0; - - virtual size_t IOSurfaceGetWidth(CFTypeRef io_surface) = 0; - virtual size_t IOSurfaceGetHeight(CFTypeRef io_surface) = 0; - virtual size_t IOSurfaceGetBytesPerRow(CFTypeRef io_surface) = 0; - virtual void* IOSurfaceGetBaseAddress(CFTypeRef io_surface) = 0; - - virtual IOReturn IOSurfaceLock(CFTypeRef io_surface, - uint32 options, - uint32* seed) = 0; - virtual IOReturn IOSurfaceUnlock(CFTypeRef io_surface, - uint32 options, - uint32* seed) = 0; - - virtual CGLError CGLTexImageIOSurface2D(CGLContextObj ctx, - GLenum target, - GLenum internal_format, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - CFTypeRef io_surface, - GLuint plane) = 0; - - virtual CFTypeRef CVPixelBufferGetIOSurface( - CVPixelBufferRef pixel_buffer) = 0; - - protected: - IOSurfaceSupport(); - virtual ~IOSurfaceSupport(); - - DISALLOW_COPY_AND_ASSIGN(IOSurfaceSupport); -}; - -#endif // UI_GL_IO_SURFACE_SUPPORT_MAC_H_ diff --git a/ui/surface/accelerated_surface_mac.cc b/ui/surface/accelerated_surface_mac.cc index 8ff8492..2fbd47a 100644 --- a/ui/surface/accelerated_surface_mac.cc +++ b/ui/surface/accelerated_surface_mac.cc @@ -11,9 +11,11 @@ #include "ui/gl/gl_context.h" #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_surface.h" -#include "ui/gl/io_surface_support_mac.h" #include "ui/gl/scoped_make_current.h" +// Note that this must be included after gl_bindings.h to avoid conflicts. +#include <OpenGL/CGLIOSurface.h> + AcceleratedSurface::AcceleratedSurface() : io_surface_id_(0), allocate_fbo_(false), @@ -192,10 +194,6 @@ uint32 AcceleratedSurface::SetSurfaceSize(const gfx::Size& size) { if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) return 0; - IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); - if (!io_surface_support) - return 0; - ui::ScopedMakeCurrent make_current(gl_context_.get(), gl_surface_.get()); if (!make_current.Succeeded()) return 0; @@ -219,24 +217,18 @@ uint32 AcceleratedSurface::SetSurfaceSize(const gfx::Size& size) { 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); - AddIntegerValue(properties, - io_surface_support->GetKIOSurfaceWidth(), - clamped_size.width()); - AddIntegerValue(properties, - io_surface_support->GetKIOSurfaceHeight(), - clamped_size.height()); - AddIntegerValue(properties, - io_surface_support->GetKIOSurfaceBytesPerElement(), 4); - AddBooleanValue(properties, - io_surface_support->GetKIOSurfaceIsGlobal(), true); + AddIntegerValue(properties, kIOSurfaceWidth, clamped_size.width()); + AddIntegerValue(properties, kIOSurfaceHeight, clamped_size.height()); + AddIntegerValue(properties, kIOSurfaceBytesPerElement, 4); + AddBooleanValue(properties, kIOSurfaceIsGlobal, true); // I believe we should be able to unreference the IOSurfaces without // synchronizing with the browser process because they are // ultimately reference counted by the operating system. - io_surface_.reset(io_surface_support->IOSurfaceCreate(properties)); + io_surface_.reset(IOSurfaceCreate(properties)); // Don't think we need to identify a plane. GLuint plane = 0; - CGLError error = io_surface_support->CGLTexImageIOSurface2D( + CGLError error = CGLTexImageIOSurface2D( static_cast<CGLContextObj>(gl_context_->GetHandle()), target, GL_RGBA, @@ -265,7 +257,7 @@ uint32 AcceleratedSurface::SetSurfaceSize(const gfx::Size& size) { // make our IOSurfaces global and send back their identifiers. On // the browser process side the identifier is reconstituted into an // IOSurface for on-screen rendering. - io_surface_id_ = io_surface_support->IOSurfaceGetID(io_surface_); + io_surface_id_ = IOSurfaceGetID(io_surface_); return io_surface_id_; } diff --git a/ui/surface/accelerated_surface_mac.h b/ui/surface/accelerated_surface_mac.h index 0fbcbdb..f5ee11c 100644 --- a/ui/surface/accelerated_surface_mac.h +++ b/ui/surface/accelerated_surface_mac.h @@ -6,6 +6,7 @@ #define UI_SURFACE_ACCELERATED_SURFACE_MAC_H_ #include <CoreFoundation/CoreFoundation.h> +#include <IOSurface/IOSurfaceAPI.h> #include "base/callback.h" #include "base/mac/scoped_cftyperef.h" @@ -118,7 +119,7 @@ class SURFACE_EXPORT AcceleratedSurface { // to the shared region (IOSurface). scoped_refptr<gfx::GLSurface> gl_surface_; scoped_refptr<gfx::GLContext> gl_context_; - base::ScopedCFTypeRef<CFTypeRef> io_surface_; + base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; // The id of |io_surface_| or 0 if that's NULL. uint32 io_surface_id_; diff --git a/ui/surface/surface.gyp b/ui/surface/surface.gyp index a6ad39b..710575c 100644 --- a/ui/surface/surface.gyp +++ b/ui/surface/surface.gyp @@ -13,6 +13,13 @@ '../../third_party/khronos', ], }], + ['OS == "mac"', { + 'link_settings': { + 'libraries': [ + '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', + ], + }, + }], ], }, 'targets': [ |