diff options
author | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-12 22:38:10 +0000 |
---|---|---|
committer | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-12 22:38:10 +0000 |
commit | 0d5bfb0221d1ce4fca44e1452c634082db562903 (patch) | |
tree | 2bf364b6a6f424c39cab3658df63bc65c1055023 | |
parent | 20cd5336b53401e691f0ee388d2dd646abc32204 (diff) | |
download | chromium_src-0d5bfb0221d1ce4fca44e1452c634082db562903.zip chromium_src-0d5bfb0221d1ce4fca44e1452c634082db562903.tar.gz chromium_src-0d5bfb0221d1ce4fca44e1452c634082db562903.tar.bz2 |
Make class anonymous and don't assume default FBO is active on Resize.
Small refactor to move a class into an anonymous namespace. Small change to preserve the active FBO when resizing the EGLImageTransportSurface.
BUG=none
TEST=open and close 3D CSS tabs on TOUCH_UI
Review URL: http://codereview.chromium.org/8241006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105185 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/common/gpu/image_transport_surface_linux.cc | 77 | ||||
-rw-r--r-- | ui/gfx/surface/accelerated_surface_linux.cc | 48 | ||||
-rw-r--r-- | ui/gfx/surface/accelerated_surface_linux.h | 35 | ||||
-rw-r--r-- | ui/gfx/surface/surface.gyp | 10 |
4 files changed, 70 insertions, 100 deletions
diff --git a/content/common/gpu/image_transport_surface_linux.cc b/content/common/gpu/image_transport_surface_linux.cc index 8c01101..079294f2 100644 --- a/content/common/gpu/image_transport_surface_linux.cc +++ b/content/common/gpu/image_transport_surface_linux.cc @@ -27,10 +27,30 @@ #include "ui/gfx/gl/gl_surface_egl.h" #include "ui/gfx/gl/gl_surface_glx.h" #include "ui/gfx/gl/gl_surface_osmesa.h" -#include "ui/gfx/surface/accelerated_surface_linux.h" namespace { +// The GL context associated with the surface must be current when +// an instance is created or destroyed. +class EGLAcceleratedSurface : public base::RefCounted<EGLAcceleratedSurface> { + public: + EGLAcceleratedSurface(const gfx::Size& size); + const gfx::Size& size() const { return size_; } + uint32 pixmap() const { return pixmap_; } + uint32 texture() const { return texture_; } + + private: + ~EGLAcceleratedSurface(); + + gfx::Size size_; + void* image_; + uint32 pixmap_; + uint32 texture_; + + friend class base::RefCounted<EGLAcceleratedSurface>; + DISALLOW_COPY_AND_ASSIGN(EGLAcceleratedSurface); +}; + // We are backed by an Pbuffer offscreen surface for the purposes of creating a // context, but use FBOs to render to X Pixmap backed EGLImages. class EGLImageTransportSurface : public ImageTransportSurface, @@ -59,12 +79,12 @@ class EGLImageTransportSurface : public ImageTransportSurface, private: virtual ~EGLImageTransportSurface() OVERRIDE; - void ReleaseSurface(scoped_refptr<AcceleratedSurface>* surface); + void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); uint32 fbo_id_; - scoped_refptr<AcceleratedSurface> back_surface_; - scoped_refptr<AcceleratedSurface> front_surface_; + scoped_refptr<EGLAcceleratedSurface> back_surface_; + scoped_refptr<EGLAcceleratedSurface> front_surface_; scoped_ptr<ImageTransportHelper> helper_; @@ -155,6 +175,42 @@ class OSMesaImageTransportSurface : public ImageTransportSurface, DISALLOW_COPY_AND_ASSIGN(OSMesaImageTransportSurface); }; +EGLAcceleratedSurface::EGLAcceleratedSurface(const gfx::Size& size) + : size_(size), texture_(0) { + Display* dpy = gfx::GLSurfaceEGL::GetNativeDisplay(); + EGLDisplay edpy = gfx::GLSurfaceEGL::GetHardwareDisplay(); + + XID window = XDefaultRootWindow(dpy); + XWindowAttributes gwa; + XGetWindowAttributes(dpy, window, &gwa); + pixmap_ = XCreatePixmap( + dpy, window, size_.width(), size_.height(), gwa.depth); + + image_ = eglCreateImageKHR( + edpy, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, + reinterpret_cast<void*>(pixmap_), NULL); + + glGenTextures(1, &texture_); + + GLint current_texture = 0; + glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture); + + glBindTexture(GL_TEXTURE_2D, texture_); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); + + glBindTexture(GL_TEXTURE_2D, current_texture); +} + +EGLAcceleratedSurface::~EGLAcceleratedSurface() { + glDeleteTextures(1, &texture_); + eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); + XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); +} + EGLImageTransportSurface::EGLImageTransportSurface( GpuChannelManager* manager, int32 render_view_id, @@ -215,7 +271,7 @@ unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { } void EGLImageTransportSurface::ReleaseSurface( - scoped_refptr<AcceleratedSurface>* surface) { + scoped_refptr<EGLAcceleratedSurface>* surface) { if (surface->get()) { GpuHostMsg_AcceleratedSurfaceRelease_Params params; params.identifier = (*surface)->pixmap(); @@ -228,7 +284,12 @@ void EGLImageTransportSurface::OnResize(gfx::Size size) { if (back_surface_.get()) ReleaseSurface(&back_surface_); - back_surface_ = new AcceleratedSurface(size); + back_surface_ = new EGLAcceleratedSurface(size); + + GLint previous_fbo_id = 0; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previous_fbo_id); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id_); glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, @@ -236,6 +297,8 @@ void EGLImageTransportSurface::OnResize(gfx::Size size) { 0); glFlush(); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previous_fbo_id); + GpuHostMsg_AcceleratedSurfaceNew_Params params; params.width = size.width(); params.height = size.height(); @@ -247,7 +310,7 @@ void EGLImageTransportSurface::OnResize(gfx::Size size) { bool EGLImageTransportSurface::SwapBuffers() { front_surface_.swap(back_surface_); - DCHECK_NE(front_surface_.get(), static_cast<AcceleratedSurface*>(NULL)); + DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); glFlush(); GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; diff --git a/ui/gfx/surface/accelerated_surface_linux.cc b/ui/gfx/surface/accelerated_surface_linux.cc deleted file mode 100644 index da2dde4..0000000 --- a/ui/gfx/surface/accelerated_surface_linux.cc +++ /dev/null @@ -1,48 +0,0 @@ -// 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. - -#include "ui/gfx/surface/accelerated_surface_linux.h" - -#include <X11/Xlib.h> - -#include "third_party/angle/include/EGL/egl.h" -#include "third_party/angle/include/EGL/eglext.h" -#include "ui/gfx/gl/gl_surface_egl.h" -#include "ui/gfx/gl/gl_bindings.h" - -AcceleratedSurface::AcceleratedSurface(const gfx::Size& size) - : size_(size) { - Display* dpy = gfx::GLSurfaceEGL::GetNativeDisplay(); - EGLDisplay edpy = gfx::GLSurfaceEGL::GetHardwareDisplay(); - - XID window = XDefaultRootWindow(dpy); - XWindowAttributes gwa; - XGetWindowAttributes(dpy, window, &gwa); - pixmap_ = XCreatePixmap( - dpy, window, size_.width(), size_.height(), gwa.depth); - - image_ = eglCreateImageKHR( - edpy, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, - reinterpret_cast<void*>(pixmap_), NULL); - - glGenTextures(1, &texture_); - - GLint current_texture = 0; - glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture); - - glBindTexture(GL_TEXTURE_2D, texture_); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); - - glBindTexture(GL_TEXTURE_2D, current_texture); -} - -AcceleratedSurface::~AcceleratedSurface() { - glDeleteTextures(1, &texture_); - eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); - XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); -} diff --git a/ui/gfx/surface/accelerated_surface_linux.h b/ui/gfx/surface/accelerated_surface_linux.h deleted file mode 100644 index e7882b8..0000000 --- a/ui/gfx/surface/accelerated_surface_linux.h +++ /dev/null @@ -1,35 +0,0 @@ -// 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. - -#ifndef UI_GFX_SURFACE_ACCELERATED_SURFACE_LINUX_H_ -#define UI_GFX_SURFACE_ACCELERATED_SURFACE_LINUX_H_ -#pragma once - -#include "base/memory/ref_counted.h" -#include "ui/gfx/size.h" -#include "ui/gfx/surface/surface_export.h" - -// The GL context associated with the surface must be current when -// an instance is created or destroyed. -class SURFACE_EXPORT AcceleratedSurface - : public base::RefCounted<AcceleratedSurface> { - public: - AcceleratedSurface(const gfx::Size& size); - const gfx::Size& size() const { return size_; } - uint32 pixmap() const { return pixmap_; } - uint32 texture() const { return texture_; } - - private: - ~AcceleratedSurface(); - - gfx::Size size_; - void* image_; - uint32 pixmap_; - uint32 texture_; - - friend class base::RefCounted<AcceleratedSurface>; - DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface); -}; - -#endif // UI_GFX_SURFACE_ACCELERATED_SURFACE_LINUX_H_ diff --git a/ui/gfx/surface/surface.gyp b/ui/gfx/surface/surface.gyp index 0a48f35..43190ba 100644 --- a/ui/gfx/surface/surface.gyp +++ b/ui/gfx/surface/surface.gyp @@ -27,8 +27,6 @@ '<(DEPTH)/ui/ui.gyp:ui', ], 'sources': [ - 'accelerated_surface_linux.cc', - 'accelerated_surface_linux.h', 'accelerated_surface_mac.cc', 'accelerated_surface_mac.h', 'accelerated_surface_wayland.cc', @@ -45,14 +43,6 @@ 'defines': [ 'SURFACE_IMPLEMENTATION', ], - 'conditions': [ - ['use_wayland == 1', { - 'sources/': [ - ['exclude', 'accelerated_surface_linux.cc'], - ['exclude', 'accelerated_surface_linux.h'], - ], - }], - ], }, ], } |