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 "content/common/gpu/image_transport_surface.h" | 5 #include "content/common/gpu/image_transport_surface.h" |
6 | 6 |
7 // This conflicts with the defines in Xlib.h and must come first. | 7 // This conflicts with the defines in Xlib.h and must come first. |
8 #include "content/common/gpu/gpu_messages.h" | 8 #include "content/common/gpu/gpu_messages.h" |
9 | 9 |
10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // gfx::GLSurface implementation | 86 // gfx::GLSurface implementation |
87 virtual bool Initialize() OVERRIDE; | 87 virtual bool Initialize() OVERRIDE; |
88 virtual void Destroy() OVERRIDE; | 88 virtual void Destroy() OVERRIDE; |
89 virtual bool IsOffscreen() OVERRIDE; | 89 virtual bool IsOffscreen() OVERRIDE; |
90 virtual bool SwapBuffers() OVERRIDE; | 90 virtual bool SwapBuffers() OVERRIDE; |
91 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 91 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
92 virtual std::string GetExtensions() OVERRIDE; | 92 virtual std::string GetExtensions() OVERRIDE; |
93 virtual gfx::Size GetSize() OVERRIDE; | 93 virtual gfx::Size GetSize() OVERRIDE; |
94 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 94 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
95 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 95 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
96 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 96 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 97 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
97 | 98 |
98 protected: | 99 protected: |
99 // ImageTransportSurface implementation | 100 // ImageTransportSurface implementation |
100 virtual void OnNewSurfaceACK( | 101 virtual void OnNewSurfaceACK( |
101 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 102 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
102 virtual void OnBuffersSwappedACK() OVERRIDE; | 103 virtual void OnBuffersSwappedACK() OVERRIDE; |
103 virtual void OnPostSubBufferACK() OVERRIDE; | 104 virtual void OnPostSubBufferACK() OVERRIDE; |
104 virtual void OnResizeViewACK() OVERRIDE; | 105 virtual void OnResizeViewACK() OVERRIDE; |
105 virtual void OnResize(gfx::Size size) OVERRIDE; | 106 virtual void OnResize(gfx::Size size) OVERRIDE; |
106 | 107 |
107 private: | 108 private: |
108 virtual ~EGLImageTransportSurface() OVERRIDE; | 109 virtual ~EGLImageTransportSurface() OVERRIDE; |
109 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); | 110 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); |
110 void SendBuffersSwapped(); | 111 void SendBuffersSwapped(); |
111 void SendPostSubBuffer(int x, int y, int width, int height); | 112 void SendPostSubBuffer(int x, int y, int width, int height); |
112 | 113 |
113 // Tracks the current buffer allocation state. | 114 // Tracks the current buffer allocation state. |
114 BufferAllocationState buffer_allocation_state_; | 115 bool backbuffer_suggested_allocation_; |
| 116 bool frontbuffer_suggested_allocation_; |
| 117 |
| 118 // The expected size when visible. |
| 119 gfx::Size visible_size_; |
115 | 120 |
116 uint32 fbo_id_; | 121 uint32 fbo_id_; |
117 | 122 |
118 scoped_refptr<EGLAcceleratedSurface> back_surface_; | 123 scoped_refptr<EGLAcceleratedSurface> back_surface_; |
119 scoped_refptr<EGLAcceleratedSurface> front_surface_; | 124 scoped_refptr<EGLAcceleratedSurface> front_surface_; |
120 gfx::Rect previous_damage_rect_; | 125 gfx::Rect previous_damage_rect_; |
121 | 126 |
122 // Whether or not we've successfully made the surface current once. | 127 // Whether or not we've successfully made the surface current once. |
123 bool made_current_; | 128 bool made_current_; |
124 | 129 |
(...skipping 13 matching lines...) Expand all Loading... |
138 GpuCommandBufferStub* stub); | 143 GpuCommandBufferStub* stub); |
139 | 144 |
140 // gfx::GLSurface implementation: | 145 // gfx::GLSurface implementation: |
141 virtual bool Initialize() OVERRIDE; | 146 virtual bool Initialize() OVERRIDE; |
142 virtual void Destroy() OVERRIDE; | 147 virtual void Destroy() OVERRIDE; |
143 virtual bool SwapBuffers() OVERRIDE; | 148 virtual bool SwapBuffers() OVERRIDE; |
144 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 149 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
145 virtual std::string GetExtensions(); | 150 virtual std::string GetExtensions(); |
146 virtual gfx::Size GetSize() OVERRIDE; | 151 virtual gfx::Size GetSize() OVERRIDE; |
147 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 152 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
148 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 153 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 154 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
149 | 155 |
150 protected: | 156 protected: |
151 // ImageTransportSurface implementation: | 157 // ImageTransportSurface implementation: |
152 virtual void OnNewSurfaceACK( | 158 virtual void OnNewSurfaceACK( |
153 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 159 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
154 virtual void OnBuffersSwappedACK() OVERRIDE; | 160 virtual void OnBuffersSwappedACK() OVERRIDE; |
155 virtual void OnPostSubBufferACK() OVERRIDE; | 161 virtual void OnPostSubBufferACK() OVERRIDE; |
156 virtual void OnResizeViewACK() OVERRIDE; | 162 virtual void OnResizeViewACK() OVERRIDE; |
157 virtual void OnResize(gfx::Size size) OVERRIDE; | 163 virtual void OnResize(gfx::Size size) OVERRIDE; |
158 | 164 |
159 private: | 165 private: |
160 virtual ~GLXImageTransportSurface(); | 166 virtual ~GLXImageTransportSurface(); |
161 | 167 |
162 // Tell the browser to release the surface. | 168 // Tell the browser to release the surface. |
163 void ReleaseSurface(); | 169 void ReleaseSurface(); |
164 | 170 |
165 void SendBuffersSwapped(); | 171 void SendBuffersSwapped(); |
166 void SendPostSubBuffer(int x, int y, int width, int height); | 172 void SendPostSubBuffer(int x, int y, int width, int height); |
167 | 173 |
168 void ResizeSurface(gfx::Size size); | 174 void ResizeSurface(gfx::Size size); |
169 | 175 |
170 // Tracks the current buffer allocation state. | 176 // Tracks the current buffer allocation state. |
171 BufferAllocationState buffer_allocation_state_; | 177 bool backbuffer_suggested_allocation_; |
| 178 bool frontbuffer_suggested_allocation_; |
172 | 179 |
173 XID dummy_parent_; | 180 XID dummy_parent_; |
174 gfx::Size size_; | 181 gfx::Size size_; |
175 | 182 |
176 // Whether or not the image has been bound on the browser side. | 183 // Whether or not the image has been bound on the browser side. |
177 bool bound_; | 184 bool bound_; |
178 | 185 |
179 // Whether or not we need to send a resize on the next swap. | 186 // Whether or not we need to send a resize on the next swap. |
180 bool needs_resize_; | 187 bool needs_resize_; |
181 | 188 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 EGLAcceleratedSurface::~EGLAcceleratedSurface() { | 270 EGLAcceleratedSurface::~EGLAcceleratedSurface() { |
264 glDeleteTextures(1, &texture_); | 271 glDeleteTextures(1, &texture_); |
265 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); | 272 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); |
266 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); | 273 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); |
267 } | 274 } |
268 | 275 |
269 EGLImageTransportSurface::EGLImageTransportSurface( | 276 EGLImageTransportSurface::EGLImageTransportSurface( |
270 GpuChannelManager* manager, | 277 GpuChannelManager* manager, |
271 GpuCommandBufferStub* stub) | 278 GpuCommandBufferStub* stub) |
272 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(16, 16)), | 279 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(16, 16)), |
273 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 280 backbuffer_suggested_allocation_(true), |
| 281 frontbuffer_suggested_allocation_(true), |
274 fbo_id_(0), | 282 fbo_id_(0), |
275 made_current_(false) { | 283 made_current_(false) { |
276 helper_.reset(new ImageTransportHelper(this, | 284 helper_.reset(new ImageTransportHelper(this, |
277 manager, | 285 manager, |
278 stub, | 286 stub, |
279 gfx::kNullPluginWindow)); | 287 gfx::kNullPluginWindow)); |
280 } | 288 } |
281 | 289 |
282 EGLImageTransportSurface::~EGLImageTransportSurface() { | 290 EGLImageTransportSurface::~EGLImageTransportSurface() { |
283 Destroy(); | 291 Destroy(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 337 } |
330 | 338 |
331 made_current_ = true; | 339 made_current_ = true; |
332 return true; | 340 return true; |
333 } | 341 } |
334 | 342 |
335 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { | 343 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { |
336 return fbo_id_; | 344 return fbo_id_; |
337 } | 345 } |
338 | 346 |
339 void EGLImageTransportSurface::SetBufferAllocation( | 347 void EGLImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
340 BufferAllocationState state) { | 348 if (backbuffer_suggested_allocation_ == allocated) |
341 if (buffer_allocation_state_ == state) | |
342 return; | 349 return; |
343 buffer_allocation_state_ = state; | 350 backbuffer_suggested_allocation_ = allocated; |
344 | 351 |
345 switch (state) { | 352 if (backbuffer_suggested_allocation_) |
346 case BUFFER_ALLOCATION_FRONT_AND_BACK: | 353 OnResize(visible_size_); |
347 if (!back_surface_.get() && front_surface_.get()) | 354 else |
348 OnResize(front_surface_->size()); | 355 ReleaseSurface(&back_surface_); |
349 break; | 356 } |
350 | 357 |
351 case BUFFER_ALLOCATION_FRONT_ONLY: | 358 void EGLImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
352 if (back_surface_.get() && front_surface_.get()) | 359 if (frontbuffer_suggested_allocation_ == allocated) |
353 ReleaseSurface(&back_surface_); | 360 return; |
354 break; | 361 frontbuffer_suggested_allocation_ = allocated; |
355 | |
356 case BUFFER_ALLOCATION_NONE: | |
357 if (back_surface_.get() && front_surface_.get()) | |
358 ReleaseSurface(&back_surface_); | |
359 break; | |
360 | |
361 default: | |
362 NOTREACHED(); | |
363 } | |
364 } | 362 } |
365 | 363 |
366 void EGLImageTransportSurface::ReleaseSurface( | 364 void EGLImageTransportSurface::ReleaseSurface( |
367 scoped_refptr<EGLAcceleratedSurface>* surface) { | 365 scoped_refptr<EGLAcceleratedSurface>* surface) { |
368 if (surface->get()) { | 366 if (surface->get()) { |
369 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 367 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
370 params.identifier = (*surface)->pixmap(); | 368 params.identifier = (*surface)->pixmap(); |
371 helper_->SendAcceleratedSurfaceRelease(params); | 369 helper_->SendAcceleratedSurfaceRelease(params); |
372 *surface = NULL; | 370 *surface = NULL; |
373 } | 371 } |
374 } | 372 } |
375 | 373 |
376 void EGLImageTransportSurface::OnResize(gfx::Size size) { | 374 void EGLImageTransportSurface::OnResize(gfx::Size size) { |
| 375 visible_size_ = size; |
377 back_surface_ = new EGLAcceleratedSurface(size); | 376 back_surface_ = new EGLAcceleratedSurface(size); |
378 | 377 |
379 GLint previous_fbo_id = 0; | 378 GLint previous_fbo_id = 0; |
380 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previous_fbo_id); | 379 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previous_fbo_id); |
381 | 380 |
382 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id_); | 381 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id_); |
383 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 382 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
384 GL_COLOR_ATTACHMENT0, | 383 GL_COLOR_ATTACHMENT0, |
385 GL_TEXTURE_2D, | 384 GL_TEXTURE_2D, |
386 back_surface_->texture(), | 385 back_surface_->texture(), |
387 0); | 386 0); |
388 glFlush(); | 387 glFlush(); |
389 | 388 |
390 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previous_fbo_id); | 389 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previous_fbo_id); |
391 | 390 |
392 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 391 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
393 params.width = size.width(); | 392 params.width = size.width(); |
394 params.height = size.height(); | 393 params.height = size.height(); |
395 params.surface_handle = back_surface_->pixmap(); | 394 params.surface_handle = back_surface_->pixmap(); |
396 helper_->SendAcceleratedSurfaceNew(params); | 395 helper_->SendAcceleratedSurfaceNew(params); |
397 | 396 |
398 helper_->SetScheduled(false); | 397 helper_->SetScheduled(false); |
399 } | 398 } |
400 | 399 |
401 bool EGLImageTransportSurface::SwapBuffers() { | 400 bool EGLImageTransportSurface::SwapBuffers() { |
| 401 DCHECK(backbuffer_suggested_allocation_); |
| 402 if (!frontbuffer_suggested_allocation_) { |
| 403 previous_damage_rect_ = gfx::Rect(visible_size_); |
| 404 return true; |
| 405 } |
402 front_surface_.swap(back_surface_); | 406 front_surface_.swap(back_surface_); |
403 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 407 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
404 helper_->DeferToFence(base::Bind( | 408 helper_->DeferToFence(base::Bind( |
405 &EGLImageTransportSurface::SendBuffersSwapped, | 409 &EGLImageTransportSurface::SendBuffersSwapped, |
406 AsWeakPtr())); | 410 AsWeakPtr())); |
407 | 411 |
408 gfx::Size expected_size = front_surface_->size(); | 412 gfx::Size expected_size = front_surface_->size(); |
409 if (!back_surface_.get() || back_surface_->size() != expected_size) { | 413 if (!back_surface_.get() || back_surface_->size() != expected_size) { |
410 OnResize(expected_size); | 414 OnResize(expected_size); |
411 } else { | 415 } else { |
412 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 416 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
413 GL_COLOR_ATTACHMENT0, | 417 GL_COLOR_ATTACHMENT0, |
414 GL_TEXTURE_2D, | 418 GL_TEXTURE_2D, |
415 back_surface_->texture(), | 419 back_surface_->texture(), |
416 0); | 420 0); |
417 } | 421 } |
418 previous_damage_rect_ = gfx::Rect(front_surface_->size()); | 422 previous_damage_rect_ = gfx::Rect(front_surface_->size()); |
419 return true; | 423 return true; |
420 } | 424 } |
421 | 425 |
422 void EGLImageTransportSurface::SendBuffersSwapped() { | 426 void EGLImageTransportSurface::SendBuffersSwapped() { |
423 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 427 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
424 params.surface_handle = front_surface_->pixmap(); | 428 params.surface_handle = front_surface_->pixmap(); |
425 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 429 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
426 helper_->SetScheduled(false); | 430 helper_->SetScheduled(false); |
427 } | 431 } |
428 | 432 |
429 bool EGLImageTransportSurface::PostSubBuffer( | 433 bool EGLImageTransportSurface::PostSubBuffer( |
430 int x, int y, int width, int height) { | 434 int x, int y, int width, int height) { |
431 | 435 DCHECK(backbuffer_suggested_allocation_); |
| 436 if (!frontbuffer_suggested_allocation_) { |
| 437 previous_damage_rect_ = gfx::Rect(visible_size_); |
| 438 return true; |
| 439 } |
432 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 440 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
433 gfx::Size expected_size = back_surface_->size(); | 441 gfx::Size expected_size = back_surface_->size(); |
434 bool surfaces_same_size = front_surface_.get() && | 442 bool surfaces_same_size = front_surface_.get() && |
435 front_surface_->size() == expected_size; | 443 front_surface_->size() == expected_size; |
436 | 444 |
437 const gfx::Rect new_damage_rect(x, y, width, height); | 445 const gfx::Rect new_damage_rect(x, y, width, height); |
438 | 446 |
439 // An empty damage rect is a successful no-op. | 447 // An empty damage rect is a successful no-op. |
440 if (new_damage_rect.IsEmpty()) | 448 if (new_damage_rect.IsEmpty()) |
441 return true; | 449 return true; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 } | 528 } |
521 | 529 |
522 void EGLImageTransportSurface::OnResizeViewACK() { | 530 void EGLImageTransportSurface::OnResizeViewACK() { |
523 NOTREACHED(); | 531 NOTREACHED(); |
524 } | 532 } |
525 | 533 |
526 GLXImageTransportSurface::GLXImageTransportSurface( | 534 GLXImageTransportSurface::GLXImageTransportSurface( |
527 GpuChannelManager* manager, | 535 GpuChannelManager* manager, |
528 GpuCommandBufferStub* stub) | 536 GpuCommandBufferStub* stub) |
529 : gfx::NativeViewGLSurfaceGLX(), | 537 : gfx::NativeViewGLSurfaceGLX(), |
530 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 538 backbuffer_suggested_allocation_(true), |
| 539 frontbuffer_suggested_allocation_(true), |
531 dummy_parent_(0), | 540 dummy_parent_(0), |
532 size_(1, 1), | 541 size_(1, 1), |
533 bound_(false), | 542 bound_(false), |
534 needs_resize_(false), | 543 needs_resize_(false), |
535 made_current_(false) { | 544 made_current_(false) { |
536 helper_.reset(new ImageTransportHelper(this, | 545 helper_.reset(new ImageTransportHelper(this, |
537 manager, | 546 manager, |
538 stub, | 547 stub, |
539 gfx::kNullPluginWindow)); | 548 gfx::kNullPluginWindow)); |
540 } | 549 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 613 } |
605 | 614 |
606 void GLXImageTransportSurface::ReleaseSurface() { | 615 void GLXImageTransportSurface::ReleaseSurface() { |
607 DCHECK(bound_); | 616 DCHECK(bound_); |
608 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 617 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
609 params.identifier = window_; | 618 params.identifier = window_; |
610 helper_->SendAcceleratedSurfaceRelease(params); | 619 helper_->SendAcceleratedSurfaceRelease(params); |
611 bound_ = false; | 620 bound_ = false; |
612 } | 621 } |
613 | 622 |
614 void GLXImageTransportSurface::SetBufferAllocation( | 623 void GLXImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
615 BufferAllocationState state) { | 624 if (backbuffer_suggested_allocation_ == allocated) |
616 if (buffer_allocation_state_ == state) | |
617 return; | 625 return; |
618 buffer_allocation_state_ = state; | 626 backbuffer_suggested_allocation_ = allocated; |
619 | 627 |
620 switch (state) { | 628 if (backbuffer_suggested_allocation_) |
621 case BUFFER_ALLOCATION_FRONT_AND_BACK: { | 629 ResizeSurface(size_); |
622 ResizeSurface(size_); | 630 else |
623 break; | 631 ResizeSurface(gfx::Size(1,1)); |
624 } | 632 } |
625 case BUFFER_ALLOCATION_FRONT_ONLY: { | 633 |
626 ResizeSurface(gfx::Size(1,1)); | 634 void GLXImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
627 break; | 635 if (frontbuffer_suggested_allocation_ == allocated) |
628 } | 636 return; |
629 case BUFFER_ALLOCATION_NONE: { | 637 frontbuffer_suggested_allocation_ = allocated; |
630 ResizeSurface(gfx::Size(1,1)); | 638 |
631 if (bound_) | 639 // We recreate frontbuffer by recreating backbuffer and swapping. |
632 ReleaseSurface(); | 640 // But we release frontbuffer by telling UI to release its handle on it. |
633 break; | 641 if (!frontbuffer_suggested_allocation_ && bound_) |
634 } | 642 ReleaseSurface(); |
635 default: | |
636 NOTREACHED(); | |
637 } | |
638 } | 643 } |
639 | 644 |
640 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { | 645 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { |
641 Display* dpy = static_cast<Display*>(GetDisplay()); | 646 Display* dpy = static_cast<Display*>(GetDisplay()); |
642 XResizeWindow(dpy, window_, size.width(), size.height()); | 647 XResizeWindow(dpy, window_, size.width(), size.height()); |
643 glXWaitX(); | 648 glXWaitX(); |
644 // Seems necessary to perform a swap after a resize | 649 // Seems necessary to perform a swap after a resize |
645 // in order to resize the front and back buffers (Intel driver bug). | 650 // in order to resize the front and back buffers (Intel driver bug). |
646 // This doesn't always happen with scissoring enabled, so do it now. | 651 // This doesn't always happen with scissoring enabled, so do it now. |
647 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) | 652 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) |
648 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 653 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
649 needs_resize_ = true; | 654 needs_resize_ = true; |
650 } | 655 } |
651 | 656 |
652 void GLXImageTransportSurface::OnResize(gfx::Size size) { | 657 void GLXImageTransportSurface::OnResize(gfx::Size size) { |
653 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); | 658 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); |
654 size_ = size; | 659 size_ = size; |
655 ResizeSurface(size_); | 660 ResizeSurface(size_); |
656 } | 661 } |
657 | 662 |
658 bool GLXImageTransportSurface::SwapBuffers() { | 663 bool GLXImageTransportSurface::SwapBuffers() { |
| 664 DCHECK(backbuffer_suggested_allocation_); |
| 665 if (!frontbuffer_suggested_allocation_) |
| 666 return true; |
659 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 667 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
660 helper_->DeferToFence(base::Bind( | 668 helper_->DeferToFence(base::Bind( |
661 &GLXImageTransportSurface::SendBuffersSwapped, | 669 &GLXImageTransportSurface::SendBuffersSwapped, |
662 AsWeakPtr())); | 670 AsWeakPtr())); |
663 | 671 |
664 if (needs_resize_) { | 672 if (needs_resize_) { |
665 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 673 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
666 params.width = size_.width(); | 674 params.width = size_.width(); |
667 params.height = size_.height(); | 675 params.height = size_.height(); |
668 params.surface_handle = window_; | 676 params.surface_handle = window_; |
669 helper_->SendAcceleratedSurfaceNew(params); | 677 helper_->SendAcceleratedSurfaceNew(params); |
670 bound_ = true; | 678 bound_ = true; |
671 needs_resize_ = false; | 679 needs_resize_ = false; |
672 } | 680 } |
673 return true; | 681 return true; |
674 } | 682 } |
675 | 683 |
676 void GLXImageTransportSurface::SendBuffersSwapped() { | 684 void GLXImageTransportSurface::SendBuffersSwapped() { |
677 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 685 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
678 params.surface_handle = window_; | 686 params.surface_handle = window_; |
679 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 687 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
680 helper_->SetScheduled(false); | 688 helper_->SetScheduled(false); |
681 } | 689 } |
682 | 690 |
683 bool GLXImageTransportSurface::PostSubBuffer( | 691 bool GLXImageTransportSurface::PostSubBuffer( |
684 int x, int y, int width, int height) { | 692 int x, int y, int width, int height) { |
| 693 DCHECK(backbuffer_suggested_allocation_); |
| 694 if (!frontbuffer_suggested_allocation_) |
| 695 return true; |
685 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); | 696 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); |
686 helper_->DeferToFence(base::Bind( | 697 helper_->DeferToFence(base::Bind( |
687 &GLXImageTransportSurface::SendPostSubBuffer, | 698 &GLXImageTransportSurface::SendPostSubBuffer, |
688 AsWeakPtr(), x, y, width, height)); | 699 AsWeakPtr(), x, y, width, height)); |
689 | 700 |
690 if (needs_resize_) { | 701 if (needs_resize_) { |
691 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 702 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
692 params.width = size_.width(); | 703 params.width = size_.width(); |
693 params.height = size_.height(); | 704 params.height = size_.height(); |
694 params.surface_handle = window_; | 705 params.surface_handle = window_; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 stub, | 950 stub, |
940 surface.get(), | 951 surface.get(), |
941 handle.transport); | 952 handle.transport); |
942 } | 953 } |
943 | 954 |
944 if (surface->Initialize()) | 955 if (surface->Initialize()) |
945 return surface; | 956 return surface; |
946 else | 957 else |
947 return NULL; | 958 return NULL; |
948 } | 959 } |
OLD | NEW |