OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/gl/gl_surface.h" | 5 #include "ui/gfx/gl/gl_surface.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" | 9 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" |
10 #include "ui/gfx/gl/gl_bindings.h" | 10 #include "ui/gfx/gl/gl_bindings.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window); | 23 explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window); |
24 virtual ~NativeViewGLSurfaceOSMesa(); | 24 virtual ~NativeViewGLSurfaceOSMesa(); |
25 | 25 |
26 // Initializes the GL context. | 26 // Initializes the GL context. |
27 bool Initialize(); | 27 bool Initialize(); |
28 | 28 |
29 // Implement subset of GLSurface. | 29 // Implement subset of GLSurface. |
30 virtual void Destroy(); | 30 virtual void Destroy(); |
31 virtual bool IsOffscreen(); | 31 virtual bool IsOffscreen(); |
32 virtual bool SwapBuffers(); | 32 virtual bool SwapBuffers(); |
| 33 virtual std::string GetExtensions(); |
| 34 virtual bool PostSubBuffer(int x, int y, int width, int height); |
33 | 35 |
34 private: | 36 private: |
35 void UpdateSize(); | 37 void UpdateSize(); |
36 | 38 |
37 gfx::PluginWindowHandle window_; | 39 gfx::PluginWindowHandle window_; |
38 HDC device_context_; | 40 HDC device_context_; |
39 | 41 |
40 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); | 42 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); |
41 }; | 43 }; |
42 | 44 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 0, 0, size.width(), size.height(), | 129 0, 0, size.width(), size.height(), |
128 0, 0, size.width(), size.height(), | 130 0, 0, size.width(), size.height(), |
129 GetHandle(), | 131 GetHandle(), |
130 reinterpret_cast<BITMAPINFO*>(&info), | 132 reinterpret_cast<BITMAPINFO*>(&info), |
131 DIB_RGB_COLORS, | 133 DIB_RGB_COLORS, |
132 SRCCOPY); | 134 SRCCOPY); |
133 | 135 |
134 return true; | 136 return true; |
135 } | 137 } |
136 | 138 |
| 139 std::string NativeViewGLSurfaceOSMesa::GetExtensions() { |
| 140 std::string extensions = gfx::GLSurfaceOSMesa::GetExtensions(); |
| 141 extensions += extensions.empty() ? "" : " "; |
| 142 extensions += "GL_CHROMIUM_post_sub_buffer"; |
| 143 return extensions; |
| 144 } |
| 145 |
| 146 bool NativeViewGLSurfaceOSMesa::PostSubBuffer( |
| 147 int x, int y, int width, int height) { |
| 148 DCHECK(device_context_); |
| 149 |
| 150 // Update the size before blitting so that the blit size is exactly the same |
| 151 // as the window. |
| 152 UpdateSize(); |
| 153 |
| 154 gfx::Size size = GetSize(); |
| 155 |
| 156 // Note: negating the height below causes GDI to treat the bitmap data as row |
| 157 // 0 being at the top. |
| 158 BITMAPV4HEADER info = { sizeof(BITMAPV4HEADER) }; |
| 159 info.bV4Width = size.width(); |
| 160 info.bV4Height = -size.height(); |
| 161 info.bV4Planes = 1; |
| 162 info.bV4BitCount = 32; |
| 163 info.bV4V4Compression = BI_BITFIELDS; |
| 164 info.bV4RedMask = 0x000000FF; |
| 165 info.bV4GreenMask = 0x0000FF00; |
| 166 info.bV4BlueMask = 0x00FF0000; |
| 167 info.bV4AlphaMask = 0xFF000000; |
| 168 |
| 169 // Copy the back buffer to the window's device context. Do not check whether |
| 170 // StretchDIBits succeeds or not. It will fail if the window has been |
| 171 // destroyed but it is preferable to allow rendering to silently fail if the |
| 172 // window is destroyed. This is because the primary application of this |
| 173 // class of GLContext is for testing and we do not want every GL related ui / |
| 174 // browser test to become flaky if there is a race condition between GL |
| 175 // context destruction and window destruction. |
| 176 StretchDIBits(device_context_, |
| 177 x, size.height() - y - height, width, height, |
| 178 x, y, width, height, |
| 179 GetHandle(), |
| 180 reinterpret_cast<BITMAPINFO*>(&info), |
| 181 DIB_RGB_COLORS, |
| 182 SRCCOPY); |
| 183 |
| 184 return true; |
| 185 } |
| 186 |
137 void NativeViewGLSurfaceOSMesa::UpdateSize() { | 187 void NativeViewGLSurfaceOSMesa::UpdateSize() { |
138 // Change back buffer size to that of window. If window handle is invalid, do | 188 // Change back buffer size to that of window. If window handle is invalid, do |
139 // not change the back buffer size. | 189 // not change the back buffer size. |
140 RECT rect; | 190 RECT rect; |
141 if (!GetClientRect(window_, &rect)) | 191 if (!GetClientRect(window_, &rect)) |
142 return; | 192 return; |
143 | 193 |
144 gfx::Size window_size = gfx::Size( | 194 gfx::Size window_size = gfx::Size( |
145 std::max(1, static_cast<int>(rect.right - rect.left)), | 195 std::max(1, static_cast<int>(rect.right - rect.left)), |
146 std::max(1, static_cast<int>(rect.bottom - rect.top))); | 196 std::max(1, static_cast<int>(rect.bottom - rect.top))); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 265 } |
216 case kGLImplementationMockGL: | 266 case kGLImplementationMockGL: |
217 return new GLSurfaceStub; | 267 return new GLSurfaceStub; |
218 default: | 268 default: |
219 NOTREACHED(); | 269 NOTREACHED(); |
220 return NULL; | 270 return NULL; |
221 } | 271 } |
222 } | 272 } |
223 | 273 |
224 } // namespace gfx | 274 } // namespace gfx |
OLD | NEW |