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 14 matching lines...) Expand all Loading... |
25 public: | 25 public: |
26 explicit NativeViewGLSurfaceOSMesa(gfx::AcceleratedWidget window); | 26 explicit NativeViewGLSurfaceOSMesa(gfx::AcceleratedWidget window); |
27 | 27 |
28 static bool InitializeOneOff(); | 28 static bool InitializeOneOff(); |
29 | 29 |
30 // Implement a subset of GLSurface. | 30 // Implement a subset of GLSurface. |
31 bool Initialize() override; | 31 bool Initialize() override; |
32 void Destroy() override; | 32 void Destroy() override; |
33 bool Resize(const gfx::Size& new_size) override; | 33 bool Resize(const gfx::Size& new_size) override; |
34 bool IsOffscreen() override; | 34 bool IsOffscreen() override; |
35 bool SwapBuffers() override; | 35 gfx::SwapResult SwapBuffers() override; |
36 bool SupportsPostSubBuffer() override; | 36 bool SupportsPostSubBuffer() override; |
37 bool PostSubBuffer(int x, int y, int width, int height) override; | 37 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; |
38 | 38 |
39 protected: | 39 protected: |
40 ~NativeViewGLSurfaceOSMesa() override; | 40 ~NativeViewGLSurfaceOSMesa() override; |
41 | 41 |
42 private: | 42 private: |
43 Display* xdisplay_; | 43 Display* xdisplay_; |
44 GC window_graphics_context_; | 44 GC window_graphics_context_; |
45 gfx::AcceleratedWidget window_; | 45 gfx::AcceleratedWidget window_; |
46 GC pixmap_graphics_context_; | 46 GC pixmap_graphics_context_; |
47 Pixmap pixmap_; | 47 Pixmap pixmap_; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return false; | 174 return false; |
175 } | 175 } |
176 | 176 |
177 return true; | 177 return true; |
178 } | 178 } |
179 | 179 |
180 bool NativeViewGLSurfaceOSMesa::IsOffscreen() { | 180 bool NativeViewGLSurfaceOSMesa::IsOffscreen() { |
181 return false; | 181 return false; |
182 } | 182 } |
183 | 183 |
184 bool NativeViewGLSurfaceOSMesa::SwapBuffers() { | 184 gfx::SwapResult NativeViewGLSurfaceOSMesa::SwapBuffers() { |
185 TRACE_EVENT2("gpu", "NativeViewGLSurfaceOSMesa:RealSwapBuffers", | 185 TRACE_EVENT2("gpu", "NativeViewGLSurfaceOSMesa:RealSwapBuffers", |
186 "width", GetSize().width(), | 186 "width", GetSize().width(), |
187 "height", GetSize().height()); | 187 "height", GetSize().height()); |
188 | 188 |
189 gfx::Size size = GetSize(); | 189 gfx::Size size = GetSize(); |
190 | 190 |
191 XWindowAttributes attributes; | 191 XWindowAttributes attributes; |
192 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { | 192 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { |
193 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 193 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
194 return false; | 194 return gfx::SWAP_FAILED; |
195 } | 195 } |
196 | 196 |
197 // Copy the frame into the pixmap. | 197 // Copy the frame into the pixmap. |
198 gfx::PutARGBImage(xdisplay_, | 198 gfx::PutARGBImage(xdisplay_, |
199 attributes.visual, | 199 attributes.visual, |
200 attributes.depth, | 200 attributes.depth, |
201 pixmap_, | 201 pixmap_, |
202 pixmap_graphics_context_, | 202 pixmap_graphics_context_, |
203 static_cast<const uint8*>(GetHandle()), | 203 static_cast<const uint8*>(GetHandle()), |
204 size.width(), | 204 size.width(), |
205 size.height()); | 205 size.height()); |
206 | 206 |
207 // Copy the pixmap to the window. | 207 // Copy the pixmap to the window. |
208 XCopyArea(xdisplay_, | 208 XCopyArea(xdisplay_, |
209 pixmap_, | 209 pixmap_, |
210 window_, | 210 window_, |
211 window_graphics_context_, | 211 window_graphics_context_, |
212 0, | 212 0, |
213 0, | 213 0, |
214 size.width(), | 214 size.width(), |
215 size.height(), | 215 size.height(), |
216 0, | 216 0, |
217 0); | 217 0); |
218 | 218 |
219 return true; | 219 return gfx::SWAP_ACK; |
220 } | 220 } |
221 | 221 |
222 bool NativeViewGLSurfaceOSMesa::SupportsPostSubBuffer() { | 222 bool NativeViewGLSurfaceOSMesa::SupportsPostSubBuffer() { |
223 return true; | 223 return true; |
224 } | 224 } |
225 | 225 |
226 bool NativeViewGLSurfaceOSMesa::PostSubBuffer( | 226 gfx::SwapResult NativeViewGLSurfaceOSMesa::PostSubBuffer(int x, |
227 int x, int y, int width, int height) { | 227 int y, |
| 228 int width, |
| 229 int height) { |
228 gfx::Size size = GetSize(); | 230 gfx::Size size = GetSize(); |
229 | 231 |
230 // Move (0,0) from lower-left to upper-left | 232 // Move (0,0) from lower-left to upper-left |
231 y = size.height() - y - height; | 233 y = size.height() - y - height; |
232 | 234 |
233 XWindowAttributes attributes; | 235 XWindowAttributes attributes; |
234 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { | 236 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { |
235 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 237 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
236 return false; | 238 return gfx::SWAP_FAILED; |
237 } | 239 } |
238 | 240 |
239 // Copy the frame into the pixmap. | 241 // Copy the frame into the pixmap. |
240 gfx::PutARGBImage(xdisplay_, | 242 gfx::PutARGBImage(xdisplay_, |
241 attributes.visual, | 243 attributes.visual, |
242 attributes.depth, | 244 attributes.depth, |
243 pixmap_, | 245 pixmap_, |
244 pixmap_graphics_context_, | 246 pixmap_graphics_context_, |
245 static_cast<const uint8*>(GetHandle()), | 247 static_cast<const uint8*>(GetHandle()), |
246 size.width(), | 248 size.width(), |
(...skipping 10 matching lines...) Expand all Loading... |
257 pixmap_, | 259 pixmap_, |
258 window_, | 260 window_, |
259 window_graphics_context_, | 261 window_graphics_context_, |
260 x, | 262 x, |
261 y, | 263 y, |
262 width, | 264 width, |
263 height, | 265 height, |
264 x, | 266 x, |
265 y); | 267 y); |
266 | 268 |
267 return true; | 269 return gfx::SWAP_ACK; |
268 } | 270 } |
269 | 271 |
270 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { | 272 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { |
271 Destroy(); | 273 Destroy(); |
272 } | 274 } |
273 | 275 |
274 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 276 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
275 gfx::AcceleratedWidget window) { | 277 gfx::AcceleratedWidget window) { |
276 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); | 278 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); |
277 switch (GetGLImplementation()) { | 279 switch (GetGLImplementation()) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 NOTREACHED(); | 340 NOTREACHED(); |
339 return NULL; | 341 return NULL; |
340 } | 342 } |
341 } | 343 } |
342 | 344 |
343 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 345 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
344 return gfx::GetXDisplay(); | 346 return gfx::GetXDisplay(); |
345 } | 347 } |
346 | 348 |
347 } // namespace gfx | 349 } // namespace gfx |
OLD | NEW |