diff options
author | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-19 10:22:56 +0000 |
---|---|---|
committer | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-19 10:22:56 +0000 |
commit | 8a48e732c0dc67b22f0b2cdce8bf750e273a4628 (patch) | |
tree | a3f0260baa264de95d1ffb21815ebcf223dfdee2 /ui | |
parent | 10ebc9183caa8dd392ec89cc6c571332c4194741 (diff) | |
download | chromium_src-8a48e732c0dc67b22f0b2cdce8bf750e273a4628.zip chromium_src-8a48e732c0dc67b22f0b2cdce8bf750e273a4628.tar.gz chromium_src-8a48e732c0dc67b22f0b2cdce8bf750e273a4628.tar.bz2 |
gpu: Add Will/DidUseTexImage to GLImage API.
WillUseTexImage/DidUseTexImage is called before/after the image is
used for sampling. The result is that the client only has to call
bind/releaseTexImage2D when contents have changed, which allows
for more efficient GLImage implementations as work required before
use can be separated from work required when contents have changed.
BUG=261649
TEST=gpu_unittests --gtest_filter=SharedTextureTest.Images && gpu_unittests --gtest_filter=GLES2DecoderWithShaderTest.UseTexImage && cc_unittests --gtest_filter=ResourceProviderTests/ResourceProviderTest.Image_GLTexture* && gl_tests --gtest_filter=MockGpuMemoryBufferTest.Lifecycle
Review URL: https://codereview.chromium.org/23129010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gl/gl_image.cc | 8 | ||||
-rw-r--r-- | ui/gl/gl_image.h | 6 | ||||
-rw-r--r-- | ui/gl/gl_image_egl.cc | 55 | ||||
-rw-r--r-- | ui/gl/gl_image_egl.h | 3 | ||||
-rw-r--r-- | ui/gl/gl_image_glx.cc | 10 | ||||
-rw-r--r-- | ui/gl/gl_image_glx.h | 2 | ||||
-rw-r--r-- | ui/gl/gl_image_shm.cc | 14 | ||||
-rw-r--r-- | ui/gl/gl_image_shm.h | 2 | ||||
-rw-r--r-- | ui/gl/gl_image_stub.cc | 13 | ||||
-rw-r--r-- | ui/gl/gl_image_stub.h | 4 |
10 files changed, 90 insertions, 27 deletions
diff --git a/ui/gl/gl_image.cc b/ui/gl/gl_image.cc index aaefb94..ff7eb56 100644 --- a/ui/gl/gl_image.cc +++ b/ui/gl/gl_image.cc @@ -19,6 +19,14 @@ void GLImage::ReleaseTexImage() { NOTIMPLEMENTED(); } +void GLImage::WillUseTexImage() { + NOTIMPLEMENTED(); +} + +void GLImage::DidUseTexImage() { + NOTIMPLEMENTED(); +} + GLImage::~GLImage() {} } // namespace gfx diff --git a/ui/gl/gl_image.h b/ui/gl/gl_image.h index 8d59bc4..859966c 100644 --- a/ui/gl/gl_image.h +++ b/ui/gl/gl_image.h @@ -33,6 +33,12 @@ class GL_EXPORT GLImage : public base::RefCounted<GLImage> { // Release image from texture currently bound to GL_TEXTURE_2D target. virtual void ReleaseTexImage(); + // Called before the texture is used for drawing. + virtual void WillUseTexImage(); + + // Called after the texture has been used for drawing. + virtual void DidUseTexImage(); + // Create a GL image for a window. static scoped_refptr<GLImage> CreateGLImage(gfx::PluginWindowHandle window); diff --git a/ui/gl/gl_image_egl.cc b/ui/gl/gl_image_egl.cc index 182117c..aeafc9a 100644 --- a/ui/gl/gl_image_egl.cc +++ b/ui/gl/gl_image_egl.cc @@ -11,7 +11,8 @@ namespace gfx { GLImageEGL::GLImageEGL(gfx::Size size) : egl_image_(EGL_NO_IMAGE_KHR), - size_(size) { + size_(size), + in_use_(false) { } GLImageEGL::~GLImageEGL() { @@ -40,25 +41,6 @@ bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) { return true; } -bool GLImageEGL::BindTexImage() { - if (egl_image_ == EGL_NO_IMAGE_KHR) { - LOG(ERROR) << "NULL EGLImage in BindTexImage"; - return false; - } - - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image_); - - if (glGetError() != GL_NO_ERROR) { - return false; - } - - return true; -} - -gfx::Size GLImageEGL::GetSize() { - return size_; -} - void GLImageEGL::Destroy() { if (egl_image_ == EGL_NO_IMAGE_KHR) return; @@ -74,7 +56,40 @@ void GLImageEGL::Destroy() { egl_image_ = EGL_NO_IMAGE_KHR; } +gfx::Size GLImageEGL::GetSize() { + return size_; +} + +bool GLImageEGL::BindTexImage() { + if (egl_image_ == EGL_NO_IMAGE_KHR) { + LOG(ERROR) << "NULL EGLImage in BindTexImage"; + return false; + } + + // Defer ImageTargetTexture2D if not currently in use. + if (!in_use_) + return true; + + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image_); + DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); + return true; +} + void GLImageEGL::ReleaseTexImage() { + // Nothing to do here as image is released after each use. +} + +void GLImageEGL::WillUseTexImage() { + DCHECK(egl_image_); + DCHECK(!in_use_); + in_use_ = true; + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image_); + DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); +} + +void GLImageEGL::DidUseTexImage() { + DCHECK(in_use_); + in_use_ = false; char zero[4] = { 0, }; glTexImage2D(GL_TEXTURE_2D, 0, diff --git a/ui/gl/gl_image_egl.h b/ui/gl/gl_image_egl.h index 1c66bb9..2c64f4d 100644 --- a/ui/gl/gl_image_egl.h +++ b/ui/gl/gl_image_egl.h @@ -21,6 +21,8 @@ class GL_EXPORT GLImageEGL : public GLImage { virtual gfx::Size GetSize() OVERRIDE; virtual bool BindTexImage() OVERRIDE; virtual void ReleaseTexImage() OVERRIDE; + virtual void WillUseTexImage() OVERRIDE; + virtual void DidUseTexImage() OVERRIDE; protected: virtual ~GLImageEGL(); @@ -28,6 +30,7 @@ class GL_EXPORT GLImageEGL : public GLImage { private: EGLImageKHR egl_image_; gfx::Size size_; + bool in_use_; DISALLOW_COPY_AND_ASSIGN(GLImageEGL); }; diff --git a/ui/gl/gl_image_glx.cc b/ui/gl/gl_image_glx.cc index 85254f3..739b4d4 100644 --- a/ui/gl/gl_image_glx.cc +++ b/ui/gl/gl_image_glx.cc @@ -52,6 +52,10 @@ GLImageGLX::GLImageGLX(gfx::PluginWindowHandle window) glx_pixmap_(0) { } +GLImageGLX::~GLImageGLX() { + Destroy(); +} + bool GLImageGLX::Initialize() { if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) { LOG(ERROR) << "GLX_EXT_texture_from_pixmap not supported."; @@ -170,8 +174,10 @@ void GLImageGLX::ReleaseTexImage() { glXReleaseTexImageEXT(display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); } -GLImageGLX::~GLImageGLX() { - Destroy(); +void GLImageGLX::WillUseTexImage() { +} + +void GLImageGLX::DidUseTexImage() { } } // namespace gfx diff --git a/ui/gl/gl_image_glx.h b/ui/gl/gl_image_glx.h index bbdaa30..e1b9b4f 100644 --- a/ui/gl/gl_image_glx.h +++ b/ui/gl/gl_image_glx.h @@ -23,6 +23,8 @@ class GL_EXPORT GLImageGLX : public GLImage { virtual gfx::Size GetSize() OVERRIDE; virtual bool BindTexImage() OVERRIDE; virtual void ReleaseTexImage() OVERRIDE; + virtual void WillUseTexImage() OVERRIDE; + virtual void DidUseTexImage() OVERRIDE; protected: virtual ~GLImageGLX(); diff --git a/ui/gl/gl_image_shm.cc b/ui/gl/gl_image_shm.cc index 78e8164..5b182eb 100644 --- a/ui/gl/gl_image_shm.cc +++ b/ui/gl/gl_image_shm.cc @@ -40,6 +40,13 @@ bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { return true; } +void GLImageShm::Destroy() { +} + +gfx::Size GLImageShm::GetSize() { + return size_; +} + bool GLImageShm::BindTexImage() { TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); DCHECK(shared_memory_); @@ -82,14 +89,13 @@ bool GLImageShm::BindTexImage() { return true; } -gfx::Size GLImageShm::GetSize() { - return size_; +void GLImageShm::ReleaseTexImage() { } -void GLImageShm::Destroy() { +void GLImageShm::WillUseTexImage() { } -void GLImageShm::ReleaseTexImage() { +void GLImageShm::DidUseTexImage() { } } // namespace gfx diff --git a/ui/gl/gl_image_shm.h b/ui/gl/gl_image_shm.h index ffdfc8b..d18938d 100644 --- a/ui/gl/gl_image_shm.h +++ b/ui/gl/gl_image_shm.h @@ -21,6 +21,8 @@ class GL_EXPORT GLImageShm : public GLImage { virtual gfx::Size GetSize() OVERRIDE; virtual bool BindTexImage() OVERRIDE; virtual void ReleaseTexImage() OVERRIDE; + virtual void WillUseTexImage() OVERRIDE; + virtual void DidUseTexImage() OVERRIDE; protected: virtual ~GLImageShm(); diff --git a/ui/gl/gl_image_stub.cc b/ui/gl/gl_image_stub.cc index 86efe6e..a1a8a85 100644 --- a/ui/gl/gl_image_stub.cc +++ b/ui/gl/gl_image_stub.cc @@ -6,6 +6,13 @@ namespace gfx { +GLImageStub::GLImageStub() { +} + +GLImageStub::~GLImageStub() { + Destroy(); +} + void GLImageStub::Destroy() { } @@ -20,6 +27,10 @@ bool GLImageStub::BindTexImage() { void GLImageStub::ReleaseTexImage() { } -GLImageStub::~GLImageStub() {} +void GLImageStub::WillUseTexImage() { +} + +void GLImageStub::DidUseTexImage() { +} } // namespace gfx diff --git a/ui/gl/gl_image_stub.h b/ui/gl/gl_image_stub.h index 8b47358..ec232fa 100644 --- a/ui/gl/gl_image_stub.h +++ b/ui/gl/gl_image_stub.h @@ -12,11 +12,15 @@ namespace gfx { // A GLImage that does nothing for unit tests. class GL_EXPORT GLImageStub : public GLImage { public: + GLImageStub(); + // Implement GLImage. virtual void Destroy() OVERRIDE; virtual gfx::Size GetSize() OVERRIDE; virtual bool BindTexImage() OVERRIDE; virtual void ReleaseTexImage() OVERRIDE; + virtual void WillUseTexImage() OVERRIDE; + virtual void DidUseTexImage() OVERRIDE; protected: virtual ~GLImageStub(); |