diff options
author | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 00:31:43 +0000 |
---|---|---|
committer | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 00:31:43 +0000 |
commit | 7359d132eb30095779eca7e76fa3724dc39d5461 (patch) | |
tree | 7252718756fde23b2289d26e6b7b5800e5f2c9df | |
parent | b9769d8d222724ddf22a109f51f3f91db9ec51dc (diff) | |
download | chromium_src-7359d132eb30095779eca7e76fa3724dc39d5461.zip chromium_src-7359d132eb30095779eca7e76fa3724dc39d5461.tar.gz chromium_src-7359d132eb30095779eca7e76fa3724dc39d5461.tar.bz2 |
Remove AcceleratedSurfaceContainerLinux
RenderWidgetHostViewAura can use the ImageTransportClient directly.
This simplifies the code a bit.
BUG=99516
TEST=run chrome aura, open poster circle.
Review URL: http://codereview.chromium.org/9373016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121357 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 98 insertions, 197 deletions
diff --git a/content/browser/renderer_host/accelerated_surface_container_linux.cc b/content/browser/renderer_host/accelerated_surface_container_linux.cc deleted file mode 100644 index 90ce064..0000000 --- a/content/browser/renderer_host/accelerated_surface_container_linux.cc +++ /dev/null @@ -1,63 +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 "content/browser/renderer_host/accelerated_surface_container_linux.h" - -#include "base/memory/scoped_ptr.h" -#include "content/browser/renderer_host/image_transport_client.h" -#include "ui/gfx/gl/gl_bindings.h" -#include "ui/gfx/gl/scoped_make_current.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/transform.h" - -AcceleratedSurfaceContainerLinux::AcceleratedSurfaceContainerLinux( - const gfx::Size& size) - : acquired_(false) { - size_ = size; -} - -AcceleratedSurfaceContainerLinux::~AcceleratedSurfaceContainerLinux() { - if (texture_id_) { - ui::SharedResources* instance = ui::SharedResources::GetInstance(); - DCHECK(instance); - scoped_ptr<gfx::ScopedMakeCurrent> bind(instance->GetScopedMakeCurrent()); - glDeleteTextures(1, &texture_id_); - } - - if (image_transport_client_.get()) - image_transport_client_->Release(); -} - -bool AcceleratedSurfaceContainerLinux::Initialize(uint64* surface_handle) { - ui::SharedResources* instance = ui::SharedResources::GetInstance(); - DCHECK(instance); - image_transport_client_.reset( - ImageTransportClient::Create(instance, size_)); - if (!image_transport_client_.get()) - return false; - - texture_id_ = image_transport_client_->Initialize(surface_handle); - if (!texture_id_) { - image_transport_client_.reset(); - return false; - } - flipped_ = image_transport_client_->Flipped(); - return true; -} - -// Texture implementation -void AcceleratedSurfaceContainerLinux::Update() { - ui::SharedResources* instance = ui::SharedResources::GetInstance(); - DCHECK(instance); - scoped_ptr<gfx::ScopedMakeCurrent> bind(instance->GetScopedMakeCurrent()); - if (acquired_) - image_transport_client_->Release(); - else - acquired_ = true; - image_transport_client_->Acquire(); -} - -TransportDIB::Handle AcceleratedSurfaceContainerLinux::Handle() const { - return image_transport_client_->Handle(); -} diff --git a/content/browser/renderer_host/accelerated_surface_container_linux.h b/content/browser/renderer_host/accelerated_surface_container_linux.h deleted file mode 100644 index 129644a..0000000 --- a/content/browser/renderer_host/accelerated_surface_container_linux.h +++ /dev/null @@ -1,41 +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 CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_SURFACE_CONTAINER_LINUX_H_ -#define CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_SURFACE_CONTAINER_LINUX_H_ -#pragma once - -#include "base/basictypes.h" -#include "ui/gfx/compositor/compositor.h" -#include "ui/gfx/surface/transport_dib.h" - -class ImageTransportClient; - -// Helper class for storing image data from the GPU process renderered -// on behalf of the RWHVV. It assumes that GL context that will display -// the image data is current when an instance of this object is created -// or destroyed. -class AcceleratedSurfaceContainerLinux : public ui::Texture { - public: - explicit AcceleratedSurfaceContainerLinux(const gfx::Size& size); - virtual ~AcceleratedSurfaceContainerLinux(); - - // Initialize the surface container, and returns an ID for it. - // The |surface_handle| given to this function may be modified, and the - // modified value should be used to identify the object. - bool Initialize(uint64* surface_handle); - - // Some implementations of this class use shared memory, this is the handle - // to the shared buffer, which is part of the surface container. - TransportDIB::Handle Handle() const; - - void Update(); - - private: - scoped_ptr<ImageTransportClient> image_transport_client_; - bool acquired_; - DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerLinux); -}; - -#endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_SURFACE_CONTAINER_LINUX_H_ diff --git a/content/browser/renderer_host/image_transport_client.cc b/content/browser/renderer_host/image_transport_client.cc index bec2d71..96c2ff1 100644 --- a/content/browser/renderer_host/image_transport_client.cc +++ b/content/browser/renderer_host/image_transport_client.cc @@ -10,6 +10,7 @@ #include "base/debug/trace_event.h" #include "base/lazy_instance.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop.h" #include "third_party/angle/include/EGL/egl.h" #include "third_party/angle/include/EGL/eglext.h" #include "ui/gfx/gl/gl_bindings.h" @@ -41,37 +42,36 @@ GLuint CreateTexture() { class ImageTransportClientEGL : public ImageTransportClient { public: - explicit ImageTransportClientEGL(ui::SharedResources* resources) - : resources_(resources), + ImageTransportClientEGL(ui::SharedResources* resources, const gfx::Size& size) + : ImageTransportClient(true, size), + resources_(resources), image_(NULL) { } virtual ~ImageTransportClientEGL() { - if (image_) { - scoped_ptr<gfx::ScopedMakeCurrent> bind( - resources_->GetScopedMakeCurrent()); + scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); + if (image_) eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); - glFlush(); - } + if (texture_id_) + glDeleteTextures(1, &texture_id_); + glFlush(); } - virtual unsigned int Initialize(uint64* surface_handle) { + virtual bool Initialize(uint64* surface_handle) { scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); image_ = eglCreateImageKHR( gfx::GLSurfaceEGL::GetHardwareDisplay(), EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<void*>(*surface_handle), NULL); if (!image_) - return 0; - GLuint texture = CreateTexture(); - glBindTexture(GL_TEXTURE_2D, texture); + return false; + texture_id_ = CreateTexture(); + glBindTexture(GL_TEXTURE_2D, texture_id_); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); glFlush(); - return texture; + return true; } - virtual void Acquire() { } - virtual void Release() { } - virtual bool Flipped() { return true; } + virtual void Update() { } virtual TransportDIB::Handle Handle() const { return TransportDIB::DefaultHandleValue(); } @@ -85,28 +85,36 @@ class ImageTransportClientEGL : public ImageTransportClient { class ImageTransportClientGLX : public ImageTransportClient { public: - explicit ImageTransportClientGLX(ui::SharedResources* resources) - : resources_(resources), + ImageTransportClientGLX(ui::SharedResources* resources, const gfx::Size& size) + : ImageTransportClient(false, size), + resources_(resources), pixmap_(0), glx_pixmap_(0), - texture_(0) { + acquired_(false) { } virtual ~ImageTransportClientGLX() { - Display* dpy = static_cast<Display*>(resources_->GetDisplay()); - if (glx_pixmap_) + scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); + Display* dpy = base::MessagePumpForUI::GetDefaultXDisplay(); + if (glx_pixmap_) { + if (acquired_) + glXReleaseTexImageEXT(dpy, glx_pixmap_, GLX_FRONT_LEFT_EXT); glXDestroyGLXPixmap(dpy, glx_pixmap_); + } if (pixmap_) XFreePixmap(dpy, pixmap_); + if (texture_id_) + glDeleteTextures(1, &texture_id_); + glFlush(); } - virtual unsigned int Initialize(uint64* surface_handle) { + virtual bool Initialize(uint64* surface_handle) { TRACE_EVENT0("renderer_host", "ImageTransportClientGLX::Initialize"); - Display* dpy = static_cast<Display*>(resources_->GetDisplay()); + Display* dpy = base::MessagePumpForUI::GetDefaultXDisplay(); scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); if (!InitializeOneOff(dpy)) - return 0; + return false; // Create pixmap from window. // We receive a window here rather than a pixmap directly because drivers @@ -122,24 +130,23 @@ class ImageTransportClientGLX : public ImageTransportClient { glx_pixmap_ = glXCreatePixmap(dpy, fbconfig_.Get(), pixmap_, pixmapAttribs); - texture_ = CreateTexture(); - return texture_; + texture_id_ = CreateTexture(); + glFlush(); + return true; } - virtual void Acquire() { - TRACE_EVENT0("renderer_host", "ImageTransportClientGLX::Acquire"); - Display* dpy = static_cast<Display*>(resources_->GetDisplay()); - glBindTexture(GL_TEXTURE_2D, texture_); + virtual void Update() { + TRACE_EVENT0("renderer_host", "ImageTransportClientGLX::Update"); + Display* dpy = base::MessagePumpForUI::GetDefaultXDisplay(); + scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); + glBindTexture(GL_TEXTURE_2D, texture_id_); + if (acquired_) + glXReleaseTexImageEXT(dpy, glx_pixmap_, GLX_FRONT_LEFT_EXT); glXBindTexImageEXT(dpy, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL); + acquired_ = true; + glFlush(); } - virtual void Release() { - TRACE_EVENT0("renderer_host", "ImageTransportClientGLX::Release"); - Display* dpy = static_cast<Display*>(resources_->GetDisplay()); - glXReleaseTexImageEXT(dpy, glx_pixmap_, GLX_FRONT_LEFT_EXT); - } - - virtual bool Flipped() { return false; } virtual TransportDIB::Handle Handle() const { return TransportDIB::DefaultHandleValue(); } @@ -214,7 +221,7 @@ class ImageTransportClientGLX : public ImageTransportClient { ui::SharedResources* resources_; XID pixmap_; XID glx_pixmap_; - GLuint texture_; + bool acquired_; static base::LazyInstance<GLXFBConfig> fbconfig_; }; @@ -225,15 +232,20 @@ class ImageTransportClientOSMesa : public ImageTransportClient { public: ImageTransportClientOSMesa(ui::SharedResources* resources, const gfx::Size& size) - : resources_(resources), - size_(size), - texture_(0) { + : ImageTransportClient(false, size), + resources_(resources) { } virtual ~ImageTransportClientOSMesa() { + if (texture_id_) { + scoped_ptr<gfx::ScopedMakeCurrent> bind( + resources_->GetScopedMakeCurrent()); + glDeleteTextures(1, &texture_id_); + glFlush(); + } } - virtual unsigned int Initialize(uint64* surface_handle) { + virtual bool Initialize(uint64* surface_handle) { // We expect to make the handle here, so don't want the other end giving us // one. DCHECK_EQ(*surface_handle, static_cast<uint64>(0)); @@ -248,29 +260,27 @@ class ImageTransportClientOSMesa : public ImageTransportClient { TransportDIB::Create(size_.GetArea() * 4, // GL_RGBA=4 B/px *surface_handle)); if (!shared_mem_.get()) - return 0; + return false; scoped_ptr<gfx::ScopedMakeCurrent> bind(resources_->GetScopedMakeCurrent()); - texture_ = CreateTexture(); - return texture_; + texture_id_ = CreateTexture(); + glFlush(); + return true; } - virtual void Acquire() { - glBindTexture(GL_TEXTURE_2D, texture_); + virtual void Update() { + glBindTexture(GL_TEXTURE_2D, texture_id_); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, shared_mem_->memory()); + glFlush(); } - virtual void Release() { } - virtual bool Flipped() { return false; } virtual TransportDIB::Handle Handle() const { return shared_mem_->handle(); } private: ui::SharedResources* resources_; - gfx::Size size_; scoped_ptr<TransportDIB> shared_mem_; - GLuint texture_; static uint32 next_handle_; }; uint32 ImageTransportClientOSMesa::next_handle_ = 0; @@ -279,6 +289,10 @@ uint32 ImageTransportClientOSMesa::next_handle_ = 0; } // anonymous namespace +ImageTransportClient::ImageTransportClient(bool flipped, const gfx::Size& size) + : ui::Texture(flipped, size) { +} + ImageTransportClient* ImageTransportClient::Create( ui::SharedResources* resources, const gfx::Size& size) { @@ -287,10 +301,10 @@ ImageTransportClient* ImageTransportClient::Create( case gfx::kGLImplementationOSMesaGL: return new ImageTransportClientOSMesa(resources, size); case gfx::kGLImplementationDesktopGL: - return new ImageTransportClientGLX(resources); + return new ImageTransportClientGLX(resources, size); #endif case gfx::kGLImplementationEGLGLES2: - return new ImageTransportClientEGL(resources); + return new ImageTransportClientEGL(resources, size); default: NOTREACHED(); return NULL; diff --git a/content/browser/renderer_host/image_transport_client.h b/content/browser/renderer_host/image_transport_client.h index 4981a31..e11e9ae 100644 --- a/content/browser/renderer_host/image_transport_client.h +++ b/content/browser/renderer_host/image_transport_client.h @@ -17,23 +17,16 @@ class Size; // This is a client for ImageTransportSurface, that handles the // platform-specific task of binding the transport surface to a GL texture. // The GL texture is allocated in the SharedResources context, and the data is -// only valid between Acquire and Release. -class ImageTransportClient { +// only valid after the first Update(). +class ImageTransportClient : public ui::Texture { public: virtual ~ImageTransportClient() {} - // Initializes the client with the surface id. This returns the GL texture id, - // or 0 if error. - virtual unsigned int Initialize(uint64* surface_handle) = 0; + // Initializes the client with the surface id. + virtual bool Initialize(uint64* surface_handle) = 0; - // Gets the surface data into the texture. - virtual void Acquire() = 0; - - // Releases the surface data. - virtual void Release() = 0; - - // Returns whether the data is flipped in the Y direction. - virtual bool Flipped() = 0; + // Updates the surface data into the texture. + virtual void Update() = 0; // Returns the shared memory handle used to transfer software data if needed. // Can be a NULL handle. @@ -42,6 +35,12 @@ class ImageTransportClient { // Creates a platform-specific client. static ImageTransportClient* Create(ui::SharedResources* resources, const gfx::Size& size); + + protected: + ImageTransportClient(bool flipped, const gfx::Size& size); + + private: + DISALLOW_COPY_AND_ASSIGN(ImageTransportClient); }; #endif // CONTENT_BROWSER_RENDERER_HOST_IMAGE_TRANSPORT_CLIENT_H_ diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 25a8fcd..63b316c 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -31,8 +31,7 @@ #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) #include "base/bind.h" -#include "content/browser/renderer_host/accelerated_surface_container_linux.h" -#include "ui/gfx/gl/gl_bindings.h" +#include "content/browser/renderer_host/image_transport_client.h" #endif using WebKit::WebTouchEvent; @@ -364,12 +363,11 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() { #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) if (current_surface_ != gfx::kNullPluginWindow && host_->is_accelerated_compositing_active()) { - AcceleratedSurfaceContainerLinux* container = - accelerated_surface_containers_[current_surface_]; + ImageTransportClient* container = + image_transport_clients_[current_surface_]; if (container) container->Update(); window_->SetExternalTexture(container); - glFlush(); } else { window_->SetExternalTexture(NULL); } @@ -390,7 +388,7 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( RenderWidgetHost::AcknowledgeSwapBuffers(params.route_id, gpu_host_id); } else { gfx::Size surface_size = - accelerated_surface_containers_[params.surface_handle]->size(); + image_transport_clients_[params.surface_handle]->size(); window_->SchedulePaintInRect(gfx::Rect(surface_size)); // Add sending an ACK to the list of things to do OnCompositingEnded @@ -419,7 +417,7 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( RenderWidgetHost::AcknowledgePostSubBuffer(params.route_id, gpu_host_id); } else { gfx::Size surface_size = - accelerated_surface_containers_[params.surface_handle]->size(); + image_transport_clients_[params.surface_handle]->size(); // Co-ordinates come in OpenGL co-ordinate space. // We need to convert to layer space. @@ -450,15 +448,17 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceNew( int32 height, uint64* surface_handle, TransportDIB::Handle* shm_handle) { - scoped_refptr<AcceleratedSurfaceContainerLinux> surface( - new AcceleratedSurfaceContainerLinux(gfx::Size(width, height))); - if (!surface->Initialize(surface_handle)) { - LOG(ERROR) << "Failed to create AcceleratedSurfaceContainer"; + ui::SharedResources* instance = ui::SharedResources::GetInstance(); + DCHECK(instance); + scoped_refptr<ImageTransportClient> surface( + ImageTransportClient::Create(instance, gfx::Size(width, height))); + if (!surface || !surface->Initialize(surface_handle)) { + LOG(ERROR) << "Failed to create ImageTransportClient"; return; } *shm_handle = surface->Handle(); - accelerated_surface_containers_[*surface_handle] = surface; + image_transport_clients_[*surface_handle] = surface; } void RenderWidgetHostViewAura::AcceleratedSurfaceRelease( @@ -470,7 +470,7 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceRelease( // flip back and forth. Instead wait until we got the accelerated // compositing deactivation. } - accelerated_surface_containers_.erase(surface_handle); + image_transport_clients_.erase(surface_handle); } #endif diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h index a60a589..f7c1ea6 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.h +++ b/content/browser/renderer_host/render_widget_host_view_aura.h @@ -35,7 +35,7 @@ class WebTouchEvent; } #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) -class AcceleratedSurfaceContainerLinux; +class ImageTransportClient; #endif class CONTENT_EXPORT RenderWidgetHostViewAura @@ -247,8 +247,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAura #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) std::vector< base::Callback<void(void)> > on_compositing_ended_callbacks_; - std::map<uint64, scoped_refptr<AcceleratedSurfaceContainerLinux> > - accelerated_surface_containers_; + std::map<uint64, scoped_refptr<ImageTransportClient> > + image_transport_clients_; gfx::PluginWindowHandle current_surface_; #endif diff --git a/content/content_browser.gypi b/content/content_browser.gypi index c4e926a..49e46af 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -408,8 +408,6 @@ 'browser/quota_permission_context.h', 'browser/renderer_host/accelerated_plugin_view_mac.h', 'browser/renderer_host/accelerated_plugin_view_mac.mm', - 'browser/renderer_host/accelerated_surface_container_linux.cc', - 'browser/renderer_host/accelerated_surface_container_linux.h', 'browser/renderer_host/accelerated_surface_container_mac.cc', 'browser/renderer_host/accelerated_surface_container_mac.h', 'browser/renderer_host/accelerated_surface_container_manager_mac.cc', @@ -839,8 +837,6 @@ ], }, { 'sources/': [ - ['exclude', '^browser/renderer_host/accelerated_surface_container_linux.cc'], - ['exclude', '^browser/renderer_host/accelerated_surface_container_linux.h'], ['exclude', '^browser/renderer_host/image_transport_client.cc'], ['exclude', '^browser/renderer_host/image_transport_client.h'], ], diff --git a/ui/gfx/compositor/compositor.cc b/ui/gfx/compositor/compositor.cc index 507e9d2..cd143a9 100644 --- a/ui/gfx/compositor/compositor.cc +++ b/ui/gfx/compositor/compositor.cc @@ -104,18 +104,15 @@ gfx::ScopedMakeCurrent* SharedResources::GetScopedMakeCurrent() { return NULL; } -void* SharedResources::GetDisplay() { - return surface_->GetDisplay(); -} - gfx::GLShareGroup* SharedResources::GetShareGroup() { DCHECK(initialized_); return context_->share_group(); } -Texture::Texture() +Texture::Texture(bool flipped, const gfx::Size& size) : texture_id_(0), - flipped_(false) { + flipped_(flipped), + size_(size) { } Texture::~Texture() { diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h index b6566fe..d946572 100644 --- a/ui/gfx/compositor/compositor.h +++ b/ui/gfx/compositor/compositor.h @@ -42,7 +42,6 @@ class COMPOSITOR_EXPORT SharedResources { // Note: Caller is responsible for managing lifetime of returned pointer. gfx::ScopedMakeCurrent* GetScopedMakeCurrent(); - void* GetDisplay(); gfx::GLShareGroup* GetShareGroup(); private: @@ -66,7 +65,7 @@ class COMPOSITOR_EXPORT SharedResources { // to a layer. class COMPOSITOR_EXPORT Texture : public base::RefCounted<Texture> { public: - Texture(); + Texture(bool flipped, const gfx::Size& size); virtual ~Texture(); unsigned int texture_id() const { return texture_id_; } |