OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "ui/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 "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 gfx::AcceleratedWidget window, | 27 gfx::AcceleratedWidget window, |
28 const gfx::SurfaceConfiguration& requested_configuration); | 28 const gfx::SurfaceConfiguration& requested_configuration); |
29 | 29 |
30 static bool InitializeOneOff(); | 30 static bool InitializeOneOff(); |
31 | 31 |
32 // Implement a subset of GLSurface. | 32 // Implement a subset of GLSurface. |
33 bool Initialize() override; | 33 bool Initialize() override; |
34 void Destroy() override; | 34 void Destroy() override; |
35 bool Resize(const gfx::Size& new_size) override; | 35 bool Resize(const gfx::Size& new_size) override; |
36 bool IsOffscreen() override; | 36 bool IsOffscreen() override; |
37 bool SwapBuffers() override; | 37 gfx::SwapResult SwapBuffers() override; |
38 bool SupportsPostSubBuffer() override; | 38 bool SupportsPostSubBuffer() override; |
39 bool PostSubBuffer(int x, int y, int width, int height) override; | 39 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; |
40 | 40 |
41 protected: | 41 protected: |
42 ~NativeViewGLSurfaceOSMesa() override; | 42 ~NativeViewGLSurfaceOSMesa() override; |
43 | 43 |
44 private: | 44 private: |
45 Display* xdisplay_; | 45 Display* xdisplay_; |
46 GC window_graphics_context_; | 46 GC window_graphics_context_; |
47 gfx::AcceleratedWidget window_; | 47 gfx::AcceleratedWidget window_; |
48 GC pixmap_graphics_context_; | 48 GC pixmap_graphics_context_; |
49 Pixmap pixmap_; | 49 Pixmap pixmap_; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 return false; | 179 return false; |
180 } | 180 } |
181 | 181 |
182 return true; | 182 return true; |
183 } | 183 } |
184 | 184 |
185 bool NativeViewGLSurfaceOSMesa::IsOffscreen() { | 185 bool NativeViewGLSurfaceOSMesa::IsOffscreen() { |
186 return false; | 186 return false; |
187 } | 187 } |
188 | 188 |
189 bool NativeViewGLSurfaceOSMesa::SwapBuffers() { | 189 gfx::SwapResult NativeViewGLSurfaceOSMesa::SwapBuffers() { |
190 TRACE_EVENT2("gpu", "NativeViewGLSurfaceOSMesa:RealSwapBuffers", | 190 TRACE_EVENT2("gpu", "NativeViewGLSurfaceOSMesa:RealSwapBuffers", |
191 "width", GetSize().width(), | 191 "width", GetSize().width(), |
192 "height", GetSize().height()); | 192 "height", GetSize().height()); |
193 | 193 |
194 gfx::Size size = GetSize(); | 194 gfx::Size size = GetSize(); |
195 | 195 |
196 XWindowAttributes attributes; | 196 XWindowAttributes attributes; |
197 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { | 197 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { |
198 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 198 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
199 return false; | 199 return gfx::SwapResult::SWAP_FAILED; |
200 } | 200 } |
201 | 201 |
202 // Copy the frame into the pixmap. | 202 // Copy the frame into the pixmap. |
203 gfx::PutARGBImage(xdisplay_, | 203 gfx::PutARGBImage(xdisplay_, |
204 attributes.visual, | 204 attributes.visual, |
205 attributes.depth, | 205 attributes.depth, |
206 pixmap_, | 206 pixmap_, |
207 pixmap_graphics_context_, | 207 pixmap_graphics_context_, |
208 static_cast<const uint8*>(GetHandle()), | 208 static_cast<const uint8*>(GetHandle()), |
209 size.width(), | 209 size.width(), |
210 size.height()); | 210 size.height()); |
211 | 211 |
212 // Copy the pixmap to the window. | 212 // Copy the pixmap to the window. |
213 XCopyArea(xdisplay_, | 213 XCopyArea(xdisplay_, |
214 pixmap_, | 214 pixmap_, |
215 window_, | 215 window_, |
216 window_graphics_context_, | 216 window_graphics_context_, |
217 0, | 217 0, |
218 0, | 218 0, |
219 size.width(), | 219 size.width(), |
220 size.height(), | 220 size.height(), |
221 0, | 221 0, |
222 0); | 222 0); |
223 | 223 |
224 return true; | 224 return gfx::SwapResult::SWAP_ACK; |
225 } | 225 } |
226 | 226 |
227 bool NativeViewGLSurfaceOSMesa::SupportsPostSubBuffer() { | 227 bool NativeViewGLSurfaceOSMesa::SupportsPostSubBuffer() { |
228 return true; | 228 return true; |
229 } | 229 } |
230 | 230 |
231 bool NativeViewGLSurfaceOSMesa::PostSubBuffer( | 231 gfx::SwapResult NativeViewGLSurfaceOSMesa::PostSubBuffer( |
232 int x, int y, int width, int height) { | 232 int x, int y, int width, int height) { |
233 gfx::Size size = GetSize(); | 233 gfx::Size size = GetSize(); |
234 | 234 |
235 // Move (0,0) from lower-left to upper-left | 235 // Move (0,0) from lower-left to upper-left |
236 y = size.height() - y - height; | 236 y = size.height() - y - height; |
237 | 237 |
238 XWindowAttributes attributes; | 238 XWindowAttributes attributes; |
239 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { | 239 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { |
240 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 240 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
241 return false; | 241 return gfx::SwapResult::SWAP_FAILED; |
242 } | 242 } |
243 | 243 |
244 // Copy the frame into the pixmap. | 244 // Copy the frame into the pixmap. |
245 gfx::PutARGBImage(xdisplay_, | 245 gfx::PutARGBImage(xdisplay_, |
246 attributes.visual, | 246 attributes.visual, |
247 attributes.depth, | 247 attributes.depth, |
248 pixmap_, | 248 pixmap_, |
249 pixmap_graphics_context_, | 249 pixmap_graphics_context_, |
250 static_cast<const uint8*>(GetHandle()), | 250 static_cast<const uint8*>(GetHandle()), |
251 size.width(), | 251 size.width(), |
(...skipping 10 matching lines...) Expand all Loading... |
262 pixmap_, | 262 pixmap_, |
263 window_, | 263 window_, |
264 window_graphics_context_, | 264 window_graphics_context_, |
265 x, | 265 x, |
266 y, | 266 y, |
267 width, | 267 width, |
268 height, | 268 height, |
269 x, | 269 x, |
270 y); | 270 y); |
271 | 271 |
272 return true; | 272 return gfx::SwapResult::SWAP_ACK; |
273 } | 273 } |
274 | 274 |
275 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { | 275 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { |
276 Destroy(); | 276 Destroy(); |
277 } | 277 } |
278 | 278 |
279 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 279 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
280 gfx::AcceleratedWidget window, | 280 gfx::AcceleratedWidget window, |
281 const gfx::SurfaceConfiguration& requested_configuration) { | 281 const gfx::SurfaceConfiguration& requested_configuration) { |
282 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); | 282 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 NOTREACHED(); | 351 NOTREACHED(); |
352 return NULL; | 352 return NULL; |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
356 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 356 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
357 return gfx::GetXDisplay(); | 357 return gfx::GetXDisplay(); |
358 } | 358 } |
359 | 359 |
360 } // namespace gfx | 360 } // namespace gfx |
OLD | NEW |