OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gl/gl_surface_osmesa_win.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/trace_event/trace_event.h" |
| 13 #include "base/win/windows_version.h" |
| 14 #include "ui/gl/gl_bindings.h" |
| 15 #include "ui/gl/gl_implementation.h" |
| 16 #include "ui/gl/gl_surface_egl.h" |
| 17 #include "ui/gl/gl_surface_wgl.h" |
| 18 #include "ui/gl/vsync_provider_win.h" |
| 19 |
| 20 // From ANGLE's egl/eglext.h. |
| 21 #if !defined(EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE) |
| 22 #define EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE \ |
| 23 reinterpret_cast<EGLNativeDisplayType>(-2) |
| 24 #endif |
| 25 |
| 26 namespace gl { |
| 27 |
| 28 GLSurfaceOSMesaWin::GLSurfaceOSMesaWin(gfx::AcceleratedWidget window) |
| 29 : GLSurfaceOSMesa(SURFACE_OSMESA_RGBA, gfx::Size(1, 1)), |
| 30 window_(window), |
| 31 device_context_(NULL) { |
| 32 DCHECK(window); |
| 33 } |
| 34 |
| 35 GLSurfaceOSMesaWin::~GLSurfaceOSMesaWin() { |
| 36 Destroy(); |
| 37 } |
| 38 |
| 39 bool GLSurfaceOSMesaWin::Initialize(GLSurface::Format format) { |
| 40 if (!GLSurfaceOSMesa::Initialize(format)) |
| 41 return false; |
| 42 |
| 43 device_context_ = GetDC(window_); |
| 44 return true; |
| 45 } |
| 46 |
| 47 void GLSurfaceOSMesaWin::Destroy() { |
| 48 if (window_ && device_context_) |
| 49 ReleaseDC(window_, device_context_); |
| 50 |
| 51 device_context_ = NULL; |
| 52 |
| 53 GLSurfaceOSMesa::Destroy(); |
| 54 } |
| 55 |
| 56 bool GLSurfaceOSMesaWin::IsOffscreen() { |
| 57 return false; |
| 58 } |
| 59 |
| 60 gfx::SwapResult GLSurfaceOSMesaWin::SwapBuffers() { |
| 61 DCHECK(device_context_); |
| 62 |
| 63 gfx::Size size = GetSize(); |
| 64 |
| 65 // Note: negating the height below causes GDI to treat the bitmap data as row |
| 66 // 0 being at the top. |
| 67 BITMAPV4HEADER info = {sizeof(BITMAPV4HEADER)}; |
| 68 info.bV4Width = size.width(); |
| 69 info.bV4Height = -size.height(); |
| 70 info.bV4Planes = 1; |
| 71 info.bV4BitCount = 32; |
| 72 info.bV4V4Compression = BI_BITFIELDS; |
| 73 info.bV4RedMask = 0x000000FF; |
| 74 info.bV4GreenMask = 0x0000FF00; |
| 75 info.bV4BlueMask = 0x00FF0000; |
| 76 info.bV4AlphaMask = 0xFF000000; |
| 77 |
| 78 // Copy the back buffer to the window's device context. Do not check whether |
| 79 // StretchDIBits succeeds or not. It will fail if the window has been |
| 80 // destroyed but it is preferable to allow rendering to silently fail if the |
| 81 // window is destroyed. This is because the primary application of this |
| 82 // class of GLContext is for testing and we do not want every GL related ui / |
| 83 // browser test to become flaky if there is a race condition between GL |
| 84 // context destruction and window destruction. |
| 85 StretchDIBits(device_context_, 0, 0, size.width(), size.height(), 0, 0, |
| 86 size.width(), size.height(), GetHandle(), |
| 87 reinterpret_cast<BITMAPINFO*>(&info), DIB_RGB_COLORS, SRCCOPY); |
| 88 |
| 89 return gfx::SwapResult::SWAP_ACK; |
| 90 } |
| 91 |
| 92 bool GLSurfaceOSMesaWin::SupportsPostSubBuffer() { |
| 93 return true; |
| 94 } |
| 95 |
| 96 gfx::SwapResult GLSurfaceOSMesaWin::PostSubBuffer(int x, |
| 97 int y, |
| 98 int width, |
| 99 int height) { |
| 100 DCHECK(device_context_); |
| 101 |
| 102 gfx::Size size = GetSize(); |
| 103 |
| 104 // Note: negating the height below causes GDI to treat the bitmap data as row |
| 105 // 0 being at the top. |
| 106 BITMAPV4HEADER info = {sizeof(BITMAPV4HEADER)}; |
| 107 info.bV4Width = size.width(); |
| 108 info.bV4Height = -size.height(); |
| 109 info.bV4Planes = 1; |
| 110 info.bV4BitCount = 32; |
| 111 info.bV4V4Compression = BI_BITFIELDS; |
| 112 info.bV4RedMask = 0x000000FF; |
| 113 info.bV4GreenMask = 0x0000FF00; |
| 114 info.bV4BlueMask = 0x00FF0000; |
| 115 info.bV4AlphaMask = 0xFF000000; |
| 116 |
| 117 // Copy the back buffer to the window's device context. Do not check whether |
| 118 // StretchDIBits succeeds or not. It will fail if the window has been |
| 119 // destroyed but it is preferable to allow rendering to silently fail if the |
| 120 // window is destroyed. This is because the primary application of this |
| 121 // class of GLContext is for testing and we do not want every GL related ui / |
| 122 // browser test to become flaky if there is a race condition between GL |
| 123 // context destruction and window destruction. |
| 124 StretchDIBits(device_context_, x, size.height() - y - height, width, height, |
| 125 x, y, width, height, GetHandle(), |
| 126 reinterpret_cast<BITMAPINFO*>(&info), DIB_RGB_COLORS, SRCCOPY); |
| 127 |
| 128 return gfx::SwapResult::SWAP_ACK; |
| 129 } |
| 130 |
| 131 } // namespace gl |
OLD | NEW |