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