diff options
Diffstat (limited to 'content/common')
-rw-r--r-- | content/common/gpu/gpu_channel.cc | 8 | ||||
-rw-r--r-- | content/common/gpu/gpu_channel.h | 2 | ||||
-rw-r--r-- | content/common/gpu/gpu_channel_manager.cc | 14 | ||||
-rw-r--r-- | content/common/gpu/gpu_channel_manager.h | 1 | ||||
-rw-r--r-- | content/common/gpu/gpu_command_buffer_stub.cc | 88 | ||||
-rw-r--r-- | content/common/gpu/gpu_command_buffer_stub.h | 16 | ||||
-rw-r--r-- | content/common/gpu/gpu_messages.h | 55 | ||||
-rw-r--r-- | content/common/gpu/image_transport_surface.cc | 94 | ||||
-rw-r--r-- | content/common/gpu/image_transport_surface.h | 46 | ||||
-rw-r--r-- | content/common/gpu/image_transport_surface_linux.cc | 30 | ||||
-rw-r--r-- | content/common/gpu/image_transport_surface_mac.cc | 10 | ||||
-rw-r--r-- | content/common/gpu/image_transport_surface_win.cc | 176 |
12 files changed, 387 insertions, 153 deletions
diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc index 2f14065..27eb490 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -209,14 +209,6 @@ void GpuChannel::CreateViewCommandBuffer( #endif // ENABLE_GPU } -void GpuChannel::ViewResized(int32 command_buffer_route_id) { - GpuCommandBufferStub* stub = stubs_.Lookup(command_buffer_route_id); - if (stub == NULL) - return; - - stub->ViewResized(); -} - GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32 route_id) { return stubs_.Lookup(route_id); } diff --git a/content/common/gpu/gpu_channel.h b/content/common/gpu/gpu_channel.h index 782698f..bc642ac 100644 --- a/content/common/gpu/gpu_channel.h +++ b/content/common/gpu/gpu_channel.h @@ -88,8 +88,6 @@ class GpuChannel : public IPC::Channel::Listener, const GPUCreateCommandBufferConfig& init_params, int32* route_id); - void ViewResized(int32 command_buffer_route_id); - gfx::GLShareGroup* share_group() const { return share_group_.get(); } GpuCommandBufferStub* LookupCommandBuffer(int32 route_id); diff --git a/content/common/gpu/gpu_channel_manager.cc b/content/common/gpu/gpu_channel_manager.cc index cd0b115..94838fb 100644 --- a/content/common/gpu/gpu_channel_manager.cc +++ b/content/common/gpu/gpu_channel_manager.cc @@ -62,9 +62,6 @@ bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, OnCreateViewCommandBuffer) IPC_MESSAGE_HANDLER(GpuMsg_VisibilityChanged, OnVisibilityChanged) -#if defined(TOOLKIT_USES_GTK) || defined(OS_WIN) - IPC_MESSAGE_HANDLER(GpuMsg_ResizeViewACK, OnResizeViewACK); -#endif IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() return handled; @@ -127,6 +124,7 @@ void GpuChannelManager::OnCreateViewCommandBuffer( int32 render_view_id, int32 renderer_id, const GPUCreateCommandBufferConfig& init_params) { + DCHECK(render_view_id); int32 route_id = MSG_ROUTING_NONE; GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); @@ -138,16 +136,6 @@ void GpuChannelManager::OnCreateViewCommandBuffer( Send(new GpuHostMsg_CommandBufferCreated(route_id)); } -void GpuChannelManager::OnResizeViewACK(int32 renderer_id, - int32 command_buffer_route_id) { - GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); - if (iter == gpu_channels_.end()) - return; - scoped_refptr<GpuChannel> channel = iter->second; - - channel->ViewResized(command_buffer_route_id); -} - void GpuChannelManager::LoseAllContexts() { MessageLoop::current()->PostTask( FROM_HERE, diff --git a/content/common/gpu/gpu_channel_manager.h b/content/common/gpu/gpu_channel_manager.h index a6fff25..db0db36 100644 --- a/content/common/gpu/gpu_channel_manager.h +++ b/content/common/gpu/gpu_channel_manager.h @@ -77,7 +77,6 @@ class GpuChannelManager : public IPC::Channel::Listener, int32 render_view_id, int32 renderer_id, const GPUCreateCommandBufferConfig& init_params); - void OnResizeViewACK(int32 renderer_id, int32 command_buffer_route_id); void OnLoseAllContexts(); diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc index 5e741ee..195cf6e 100644 --- a/content/common/gpu/gpu_command_buffer_stub.cc +++ b/content/common/gpu/gpu_command_buffer_stub.cc @@ -15,13 +15,11 @@ #include "content/common/gpu/gpu_command_buffer_stub.h" #include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/gpu_watchdog.h" +#include "content/common/gpu/image_transport_surface.h" #include "gpu/command_buffer/common/constants.h" +#include "ui/gfx/gl/gl_bindings.h" #include "ui/gfx/gl/gl_switches.h" -#if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT) -#include "content/common/gpu/image_transport_surface.h" -#endif - GpuCommandBufferStub::GpuCommandBufferStub( GpuChannel* channel, GpuCommandBufferStub* share_group, @@ -125,6 +123,19 @@ bool GpuCommandBufferStub::IsScheduled() { return !scheduler_.get() || scheduler_->IsScheduled(); } +void GpuCommandBufferStub::SetSwapInterval() { +#if !defined(OS_MACOSX) && !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) + // Set up swap interval for onscreen contexts. + if (!surface_->IsOffscreen()) { + decoder_->MakeCurrent(); + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) + context_->SetSwapInterval(0); + else + context_->SetSwapInterval(1); + } +#endif +} + void GpuCommandBufferStub::Destroy() { // The scheduler has raw references to the decoder and the command buffer so // destroy it before those. @@ -186,6 +197,7 @@ void GpuCommandBufferStub::OnInitialize( OnInitializeFailed(reply_message); return; } +#endif surface_ = ImageTransportSurface::CreateSurface( channel_->gpu_channel_manager(), @@ -193,9 +205,6 @@ void GpuCommandBufferStub::OnInitialize( renderer_id_, route_id_, handle_); -#elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_OPENBSD) - surface_ = gfx::GLSurface::CreateViewGLSurface(software_, handle_); -#endif } else { surface_ = gfx::GLSurface::CreateOffscreenGLSurface(software_, gfx::Size(1, 1)); @@ -254,16 +263,6 @@ void GpuCommandBufferStub::OnInitialize( scheduler_->SetScheduledCallback( base::Bind(&GpuChannel::OnScheduled, base::Unretained(channel_))); - // On platforms that use an ImageTransportSurface, the surface - // handles co-ordinating the resize with the browser process. The - // surface sets it's own resize callback, so we shouldn't do it here. -#if !defined(OS_MACOSX) && !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) - if (handle_ != gfx::kNullPluginWindow) { - decoder_->SetResizeCallback( - base::Bind(&GpuCommandBufferStub::OnResize, base::Unretained(this))); - } -#endif - if (watchdog_) { scheduler_->SetCommandProcessedCallback( base::Bind(&GpuCommandBufferStub::OnCommandProcessed, @@ -431,48 +430,6 @@ void GpuCommandBufferStub::OnCommandProcessed() { watchdog_->CheckArmed(); } -void GpuCommandBufferStub::OnResize(gfx::Size size) { - if (handle_ == gfx::kNullPluginWindow) - return; - -#if defined(TOOLKIT_USES_GTK) && !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) || \ - defined(OS_WIN) - GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); - - // On Windows, Linux, we need to coordinate resizing of onscreen - // contexts with the resizing of the actual OS-level window. We do this by - // sending a resize message to the browser process and descheduling the - // context until the ViewResized message comes back in reply. - // Send the resize message if needed - gpu_channel_manager->Send( - new GpuHostMsg_ResizeView(renderer_id_, - render_view_id_, - route_id_, - size)); - - scheduler_->SetScheduled(false); -#endif -} - -void GpuCommandBufferStub::ViewResized() { -#if defined(TOOLKIT_USES_GTK) && !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) || \ - defined(OS_WIN) - DCHECK(handle_ != gfx::kNullPluginWindow); - scheduler_->SetScheduled(true); -#endif - -#if defined(OS_WIN) - // Recreate the view surface to match the window size. Swap chains do not - // automatically resize with window size with D3D. - context_->ReleaseCurrent(surface_.get()); - if (surface_.get()) { - surface_->Destroy(); - surface_->Initialize(); - SetSwapInterval(); - } -#endif -} - void GpuCommandBufferStub::ReportState() { gpu::CommandBuffer::State state = command_buffer_->GetState(); if (state.error == gpu::error::kLostContext && @@ -485,19 +442,6 @@ void GpuCommandBufferStub::ReportState() { } } -void GpuCommandBufferStub::SetSwapInterval() { -#if !defined(OS_MACOSX) && !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) - // Set up swap interval for onscreen contexts. - if (!surface_->IsOffscreen()) { - decoder_->MakeCurrent(); - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) - context_->SetSwapInterval(0); - else - context_->SetSwapInterval(1); - } -#endif -} - void GpuCommandBufferStub::OnCreateVideoDecoder( media::VideoDecodeAccelerator::Profile profile, IPC::Message* reply_message) { diff --git a/content/common/gpu/gpu_command_buffer_stub.h b/content/common/gpu/gpu_command_buffer_stub.h index 6ece34f..f581593 100644 --- a/content/common/gpu/gpu_command_buffer_stub.h +++ b/content/common/gpu/gpu_command_buffer_stub.h @@ -65,6 +65,9 @@ class GpuCommandBufferStub // Whether this command buffer can currently handle IPC messages. bool IsScheduled(); + // Set the swap interval according to the command line. + void SetSwapInterval(); + gpu::gles2::GLES2Decoder* decoder() const { return decoder_.get(); } gpu::GpuScheduler* scheduler() const { return scheduler_.get(); } @@ -78,8 +81,6 @@ class GpuCommandBufferStub // to the same renderer process. int32 route_id() const { return route_id_; } - void ViewResized(); - gfx::GpuPreference gpu_preference() { return gpu_preference_; } private: @@ -117,22 +118,11 @@ class GpuCommandBufferStub void OnSetSurfaceVisible(bool visible); -#if defined(OS_MACOSX) - void OnSwapBuffers(); - - // Returns the id of the current surface that is being rendered to - // (or 0 if no such surface has been created). - uint64 GetSurfaceId(); -#endif - void OnCommandProcessed(); void OnParseError(); - void OnResize(gfx::Size size); void ReportState(); - void SetSwapInterval(); - // The lifetime of objects of this class is managed by a GpuChannel. The // GpuChannels destroy all the GpuCommandBufferStubs that they own when they // are destroyed. So a raw pointer is safe. diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h index 906a195..8c99041 100644 --- a/content/common/gpu/gpu_messages.h +++ b/content/common/gpu/gpu_messages.h @@ -33,43 +33,17 @@ IPC_STRUCT_BEGIN(GPUCreateCommandBufferConfig) IPC_STRUCT_MEMBER(gfx::GpuPreference, gpu_preference) IPC_STRUCT_END() -#if defined(OS_MACOSX) IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceNew_Params) IPC_STRUCT_MEMBER(int32, renderer_id) IPC_STRUCT_MEMBER(int32, render_view_id) - IPC_STRUCT_MEMBER(gfx::PluginWindowHandle, window) IPC_STRUCT_MEMBER(int32, width) IPC_STRUCT_MEMBER(int32, height) IPC_STRUCT_MEMBER(uint64, surface_id) - IPC_STRUCT_MEMBER(bool, create_transport_dib) - IPC_STRUCT_MEMBER(int32, route_id) -IPC_STRUCT_END() - -IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params) - IPC_STRUCT_MEMBER(int32, renderer_id) - IPC_STRUCT_MEMBER(int32, render_view_id) - IPC_STRUCT_MEMBER(gfx::PluginWindowHandle, window) - IPC_STRUCT_MEMBER(uint64, surface_id) IPC_STRUCT_MEMBER(int32, route_id) -IPC_STRUCT_END() - -IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceRelease_Params) - IPC_STRUCT_MEMBER(int32, renderer_id) - IPC_STRUCT_MEMBER(int32, render_view_id) +#if defined(OS_MACOSX) IPC_STRUCT_MEMBER(gfx::PluginWindowHandle, window) - IPC_STRUCT_MEMBER(uint64, identifier) - IPC_STRUCT_MEMBER(int32, route_id) -IPC_STRUCT_END() + IPC_STRUCT_MEMBER(bool, create_transport_dib) #endif - -#if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) -IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceNew_Params) - IPC_STRUCT_MEMBER(int32, renderer_id) - IPC_STRUCT_MEMBER(int32, render_view_id) - IPC_STRUCT_MEMBER(int32, width) - IPC_STRUCT_MEMBER(int32, height) - IPC_STRUCT_MEMBER(uint64, surface_id) - IPC_STRUCT_MEMBER(int32, route_id) IPC_STRUCT_END() IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params) @@ -77,6 +51,11 @@ IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params) IPC_STRUCT_MEMBER(int32, render_view_id) IPC_STRUCT_MEMBER(uint64, surface_id) IPC_STRUCT_MEMBER(int32, route_id) +#if defined(OS_WIN) + IPC_STRUCT_MEMBER(gfx::Size, size) +#elif defined(OS_MACOSX) + IPC_STRUCT_MEMBER(gfx::PluginWindowHandle, window) +#endif IPC_STRUCT_END() IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceRelease_Params) @@ -84,8 +63,10 @@ IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceRelease_Params) IPC_STRUCT_MEMBER(int32, render_view_id) IPC_STRUCT_MEMBER(uint64, identifier) IPC_STRUCT_MEMBER(int32, route_id) -IPC_STRUCT_END() +#if defined(OS_MACOSX) + IPC_STRUCT_MEMBER(gfx::PluginWindowHandle, window) #endif +IPC_STRUCT_END() IPC_STRUCT_TRAITS_BEGIN(content::DxDiagNode) IPC_STRUCT_TRAITS_MEMBER(values) @@ -160,16 +141,10 @@ IPC_MESSAGE_CONTROL4(GpuMsg_CreateViewCommandBuffer, // information. IPC_MESSAGE_CONTROL0(GpuMsg_CollectGraphicsInfo) -#if defined(TOOLKIT_USES_GTK) && !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) || \ - defined(OS_WIN) // Tells the GPU process that the browser process has finished resizing the // view. -IPC_MESSAGE_CONTROL2(GpuMsg_ResizeViewACK, - int32 /* renderer_id */, - int32 /* command_buffer_id */) -#endif +IPC_MESSAGE_ROUTED0(AcceleratedSurfaceMsg_ResizeViewACK) -#if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT) // Tells the GPU process that it's safe to start rendering to the surface. IPC_MESSAGE_ROUTED2(AcceleratedSurfaceMsg_NewACK, uint64 /* surface_id */, @@ -178,7 +153,6 @@ IPC_MESSAGE_ROUTED2(AcceleratedSurfaceMsg_NewACK, // Tells the GPU process that the browser process handled the swap // buffers request with the given number. IPC_MESSAGE_ROUTED0(AcceleratedSurfaceMsg_BuffersSwappedACK) -#endif // Tells the GPU process to remove all contexts. IPC_MESSAGE_CONTROL0(GpuMsg_Clean) @@ -234,18 +208,14 @@ IPC_MESSAGE_CONTROL3(GpuHostMsg_OnLogMessage, std::string /* header */, std::string /* message */) -#if defined(TOOLKIT_USES_GTK) && !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) || \ - defined(OS_WIN) // Resize the window that is being drawn into. It's important that this // resize be synchronized with the swapping of the front and back buffers. IPC_MESSAGE_CONTROL4(GpuHostMsg_ResizeView, int32 /* renderer_id */, int32 /* render_view_id */, - int32 /* command_buffer_route_id */, + int32 /* route_id */, gfx::Size /* size */) -#endif -#if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT) // This message is sent from the GPU process to the browser to notify about a // new or resized surface in the GPU. The browser allocates any resources // needed for it on its end and replies with an ACK containing any shared @@ -264,7 +234,6 @@ IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, // is complete. IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfaceRelease, GpuHostMsg_AcceleratedSurfaceRelease_Params) -#endif //------------------------------------------------------------------------------ // GPU Channel Messages diff --git a/content/common/gpu/image_transport_surface.cc b/content/common/gpu/image_transport_surface.cc index 5bb016e..d0dfee1 100644 --- a/content/common/gpu/image_transport_surface.cc +++ b/content/common/gpu/image_transport_surface.cc @@ -14,6 +14,12 @@ #include "content/common/gpu/gpu_messages.h" #include "gpu/command_buffer/service/gpu_scheduler.h" +ImageTransportSurface::ImageTransportSurface() { +} + +ImageTransportSurface::~ImageTransportSurface() { +} + ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, GpuChannelManager* manager, int32 render_view_id, @@ -56,6 +62,7 @@ bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { OnBuffersSwappedACK) IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_NewACK, OnNewSurfaceACK) + IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_ResizeViewACK, OnResizeViewACK); IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -91,6 +98,13 @@ void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( manager_->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); } +void ImageTransportHelper::SendResizeView(const gfx::Size& size) { + manager_->Send(new GpuHostMsg_ResizeView(renderer_id_, + render_view_id_, + route_id_, + size)); +} + void ImageTransportHelper::SetScheduled(bool is_scheduled) { gpu::GpuScheduler* scheduler = Scheduler(); if (!scheduler) @@ -99,6 +113,13 @@ void ImageTransportHelper::SetScheduled(bool is_scheduled) { scheduler->SetScheduled(is_scheduled); } +void ImageTransportHelper::DeferToFence(base::Closure task) { + gpu::GpuScheduler* scheduler = Scheduler(); + DCHECK(scheduler); + + scheduler->DeferToFence(task); +} + void ImageTransportHelper::OnBuffersSwappedACK() { surface_->OnBuffersSwappedACK(); } @@ -109,8 +130,38 @@ void ImageTransportHelper::OnNewSurfaceACK( surface_->OnNewSurfaceACK(surface_id, shm_handle); } +void ImageTransportHelper::OnResizeViewACK() { + surface_->OnResizeViewACK(); +} + void ImageTransportHelper::Resize(gfx::Size size) { + // On windows, the surface is recreated and, in case the newly allocated + // surface happens to have the same address, it should be invalidated on the + // decoder so that future calls to MakeCurrent do not early out on the + // assumption that neither the context or surface have actually changed. +#if defined(OS_WIN) + Decoder()->ReleaseCurrent(); +#endif + surface_->OnResize(size); + +#if defined(OS_WIN) + Decoder()->MakeCurrent(); + SetSwapInterval(); +#endif +} + +void ImageTransportHelper::SetSwapInterval() { + GpuChannel* channel = manager_->LookupChannel(renderer_id_); + if (!channel) + return; + + GpuCommandBufferStub* stub = + channel->LookupCommandBuffer(command_buffer_id_); + if (!stub) + return; + + stub->SetSwapInterval(); } bool ImageTransportHelper::MakeCurrent() { @@ -146,4 +197,47 @@ gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { return stub->decoder(); } +PassThroughImageTransportSurface::PassThroughImageTransportSurface( + GpuChannelManager* manager, + int32 render_view_id, + int32 renderer_id, + int32 command_buffer_id, + gfx::GLSurface* surface) : GLSurfaceAdapter(surface) { + helper_.reset(new ImageTransportHelper(this, + manager, + render_view_id, + renderer_id, + command_buffer_id, + gfx::kNullPluginWindow)); +} + +PassThroughImageTransportSurface::~PassThroughImageTransportSurface() { +} + +bool PassThroughImageTransportSurface::Initialize() { + // The surface is assumed to have already been initialized. + return helper_->Initialize(); +} + +void PassThroughImageTransportSurface::Destroy() { + helper_->Destroy(); + GLSurfaceAdapter::Destroy(); +} + +void PassThroughImageTransportSurface::OnNewSurfaceACK( + uint64 surface_id, TransportDIB::Handle surface_handle) { +} + +void PassThroughImageTransportSurface::OnBuffersSwappedACK() { +} + +void PassThroughImageTransportSurface::OnResizeViewACK() { + helper_->SetScheduled(true); +} + +void PassThroughImageTransportSurface::OnResize(gfx::Size size) { + helper_->SendResizeView(size); + helper_->SetScheduled(false); +} + #endif // defined(ENABLE_GPU) diff --git a/content/common/gpu/image_transport_surface.h b/content/common/gpu/image_transport_surface.h index 044d8c3..b791c6e 100644 --- a/content/common/gpu/image_transport_surface.h +++ b/content/common/gpu/image_transport_surface.h @@ -8,9 +8,12 @@ #if defined(ENABLE_GPU) +#include "base/callback.h" #include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "ipc/ipc_channel.h" #include "ipc/ipc_message.h" +#include "ui/gfx/gl/gl_surface.h" #include "ui/gfx/size.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/surface/transport_dib.h" @@ -48,9 +51,13 @@ class GLES2Decoder; class ImageTransportSurface { public: + ImageTransportSurface(); + virtual ~ImageTransportSurface(); + virtual void OnNewSurfaceACK( uint64 surface_id, TransportDIB::Handle surface_handle) = 0; virtual void OnBuffersSwappedACK() = 0; + virtual void OnResizeViewACK() = 0; virtual void OnResize(gfx::Size size) = 0; // Creates the appropriate surface depending on the GL implementation. @@ -60,6 +67,8 @@ class ImageTransportSurface { int32 renderer_id, int32 command_buffer_id, gfx::PluginWindowHandle handle); + private: + DISALLOW_COPY_AND_ASSIGN(ImageTransportSurface); }; class ImageTransportHelper : public IPC::Channel::Listener { @@ -87,10 +96,13 @@ class ImageTransportHelper : public IPC::Channel::Listener { GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params); void SendAcceleratedSurfaceRelease( GpuHostMsg_AcceleratedSurfaceRelease_Params params); + void SendResizeView(const gfx::Size& size); // Whether or not we should execute more commands. void SetScheduled(bool is_scheduled); + void DeferToFence(base::Closure task); + // Make the surface's context current. bool MakeCurrent(); @@ -101,10 +113,14 @@ class ImageTransportHelper : public IPC::Channel::Listener { // IPC::Message handlers. void OnNewSurfaceACK(uint64 surface_id, TransportDIB::Handle surface_handle); void OnBuffersSwappedACK(); + void OnResizeViewACK(); // Backbuffer resize callback. void Resize(gfx::Size size); + // Set the default swap interval on the surface. + void SetSwapInterval(); + // Weak pointers that point to objects that outlive this helper. ImageTransportSurface* surface_; GpuChannelManager* manager_; @@ -118,6 +134,36 @@ class ImageTransportHelper : public IPC::Channel::Listener { DISALLOW_COPY_AND_ASSIGN(ImageTransportHelper); }; +// An implementation of ImageTransportSurface that implements GLSurface through +// GLSurfaceAdapter, thereby forwarding GLSurface methods through to it. +class PassThroughImageTransportSurface + : public gfx::GLSurfaceAdapter, + public ImageTransportSurface { + public: + PassThroughImageTransportSurface(GpuChannelManager* manager, + int32 render_view_id, + int32 renderer_id, + int32 command_buffer_id, + gfx::GLSurface* surface); + virtual ~PassThroughImageTransportSurface(); + + // GLSurface implementation. + virtual bool Initialize(); + virtual void Destroy(); + + // ImageTransportSurface implementation. + virtual void OnNewSurfaceACK( + uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; + virtual void OnBuffersSwappedACK() OVERRIDE; + virtual void OnResizeViewACK() OVERRIDE; + virtual void OnResize(gfx::Size size) OVERRIDE; + + private: + scoped_ptr<ImageTransportHelper> helper_; + + DISALLOW_COPY_AND_ASSIGN(PassThroughImageTransportSurface); +}; + #endif // defined(ENABLE_GPU) #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ diff --git a/content/common/gpu/image_transport_surface_linux.cc b/content/common/gpu/image_transport_surface_linux.cc index 5cc75ba..bcb1284 100644 --- a/content/common/gpu/image_transport_surface_linux.cc +++ b/content/common/gpu/image_transport_surface_linux.cc @@ -77,6 +77,7 @@ class EGLImageTransportSurface : public ImageTransportSurface, virtual void OnNewSurfaceACK( uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; virtual void OnBuffersSwappedACK() OVERRIDE; + virtual void OnResizeViewACK() OVERRIDE; virtual void OnResize(gfx::Size size) OVERRIDE; private: @@ -119,6 +120,7 @@ class GLXImageTransportSurface : public ImageTransportSurface, virtual void OnNewSurfaceACK( uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; virtual void OnBuffersSwappedACK() OVERRIDE; + virtual void OnResizeViewACK() OVERRIDE; virtual void OnResize(gfx::Size size) OVERRIDE; private: @@ -167,6 +169,7 @@ class OSMesaImageTransportSurface : public ImageTransportSurface, virtual void OnNewSurfaceACK( uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; virtual void OnBuffersSwappedACK() OVERRIDE; + virtual void OnResizeViewACK() OVERRIDE; virtual void OnResize(gfx::Size size) OVERRIDE; private: @@ -374,6 +377,11 @@ void EGLImageTransportSurface::OnBuffersSwappedACK() { helper_->SetScheduled(true); } + +void EGLImageTransportSurface::OnResizeViewACK() { + NOTREACHED(); +} + GLXImageTransportSurface::GLXImageTransportSurface( GpuChannelManager* manager, int32 render_view_id, @@ -539,6 +547,10 @@ void GLXImageTransportSurface::OnBuffersSwappedACK() { helper_->SetScheduled(true); } +void GLXImageTransportSurface::OnResizeViewACK() { + NOTREACHED(); +} + OSMesaImageTransportSurface::OSMesaImageTransportSurface( GpuChannelManager* manager, int32 render_view_id, @@ -617,6 +629,10 @@ void OSMesaImageTransportSurface::OnNewSurfaceACK( helper_->SetScheduled(true); } +void OSMesaImageTransportSurface::OnResizeViewACK() { + NOTREACHED(); +} + bool OSMesaImageTransportSurface::SwapBuffers() { DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); @@ -648,8 +664,9 @@ scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( int32 render_view_id, int32 renderer_id, int32 command_buffer_id, - gfx::PluginWindowHandle /* handle */) { + gfx::PluginWindowHandle handle) { scoped_refptr<gfx::GLSurface> surface; +#if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) switch (gfx::GetGLImplementation()) { case gfx::kGLImplementationDesktopGL: surface = new GLXImageTransportSurface(manager, @@ -673,6 +690,17 @@ scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( NOTREACHED(); return NULL; } +#else + surface = gfx::GLSurface::CreateViewGLSurface(false, handle); + if (!surface.get()) + return NULL; + + surface = new PassThroughImageTransportSurface(manager, + render_view_id, + renderer_id, + command_buffer_id, + surface.get()); +#endif if (surface->Initialize()) return surface; else diff --git a/content/common/gpu/image_transport_surface_mac.cc b/content/common/gpu/image_transport_surface_mac.cc index 09d3521..8449f81 100644 --- a/content/common/gpu/image_transport_surface_mac.cc +++ b/content/common/gpu/image_transport_surface_mac.cc @@ -43,6 +43,7 @@ class IOSurfaceImageTransportSurface : public gfx::PbufferGLSurfaceCGL, virtual void OnNewSurfaceACK(uint64 surface_id, TransportDIB::Handle shm_handle) OVERRIDE; virtual void OnBuffersSwappedACK() OVERRIDE; + virtual void OnResizeViewACK() OVERRIDE; virtual void OnResize(gfx::Size size) OVERRIDE; private: @@ -94,6 +95,7 @@ class TransportDIBImageTransportSurface : public gfx::PbufferGLSurfaceCGL, virtual void OnBuffersSwappedACK() OVERRIDE; virtual void OnNewSurfaceACK(uint64 surface_id, TransportDIB::Handle shm_handle) OVERRIDE; + virtual void OnResizeViewACK() OVERRIDE; virtual void OnResize(gfx::Size size) OVERRIDE; private: @@ -239,6 +241,10 @@ void IOSurfaceImageTransportSurface::OnNewSurfaceACK( helper_->SetScheduled(true); } +void IOSurfaceImageTransportSurface::OnResizeViewACK() { + NOTREACHED(); +} + void IOSurfaceImageTransportSurface::OnResize(gfx::Size size) { IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); @@ -443,6 +449,10 @@ void TransportDIBImageTransportSurface::OnNewSurfaceACK( DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); } +void TransportDIBImageTransportSurface::OnResizeViewACK() { + NOTREACHED(); +} + void TransportDIBImageTransportSurface::OnResize(gfx::Size size) { size_ = size; diff --git a/content/common/gpu/image_transport_surface_win.cc b/content/common/gpu/image_transport_surface_win.cc new file mode 100644 index 0000000..91040fe --- /dev/null +++ b/content/common/gpu/image_transport_surface_win.cc @@ -0,0 +1,176 @@ +// Copyright (c) 2011 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. + +#if defined(ENABLE_GPU) + +#include "content/common/gpu/image_transport_surface.h" + +#include "base/bind.h" +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "base/win/windows_version.h" +#include "content/common/gpu/gpu_messages.h" +#include "ui/gfx/gl/gl_bindings.h" +#include "ui/gfx/gl/gl_context.h" +#include "ui/gfx/gl/gl_implementation.h" +#include "ui/gfx/gl/gl_surface_egl.h" +#include "ui/gfx/native_widget_types.h" + +namespace { + +// We are backed by an Pbuffer offscreen surface through which ANGLE provides +// a handle to the corresponding render target texture through an extension. +class PbufferImageTransportSurface + : public gfx::GLSurfaceAdapter, + public ImageTransportSurface, + public base::SupportsWeakPtr<PbufferImageTransportSurface> { + public: + PbufferImageTransportSurface(GpuChannelManager* manager, + int32 render_view_id, + int32 renderer_id, + int32 command_buffer_id); + + // GLSurface implementation + virtual bool Initialize(); + virtual void Destroy(); + virtual bool IsOffscreen(); + virtual bool SwapBuffers(); + + protected: + // ImageTransportSurface implementation + virtual void OnNewSurfaceACK(uint64 surface_id, + TransportDIB::Handle shm_handle) OVERRIDE; + virtual void OnBuffersSwappedACK() OVERRIDE; + virtual void OnResizeViewACK() OVERRIDE; + virtual void OnResize(gfx::Size size) OVERRIDE; + + private: + virtual ~PbufferImageTransportSurface(); + void SendBuffersSwapped(); + + scoped_ptr<ImageTransportHelper> helper_; + + DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); +}; + +PbufferImageTransportSurface::PbufferImageTransportSurface( + GpuChannelManager* manager, + int32 render_view_id, + int32 renderer_id, + int32 command_buffer_id) + : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, + gfx::Size(1, 1))) { + helper_.reset(new ImageTransportHelper(this, + manager, + render_view_id, + renderer_id, + command_buffer_id, + gfx::kNullPluginWindow)); +} + +PbufferImageTransportSurface::~PbufferImageTransportSurface() { + Destroy(); +} + +bool PbufferImageTransportSurface::Initialize() { + // Only support this path if the GL implementation is ANGLE. + // IO surfaces will not work with, for example, OSMesa software renderer + // GL contexts. + if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) + return false; + + if (!helper_->Initialize()) + return false; + + return GLSurfaceAdapter::Initialize(); +} + +void PbufferImageTransportSurface::Destroy() { + helper_->Destroy(); + GLSurfaceAdapter::Destroy(); +} + +bool PbufferImageTransportSurface::IsOffscreen() { + return false; +} + +bool PbufferImageTransportSurface::SwapBuffers() { + HANDLE surface_handle = GetShareHandle(); + if (!surface_handle) + return false; + + helper_->DeferToFence(base::Bind( + &PbufferImageTransportSurface::SendBuffersSwapped, + AsWeakPtr())); + + return true; +} + +void PbufferImageTransportSurface::SendBuffersSwapped() { + GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; + params.surface_id = reinterpret_cast<int64>(GetShareHandle()); + params.size = GetSize(); + helper_->SendAcceleratedSurfaceBuffersSwapped(params); + + helper_->SetScheduled(false); +} + +void PbufferImageTransportSurface::OnBuffersSwappedACK() { + helper_->SetScheduled(true); +} + +void PbufferImageTransportSurface::OnNewSurfaceACK( + uint64 surface_id, + TransportDIB::Handle shm_handle) { + NOTIMPLEMENTED(); +} + +void PbufferImageTransportSurface::OnResizeViewACK() { + NOTIMPLEMENTED(); +} + +void PbufferImageTransportSurface::OnResize(gfx::Size size) { + Resize(size); +} + +} // namespace anonymous + +// static +scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( + GpuChannelManager* manager, + int32 render_view_id, + int32 renderer_id, + int32 command_buffer_id, + gfx::PluginWindowHandle handle) { + scoped_refptr<gfx::GLSurface> surface; + + base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); + + // TODO(apatrick): Enable this once it has settled in the tree. + if (false && gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && + os_info->version() >= base::win::VERSION_VISTA) { + surface = new PbufferImageTransportSurface(manager, + render_view_id, + renderer_id, + command_buffer_id); + } else { + surface = gfx::GLSurface::CreateViewGLSurface(false, handle); + if (!surface.get()) + return NULL; + + surface = new PassThroughImageTransportSurface(manager, + render_view_id, + renderer_id, + command_buffer_id, + surface.get()); + } + + if (surface->Initialize()) + return surface; + else + return NULL; +} + +#endif // ENABLE_GPU |