Chromium Code Reviews| 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 <map> | 10 #include <map> |
| (...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); |
| 113 void AdjustBufferAllocations(); | |
| 112 | 114 |
| 113 // Tracks the current buffer allocation state. | 115 // Tracks the current buffer allocation state. |
| 114 BufferAllocationState buffer_allocation_state_; | 116 bool backbuffer_suggested_allocation_; |
| 117 bool frontbuffer_suggested_allocation_; | |
| 115 | 118 |
| 116 uint32 fbo_id_; | 119 uint32 fbo_id_; |
| 117 | 120 |
| 118 scoped_refptr<EGLAcceleratedSurface> back_surface_; | 121 scoped_refptr<EGLAcceleratedSurface> back_surface_; |
| 119 scoped_refptr<EGLAcceleratedSurface> front_surface_; | 122 scoped_refptr<EGLAcceleratedSurface> front_surface_; |
| 120 gfx::Rect previous_damage_rect_; | 123 gfx::Rect previous_damage_rect_; |
| 121 | 124 |
| 122 // Whether or not we've successfully made the surface current once. | 125 // Whether or not we've successfully made the surface current once. |
| 123 bool made_current_; | 126 bool made_current_; |
| 124 | 127 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 138 GpuCommandBufferStub* stub); | 141 GpuCommandBufferStub* stub); |
| 139 | 142 |
| 140 // gfx::GLSurface implementation: | 143 // gfx::GLSurface implementation: |
| 141 virtual bool Initialize() OVERRIDE; | 144 virtual bool Initialize() OVERRIDE; |
| 142 virtual void Destroy() OVERRIDE; | 145 virtual void Destroy() OVERRIDE; |
| 143 virtual bool SwapBuffers() OVERRIDE; | 146 virtual bool SwapBuffers() OVERRIDE; |
| 144 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 147 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 145 virtual std::string GetExtensions(); | 148 virtual std::string GetExtensions(); |
| 146 virtual gfx::Size GetSize() OVERRIDE; | 149 virtual gfx::Size GetSize() OVERRIDE; |
| 147 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 150 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 148 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 151 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 152 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; | |
| 149 | 153 |
| 150 protected: | 154 protected: |
| 151 // ImageTransportSurface implementation: | 155 // ImageTransportSurface implementation: |
| 152 virtual void OnNewSurfaceACK( | 156 virtual void OnNewSurfaceACK( |
| 153 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 157 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
| 154 virtual void OnBuffersSwappedACK() OVERRIDE; | 158 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 155 virtual void OnPostSubBufferACK() OVERRIDE; | 159 virtual void OnPostSubBufferACK() OVERRIDE; |
| 156 virtual void OnResizeViewACK() OVERRIDE; | 160 virtual void OnResizeViewACK() OVERRIDE; |
| 157 virtual void OnResize(gfx::Size size) OVERRIDE; | 161 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 158 | 162 |
| 159 private: | 163 private: |
| 160 virtual ~GLXImageTransportSurface(); | 164 virtual ~GLXImageTransportSurface(); |
| 161 | 165 |
| 162 // Tell the browser to release the surface. | 166 // Tell the browser to release the surface. |
| 163 void ReleaseSurface(); | 167 void ReleaseSurface(); |
| 164 | 168 |
| 165 void SendBuffersSwapped(); | 169 void SendBuffersSwapped(); |
| 166 void SendPostSubBuffer(int x, int y, int width, int height); | 170 void SendPostSubBuffer(int x, int y, int width, int height); |
| 167 | 171 |
| 168 void ResizeSurface(gfx::Size size); | 172 void ResizeSurface(gfx::Size size); |
| 173 void AdjustBufferAllocations(); | |
| 169 | 174 |
| 170 // Tracks the current buffer allocation state. | 175 // Tracks the current buffer allocation state. |
| 171 BufferAllocationState buffer_allocation_state_; | 176 bool backbuffer_suggested_allocation_; |
| 177 bool frontbuffer_suggested_allocation_; | |
| 172 | 178 |
| 173 XID dummy_parent_; | 179 XID dummy_parent_; |
| 174 gfx::Size size_; | 180 gfx::Size size_; |
| 175 | 181 |
| 176 // Whether or not the image has been bound on the browser side. | 182 // Whether or not the image has been bound on the browser side. |
| 177 bool bound_; | 183 bool bound_; |
| 178 | 184 |
| 179 // Whether or not we need to send a resize on the next swap. | 185 // Whether or not we need to send a resize on the next swap. |
| 180 bool needs_resize_; | 186 bool needs_resize_; |
| 181 | 187 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 EGLAcceleratedSurface::~EGLAcceleratedSurface() { | 269 EGLAcceleratedSurface::~EGLAcceleratedSurface() { |
| 264 glDeleteTextures(1, &texture_); | 270 glDeleteTextures(1, &texture_); |
| 265 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); | 271 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); |
| 266 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); | 272 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); |
| 267 } | 273 } |
| 268 | 274 |
| 269 EGLImageTransportSurface::EGLImageTransportSurface( | 275 EGLImageTransportSurface::EGLImageTransportSurface( |
| 270 GpuChannelManager* manager, | 276 GpuChannelManager* manager, |
| 271 GpuCommandBufferStub* stub) | 277 GpuCommandBufferStub* stub) |
| 272 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(16, 16)), | 278 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(16, 16)), |
| 273 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 279 backbuffer_suggested_allocation_(true), |
| 280 frontbuffer_suggested_allocation_(true), | |
| 274 fbo_id_(0), | 281 fbo_id_(0), |
| 275 made_current_(false) { | 282 made_current_(false) { |
| 276 helper_.reset(new ImageTransportHelper(this, | 283 helper_.reset(new ImageTransportHelper(this, |
| 277 manager, | 284 manager, |
| 278 stub, | 285 stub, |
| 279 gfx::kNullPluginWindow)); | 286 gfx::kNullPluginWindow)); |
| 280 } | 287 } |
| 281 | 288 |
| 282 EGLImageTransportSurface::~EGLImageTransportSurface() { | 289 EGLImageTransportSurface::~EGLImageTransportSurface() { |
| 283 Destroy(); | 290 Destroy(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } | 336 } |
| 330 | 337 |
| 331 made_current_ = true; | 338 made_current_ = true; |
| 332 return true; | 339 return true; |
| 333 } | 340 } |
| 334 | 341 |
| 335 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { | 342 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { |
| 336 return fbo_id_; | 343 return fbo_id_; |
| 337 } | 344 } |
| 338 | 345 |
| 339 void EGLImageTransportSurface::SetBufferAllocation( | 346 void EGLImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
| 340 BufferAllocationState state) { | 347 if (backbuffer_suggested_allocation_ == allocated) |
| 341 if (buffer_allocation_state_ == state) | |
| 342 return; | 348 return; |
| 343 buffer_allocation_state_ = state; | 349 backbuffer_suggested_allocation_ = allocated; |
| 350 AdjustBufferAllocations(); | |
| 351 } | |
| 344 | 352 |
| 345 switch (state) { | 353 void EGLImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
| 346 case BUFFER_ALLOCATION_FRONT_AND_BACK: | 354 if (frontbuffer_suggested_allocation_ == allocated) |
| 347 if (!back_surface_.get() && front_surface_.get()) | 355 return; |
| 348 OnResize(front_surface_->size()); | 356 frontbuffer_suggested_allocation_ = allocated; |
| 349 break; | 357 AdjustBufferAllocations(); |
| 358 } | |
| 350 | 359 |
| 351 case BUFFER_ALLOCATION_FRONT_ONLY: | 360 void EGLImageTransportSurface::AdjustBufferAllocations() { |
| 352 if (back_surface_.get() && front_surface_.get()) | 361 if (backbuffer_suggested_allocation_) { |
| 353 ReleaseSurface(&back_surface_); | 362 if (back_surface_.get()) |
| 354 break; | 363 return; |
| 355 | 364 if (!front_surface_.get()) |
| 356 case BUFFER_ALLOCATION_NONE: | 365 return; |
| 357 if (back_surface_.get() && front_surface_.get()) | 366 OnResize(front_surface_->size()); |
|
jonathan.backer
2012/05/09 18:13:01
AFAICT, we're only managing the backbuffer here. S
mmocny
2012/05/09 18:59:15
Yes, we need front only to read size, and we shoul
| |
| 358 ReleaseSurface(&back_surface_); | 367 } else { |
| 359 break; | 368 if (!back_surface_.get()) |
| 360 | 369 return; |
| 361 default: | 370 if (!front_surface_.get()) |
| 362 NOTREACHED(); | 371 return; |
|
jonathan.backer
2012/05/09 18:13:01
Why do we exit early here? Perhaps we should never
mmocny
2012/05/09 18:59:15
Its possible that this is testing for a case that
| |
| 372 ReleaseSurface(&back_surface_); | |
| 363 } | 373 } |
| 364 } | 374 } |
| 365 | 375 |
| 376 | |
| 366 void EGLImageTransportSurface::ReleaseSurface( | 377 void EGLImageTransportSurface::ReleaseSurface( |
| 367 scoped_refptr<EGLAcceleratedSurface>* surface) { | 378 scoped_refptr<EGLAcceleratedSurface>* surface) { |
| 368 if (surface->get()) { | 379 if (surface->get()) { |
| 369 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 380 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| 370 params.identifier = (*surface)->pixmap(); | 381 params.identifier = (*surface)->pixmap(); |
| 371 helper_->SendAcceleratedSurfaceRelease(params); | 382 helper_->SendAcceleratedSurfaceRelease(params); |
| 372 *surface = NULL; | 383 *surface = NULL; |
| 373 } | 384 } |
| 374 } | 385 } |
| 375 | 386 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 392 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 403 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 393 params.width = size.width(); | 404 params.width = size.width(); |
| 394 params.height = size.height(); | 405 params.height = size.height(); |
| 395 params.surface_handle = back_surface_->pixmap(); | 406 params.surface_handle = back_surface_->pixmap(); |
| 396 helper_->SendAcceleratedSurfaceNew(params); | 407 helper_->SendAcceleratedSurfaceNew(params); |
| 397 | 408 |
| 398 helper_->SetScheduled(false); | 409 helper_->SetScheduled(false); |
| 399 } | 410 } |
| 400 | 411 |
| 401 bool EGLImageTransportSurface::SwapBuffers() { | 412 bool EGLImageTransportSurface::SwapBuffers() { |
| 413 DCHECK(backbuffer_suggested_allocation_); | |
| 414 DCHECK(frontbuffer_suggested_allocation_); | |
| 402 front_surface_.swap(back_surface_); | 415 front_surface_.swap(back_surface_); |
| 403 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 416 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
| 404 helper_->DeferToFence(base::Bind( | 417 helper_->DeferToFence(base::Bind( |
| 405 &EGLImageTransportSurface::SendBuffersSwapped, | 418 &EGLImageTransportSurface::SendBuffersSwapped, |
| 406 AsWeakPtr())); | 419 AsWeakPtr())); |
| 407 | 420 |
| 408 gfx::Size expected_size = front_surface_->size(); | 421 gfx::Size expected_size = front_surface_->size(); |
| 409 if (!back_surface_.get() || back_surface_->size() != expected_size) { | 422 if (!back_surface_.get() || back_surface_->size() != expected_size) { |
| 410 OnResize(expected_size); | 423 OnResize(expected_size); |
| 411 } else { | 424 } else { |
| 412 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 425 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 413 GL_COLOR_ATTACHMENT0, | 426 GL_COLOR_ATTACHMENT0, |
| 414 GL_TEXTURE_2D, | 427 GL_TEXTURE_2D, |
| 415 back_surface_->texture(), | 428 back_surface_->texture(), |
| 416 0); | 429 0); |
| 417 } | 430 } |
| 418 previous_damage_rect_ = gfx::Rect(front_surface_->size()); | 431 previous_damage_rect_ = gfx::Rect(front_surface_->size()); |
| 419 return true; | 432 return true; |
| 420 } | 433 } |
| 421 | 434 |
| 422 void EGLImageTransportSurface::SendBuffersSwapped() { | 435 void EGLImageTransportSurface::SendBuffersSwapped() { |
| 423 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 436 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 424 params.surface_handle = front_surface_->pixmap(); | 437 params.surface_handle = front_surface_->pixmap(); |
| 425 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 438 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 426 helper_->SetScheduled(false); | 439 helper_->SetScheduled(false); |
| 427 } | 440 } |
| 428 | 441 |
| 429 bool EGLImageTransportSurface::PostSubBuffer( | 442 bool EGLImageTransportSurface::PostSubBuffer( |
| 430 int x, int y, int width, int height) { | 443 int x, int y, int width, int height) { |
| 431 | 444 DCHECK(backbuffer_suggested_allocation_); |
| 445 DCHECK(frontbuffer_suggested_allocation_); | |
| 432 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 446 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
| 433 gfx::Size expected_size = back_surface_->size(); | 447 gfx::Size expected_size = back_surface_->size(); |
| 434 bool surfaces_same_size = front_surface_.get() && | 448 bool surfaces_same_size = front_surface_.get() && |
| 435 front_surface_->size() == expected_size; | 449 front_surface_->size() == expected_size; |
| 436 | 450 |
| 437 const gfx::Rect new_damage_rect(x, y, width, height); | 451 const gfx::Rect new_damage_rect(x, y, width, height); |
| 438 | 452 |
| 439 // An empty damage rect is a successful no-op. | 453 // An empty damage rect is a successful no-op. |
| 440 if (new_damage_rect.IsEmpty()) | 454 if (new_damage_rect.IsEmpty()) |
| 441 return true; | 455 return true; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 } | 534 } |
| 521 | 535 |
| 522 void EGLImageTransportSurface::OnResizeViewACK() { | 536 void EGLImageTransportSurface::OnResizeViewACK() { |
| 523 NOTREACHED(); | 537 NOTREACHED(); |
| 524 } | 538 } |
| 525 | 539 |
| 526 GLXImageTransportSurface::GLXImageTransportSurface( | 540 GLXImageTransportSurface::GLXImageTransportSurface( |
| 527 GpuChannelManager* manager, | 541 GpuChannelManager* manager, |
| 528 GpuCommandBufferStub* stub) | 542 GpuCommandBufferStub* stub) |
| 529 : gfx::NativeViewGLSurfaceGLX(), | 543 : gfx::NativeViewGLSurfaceGLX(), |
| 530 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 544 backbuffer_suggested_allocation_(true), |
| 545 frontbuffer_suggested_allocation_(true), | |
| 531 dummy_parent_(0), | 546 dummy_parent_(0), |
| 532 size_(1, 1), | 547 size_(1, 1), |
| 533 bound_(false), | 548 bound_(false), |
| 534 needs_resize_(false), | 549 needs_resize_(false), |
| 535 made_current_(false) { | 550 made_current_(false) { |
| 536 helper_.reset(new ImageTransportHelper(this, | 551 helper_.reset(new ImageTransportHelper(this, |
| 537 manager, | 552 manager, |
| 538 stub, | 553 stub, |
| 539 gfx::kNullPluginWindow)); | 554 gfx::kNullPluginWindow)); |
| 540 } | 555 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 } | 619 } |
| 605 | 620 |
| 606 void GLXImageTransportSurface::ReleaseSurface() { | 621 void GLXImageTransportSurface::ReleaseSurface() { |
| 607 DCHECK(bound_); | 622 DCHECK(bound_); |
| 608 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 623 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| 609 params.identifier = window_; | 624 params.identifier = window_; |
| 610 helper_->SendAcceleratedSurfaceRelease(params); | 625 helper_->SendAcceleratedSurfaceRelease(params); |
| 611 bound_ = false; | 626 bound_ = false; |
| 612 } | 627 } |
| 613 | 628 |
| 614 void GLXImageTransportSurface::SetBufferAllocation( | 629 void GLXImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
| 615 BufferAllocationState state) { | 630 if (backbuffer_suggested_allocation_ == allocated) |
| 616 if (buffer_allocation_state_ == state) | |
| 617 return; | 631 return; |
| 618 buffer_allocation_state_ = state; | 632 backbuffer_suggested_allocation_ = allocated; |
| 633 AdjustBufferAllocations(); | |
| 634 } | |
| 619 | 635 |
| 620 switch (state) { | 636 void GLXImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
| 621 case BUFFER_ALLOCATION_FRONT_AND_BACK: { | 637 if (frontbuffer_suggested_allocation_ == allocated) |
| 622 ResizeSurface(size_); | 638 return; |
| 623 break; | 639 frontbuffer_suggested_allocation_ = allocated; |
| 624 } | 640 AdjustBufferAllocations(); |
| 625 case BUFFER_ALLOCATION_FRONT_ONLY: { | 641 } |
| 626 ResizeSurface(gfx::Size(1,1)); | 642 |
| 627 break; | 643 void GLXImageTransportSurface::AdjustBufferAllocations() { |
| 628 } | 644 if (backbuffer_suggested_allocation_) { |
| 629 case BUFFER_ALLOCATION_NONE: { | 645 ResizeSurface(size_); |
| 630 ResizeSurface(gfx::Size(1,1)); | 646 } else { |
| 631 if (bound_) | 647 ResizeSurface(gfx::Size(1,1)); |
| 632 ReleaseSurface(); | 648 if (!frontbuffer_suggested_allocation_ && bound_) |
| 633 break; | 649 ReleaseSurface(); |
| 634 } | |
| 635 default: | |
| 636 NOTREACHED(); | |
| 637 } | 650 } |
| 638 } | 651 } |
| 639 | 652 |
| 640 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { | 653 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { |
| 641 Display* dpy = static_cast<Display*>(GetDisplay()); | 654 Display* dpy = static_cast<Display*>(GetDisplay()); |
| 642 XResizeWindow(dpy, window_, size.width(), size.height()); | 655 XResizeWindow(dpy, window_, size.width(), size.height()); |
| 643 glXWaitX(); | 656 glXWaitX(); |
| 644 // Seems necessary to perform a swap after a resize | 657 // Seems necessary to perform a swap after a resize |
| 645 // in order to resize the front and back buffers (Intel driver bug). | 658 // 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. | 659 // 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) | 660 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) |
| 648 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 661 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
| 649 needs_resize_ = true; | 662 needs_resize_ = true; |
| 650 } | 663 } |
| 651 | 664 |
| 652 void GLXImageTransportSurface::OnResize(gfx::Size size) { | 665 void GLXImageTransportSurface::OnResize(gfx::Size size) { |
| 653 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); | 666 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); |
| 654 size_ = size; | 667 size_ = size; |
| 655 ResizeSurface(size_); | 668 ResizeSurface(size_); |
| 656 } | 669 } |
| 657 | 670 |
| 658 bool GLXImageTransportSurface::SwapBuffers() { | 671 bool GLXImageTransportSurface::SwapBuffers() { |
| 672 DCHECK(backbuffer_suggested_allocation_); | |
| 673 DCHECK(frontbuffer_suggested_allocation_); | |
| 659 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 674 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
| 660 helper_->DeferToFence(base::Bind( | 675 helper_->DeferToFence(base::Bind( |
| 661 &GLXImageTransportSurface::SendBuffersSwapped, | 676 &GLXImageTransportSurface::SendBuffersSwapped, |
| 662 AsWeakPtr())); | 677 AsWeakPtr())); |
| 663 | 678 |
| 664 if (needs_resize_) { | 679 if (needs_resize_) { |
| 665 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 680 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 666 params.width = size_.width(); | 681 params.width = size_.width(); |
| 667 params.height = size_.height(); | 682 params.height = size_.height(); |
| 668 params.surface_handle = window_; | 683 params.surface_handle = window_; |
| 669 helper_->SendAcceleratedSurfaceNew(params); | 684 helper_->SendAcceleratedSurfaceNew(params); |
| 670 bound_ = true; | 685 bound_ = true; |
| 671 needs_resize_ = false; | 686 needs_resize_ = false; |
| 672 } | 687 } |
| 673 return true; | 688 return true; |
| 674 } | 689 } |
| 675 | 690 |
| 676 void GLXImageTransportSurface::SendBuffersSwapped() { | 691 void GLXImageTransportSurface::SendBuffersSwapped() { |
| 677 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 692 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 678 params.surface_handle = window_; | 693 params.surface_handle = window_; |
| 679 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 694 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 680 helper_->SetScheduled(false); | 695 helper_->SetScheduled(false); |
| 681 } | 696 } |
| 682 | 697 |
| 683 bool GLXImageTransportSurface::PostSubBuffer( | 698 bool GLXImageTransportSurface::PostSubBuffer( |
| 684 int x, int y, int width, int height) { | 699 int x, int y, int width, int height) { |
| 700 DCHECK(backbuffer_suggested_allocation_); | |
| 701 DCHECK(frontbuffer_suggested_allocation_); | |
| 685 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); | 702 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); |
| 686 helper_->DeferToFence(base::Bind( | 703 helper_->DeferToFence(base::Bind( |
| 687 &GLXImageTransportSurface::SendPostSubBuffer, | 704 &GLXImageTransportSurface::SendPostSubBuffer, |
| 688 AsWeakPtr(), x, y, width, height)); | 705 AsWeakPtr(), x, y, width, height)); |
| 689 | 706 |
| 690 if (needs_resize_) { | 707 if (needs_resize_) { |
| 691 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 708 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 692 params.width = size_.width(); | 709 params.width = size_.width(); |
| 693 params.height = size_.height(); | 710 params.height = size_.height(); |
| 694 params.surface_handle = window_; | 711 params.surface_handle = window_; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 stub, | 956 stub, |
| 940 surface.get(), | 957 surface.get(), |
| 941 handle.transport); | 958 handle.transport); |
| 942 } | 959 } |
| 943 | 960 |
| 944 if (surface->Initialize()) | 961 if (surface->Initialize()) |
| 945 return surface; | 962 return surface; |
| 946 else | 963 else |
| 947 return NULL; | 964 return NULL; |
| 948 } | 965 } |
| OLD | NEW |