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 gfx::SwapResult SwapBuffers() override; | 35 bool SwapBuffers() override; |
36 bool SupportsPostSubBuffer() override; | 36 bool SupportsPostSubBuffer() override; |
37 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; | 37 bool 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 gfx::SwapResult NativeViewGLSurfaceOSMesa::SwapBuffers() { | 184 bool 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 gfx::SwapResult::SWAP_FAILED; | 194 return false; |
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 gfx::SwapResult::SWAP_ACK; | 219 return true; |
220 } | 220 } |
221 | 221 |
222 bool NativeViewGLSurfaceOSMesa::SupportsPostSubBuffer() { | 222 bool NativeViewGLSurfaceOSMesa::SupportsPostSubBuffer() { |
223 return true; | 223 return true; |
224 } | 224 } |
225 | 225 |
226 gfx::SwapResult NativeViewGLSurfaceOSMesa::PostSubBuffer(int x, | 226 bool NativeViewGLSurfaceOSMesa::PostSubBuffer( |
227 int y, | 227 int x, int y, int width, int height) { |
228 int width, | |
229 int height) { | |
230 gfx::Size size = GetSize(); | 228 gfx::Size size = GetSize(); |
231 | 229 |
232 // Move (0,0) from lower-left to upper-left | 230 // Move (0,0) from lower-left to upper-left |
233 y = size.height() - y - height; | 231 y = size.height() - y - height; |
234 | 232 |
235 XWindowAttributes attributes; | 233 XWindowAttributes attributes; |
236 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { | 234 if (!XGetWindowAttributes(xdisplay_, window_, &attributes)) { |
237 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 235 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
238 return gfx::SwapResult::SWAP_FAILED; | 236 return false; |
239 } | 237 } |
240 | 238 |
241 // Copy the frame into the pixmap. | 239 // Copy the frame into the pixmap. |
242 gfx::PutARGBImage(xdisplay_, | 240 gfx::PutARGBImage(xdisplay_, |
243 attributes.visual, | 241 attributes.visual, |
244 attributes.depth, | 242 attributes.depth, |
245 pixmap_, | 243 pixmap_, |
246 pixmap_graphics_context_, | 244 pixmap_graphics_context_, |
247 static_cast<const uint8*>(GetHandle()), | 245 static_cast<const uint8*>(GetHandle()), |
248 size.width(), | 246 size.width(), |
(...skipping 10 matching lines...) Expand all Loading... |
259 pixmap_, | 257 pixmap_, |
260 window_, | 258 window_, |
261 window_graphics_context_, | 259 window_graphics_context_, |
262 x, | 260 x, |
263 y, | 261 y, |
264 width, | 262 width, |
265 height, | 263 height, |
266 x, | 264 x, |
267 y); | 265 y); |
268 | 266 |
269 return gfx::SwapResult::SWAP_ACK; | 267 return true; |
270 } | 268 } |
271 | 269 |
272 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { | 270 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { |
273 Destroy(); | 271 Destroy(); |
274 } | 272 } |
275 | 273 |
276 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 274 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
277 gfx::AcceleratedWidget window) { | 275 gfx::AcceleratedWidget window) { |
278 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); | 276 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); |
279 switch (GetGLImplementation()) { | 277 switch (GetGLImplementation()) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 NOTREACHED(); | 339 NOTREACHED(); |
342 return NULL; | 340 return NULL; |
343 } | 341 } |
344 } | 342 } |
345 | 343 |
346 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 344 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
347 return gfx::GetXDisplay(); | 345 return gfx::GetXDisplay(); |
348 } | 346 } |
349 | 347 |
350 } // namespace gfx | 348 } // namespace gfx |
OLD | NEW |