diff options
author | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 18:27:27 +0000 |
---|---|---|
committer | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 18:27:27 +0000 |
commit | 4297bea874c5620b111cd07bb06bd4e256e7e72b (patch) | |
tree | 0b934b27d12098ea9bf28c1ffaee7cbd71b86464 /ui/gfx/gl | |
parent | f8530b797730cca270210117a949a4a06be4009d (diff) | |
download | chromium_src-4297bea874c5620b111cd07bb06bd4e256e7e72b.zip chromium_src-4297bea874c5620b111cd07bb06bd4e256e7e72b.tar.gz chromium_src-4297bea874c5620b111cd07bb06bd4e256e7e72b.tar.bz2 |
Enable GL_CHROMIUM_post_sub_buffer for osmesa
Small changes to WGC3DInProcessImpl to pass the extension up to WebKit.
BUG=none
TEST=with https://bugs.webkit.org/show_bug.cgi?id=67341 and --use-gl=osmesa
Review URL: http://codereview.chromium.org/8772021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/gl')
-rw-r--r-- | ui/gfx/gl/gl_surface_linux.cc | 55 | ||||
-rw-r--r-- | ui/gfx/gl/gl_surface_win.cc | 50 |
2 files changed, 105 insertions, 0 deletions
diff --git a/ui/gfx/gl/gl_surface_linux.cc b/ui/gfx/gl/gl_surface_linux.cc index cf067c2..b152b46 100644 --- a/ui/gfx/gl/gl_surface_linux.cc +++ b/ui/gfx/gl/gl_surface_linux.cc @@ -42,6 +42,8 @@ class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { virtual void Destroy(); virtual bool IsOffscreen(); virtual bool SwapBuffers(); + virtual std::string GetExtensions(); + virtual bool PostSubBuffer(int x, int y, int width, int height); private: bool UpdateSize(); @@ -194,6 +196,59 @@ bool NativeViewGLSurfaceOSMesa::SwapBuffers() { return true; } +std::string NativeViewGLSurfaceOSMesa::GetExtensions() { + std::string extensions = gfx::GLSurfaceOSMesa::GetExtensions(); + extensions += extensions.empty() ? "" : " "; + extensions += "GL_CHROMIUM_post_sub_buffer"; + return extensions; +} + +bool NativeViewGLSurfaceOSMesa::PostSubBuffer( + int x, int y, int width, int height) { + // Update the size before blitting so that the blit size is exactly the same + // as the window. + if (!UpdateSize()) { + LOG(ERROR) << "Failed to update size of GLContextOSMesa."; + return false; + } + + gfx::Size size = GetSize(); + + // Move (0,0) from lower-left to upper-left + y = size.height() - y - height; + + XWindowAttributes attributes; + if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) { + LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; + return false; + } + + // Copy the frame into the pixmap. + ui::PutARGBImage(g_osmesa_display, + attributes.visual, + attributes.depth, + pixmap_, + pixmap_graphics_context_, + static_cast<const uint8*>(GetHandle()), + size.width(), + size.height(), + x, y, + x, y, + width, + height); + + // Copy the pixmap to the window. + XCopyArea(g_osmesa_display, + pixmap_, + window_, + window_graphics_context_, + x, y, + width, height, + x, y); + + return true; +} + bool NativeViewGLSurfaceOSMesa::UpdateSize() { // Get the window size. XWindowAttributes attributes; diff --git a/ui/gfx/gl/gl_surface_win.cc b/ui/gfx/gl/gl_surface_win.cc index e6abf55..08b3396 100644 --- a/ui/gfx/gl/gl_surface_win.cc +++ b/ui/gfx/gl/gl_surface_win.cc @@ -30,6 +30,8 @@ class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { virtual void Destroy(); virtual bool IsOffscreen(); virtual bool SwapBuffers(); + virtual std::string GetExtensions(); + virtual bool PostSubBuffer(int x, int y, int width, int height); private: void UpdateSize(); @@ -134,6 +136,54 @@ bool NativeViewGLSurfaceOSMesa::SwapBuffers() { return true; } +std::string NativeViewGLSurfaceOSMesa::GetExtensions() { + std::string extensions = gfx::GLSurfaceOSMesa::GetExtensions(); + extensions += extensions.empty() ? "" : " "; + extensions += "GL_CHROMIUM_post_sub_buffer"; + return extensions; +} + +bool NativeViewGLSurfaceOSMesa::PostSubBuffer( + int x, int y, int width, int height) { + DCHECK(device_context_); + + // Update the size before blitting so that the blit size is exactly the same + // as the window. + UpdateSize(); + + gfx::Size size = GetSize(); + + // Note: negating the height below causes GDI to treat the bitmap data as row + // 0 being at the top. + BITMAPV4HEADER info = { sizeof(BITMAPV4HEADER) }; + info.bV4Width = size.width(); + info.bV4Height = -size.height(); + info.bV4Planes = 1; + info.bV4BitCount = 32; + info.bV4V4Compression = BI_BITFIELDS; + info.bV4RedMask = 0x000000FF; + info.bV4GreenMask = 0x0000FF00; + info.bV4BlueMask = 0x00FF0000; + info.bV4AlphaMask = 0xFF000000; + + // Copy the back buffer to the window's device context. Do not check whether + // StretchDIBits succeeds or not. It will fail if the window has been + // destroyed but it is preferable to allow rendering to silently fail if the + // window is destroyed. This is because the primary application of this + // class of GLContext is for testing and we do not want every GL related ui / + // browser test to become flaky if there is a race condition between GL + // context destruction and window destruction. + StretchDIBits(device_context_, + x, size.height() - y - height, width, height, + x, y, width, height, + GetHandle(), + reinterpret_cast<BITMAPINFO*>(&info), + DIB_RGB_COLORS, + SRCCOPY); + + return true; +} + void NativeViewGLSurfaceOSMesa::UpdateSize() { // Change back buffer size to that of window. If window handle is invalid, do // not change the back buffer size. |