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 <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_) | |
|
jonathan.backer
2012/05/15 15:53:31
Need to set |previous_damage_rect_| here. AFAIK, w
mmocny
2012/05/15 20:02:28
Actually, I think I need to set previous damage to
jonathan.backer
2012/05/16 02:39:01
We use |previous_damage_rect_| for two frame damag
| |
| 403 return true; | |
| 402 front_surface_.swap(back_surface_); | 404 front_surface_.swap(back_surface_); |
| 403 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 405 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
| 404 helper_->DeferToFence(base::Bind( | 406 helper_->DeferToFence(base::Bind( |
| 405 &EGLImageTransportSurface::SendBuffersSwapped, | 407 &EGLImageTransportSurface::SendBuffersSwapped, |
| 406 AsWeakPtr())); | 408 AsWeakPtr())); |
| 407 | 409 |
| 408 gfx::Size expected_size = front_surface_->size(); | 410 gfx::Size expected_size = front_surface_->size(); |
| 409 if (!back_surface_.get() || back_surface_->size() != expected_size) { | 411 if (!back_surface_.get() || back_surface_->size() != expected_size) { |
| 410 OnResize(expected_size); | 412 OnResize(expected_size); |
| 411 } else { | 413 } else { |
| 412 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 414 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 413 GL_COLOR_ATTACHMENT0, | 415 GL_COLOR_ATTACHMENT0, |
| 414 GL_TEXTURE_2D, | 416 GL_TEXTURE_2D, |
| 415 back_surface_->texture(), | 417 back_surface_->texture(), |
| 416 0); | 418 0); |
| 417 } | 419 } |
| 418 previous_damage_rect_ = gfx::Rect(front_surface_->size()); | 420 previous_damage_rect_ = gfx::Rect(front_surface_->size()); |
| 419 return true; | 421 return true; |
| 420 } | 422 } |
| 421 | 423 |
| 422 void EGLImageTransportSurface::SendBuffersSwapped() { | 424 void EGLImageTransportSurface::SendBuffersSwapped() { |
| 423 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 425 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 424 params.surface_handle = front_surface_->pixmap(); | 426 params.surface_handle = front_surface_->pixmap(); |
| 425 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 427 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 426 helper_->SetScheduled(false); | 428 helper_->SetScheduled(false); |
| 427 } | 429 } |
| 428 | 430 |
| 429 bool EGLImageTransportSurface::PostSubBuffer( | 431 bool EGLImageTransportSurface::PostSubBuffer( |
| 430 int x, int y, int width, int height) { | 432 int x, int y, int width, int height) { |
| 431 | 433 DCHECK(backbuffer_suggested_allocation_); |
| 434 if (!frontbuffer_suggested_allocation_) | |
|
jonathan.backer
2012/05/15 15:53:31
I think that we need to set |previous_damage_rect_
mmocny
2012/05/15 20:02:28
I dont think we do read from the frontbuffer (righ
jonathan.backer
2012/05/16 02:39:01
We often do a copy from the front buffer to the ba
mmocny
2012/05/16 14:41:50
I see, thank you for clearing up the direction of
| |
| 435 return true; | |
| 432 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 436 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
| 433 gfx::Size expected_size = back_surface_->size(); | 437 gfx::Size expected_size = back_surface_->size(); |
| 434 bool surfaces_same_size = front_surface_.get() && | 438 bool surfaces_same_size = front_surface_.get() && |
| 435 front_surface_->size() == expected_size; | 439 front_surface_->size() == expected_size; |
| 436 | 440 |
| 437 const gfx::Rect new_damage_rect(x, y, width, height); | 441 const gfx::Rect new_damage_rect(x, y, width, height); |
| 438 | 442 |
| 439 // An empty damage rect is a successful no-op. | 443 // An empty damage rect is a successful no-op. |
| 440 if (new_damage_rect.IsEmpty()) | 444 if (new_damage_rect.IsEmpty()) |
| 441 return true; | 445 return true; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 } | 524 } |
| 521 | 525 |
| 522 void EGLImageTransportSurface::OnResizeViewACK() { | 526 void EGLImageTransportSurface::OnResizeViewACK() { |
| 523 NOTREACHED(); | 527 NOTREACHED(); |
| 524 } | 528 } |
| 525 | 529 |
| 526 GLXImageTransportSurface::GLXImageTransportSurface( | 530 GLXImageTransportSurface::GLXImageTransportSurface( |
| 527 GpuChannelManager* manager, | 531 GpuChannelManager* manager, |
| 528 GpuCommandBufferStub* stub) | 532 GpuCommandBufferStub* stub) |
| 529 : gfx::NativeViewGLSurfaceGLX(), | 533 : gfx::NativeViewGLSurfaceGLX(), |
| 530 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 534 backbuffer_suggested_allocation_(true), |
| 535 frontbuffer_suggested_allocation_(true), | |
| 531 dummy_parent_(0), | 536 dummy_parent_(0), |
| 532 size_(1, 1), | 537 size_(1, 1), |
| 533 bound_(false), | 538 bound_(false), |
| 534 needs_resize_(false), | 539 needs_resize_(false), |
| 535 made_current_(false) { | 540 made_current_(false) { |
| 536 helper_.reset(new ImageTransportHelper(this, | 541 helper_.reset(new ImageTransportHelper(this, |
| 537 manager, | 542 manager, |
| 538 stub, | 543 stub, |
| 539 gfx::kNullPluginWindow)); | 544 gfx::kNullPluginWindow)); |
| 540 } | 545 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 } | 609 } |
| 605 | 610 |
| 606 void GLXImageTransportSurface::ReleaseSurface() { | 611 void GLXImageTransportSurface::ReleaseSurface() { |
| 607 DCHECK(bound_); | 612 DCHECK(bound_); |
| 608 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 613 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| 609 params.identifier = window_; | 614 params.identifier = window_; |
| 610 helper_->SendAcceleratedSurfaceRelease(params); | 615 helper_->SendAcceleratedSurfaceRelease(params); |
| 611 bound_ = false; | 616 bound_ = false; |
| 612 } | 617 } |
| 613 | 618 |
| 614 void GLXImageTransportSurface::SetBufferAllocation( | 619 void GLXImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
| 615 BufferAllocationState state) { | 620 if (backbuffer_suggested_allocation_ == allocated) |
| 616 if (buffer_allocation_state_ == state) | |
| 617 return; | 621 return; |
| 618 buffer_allocation_state_ = state; | 622 backbuffer_suggested_allocation_ = allocated; |
| 619 | 623 |
| 620 switch (state) { | 624 if (backbuffer_suggested_allocation_) |
| 621 case BUFFER_ALLOCATION_FRONT_AND_BACK: { | 625 ResizeSurface(size_); |
| 622 ResizeSurface(size_); | 626 else |
| 623 break; | 627 ResizeSurface(gfx::Size(1,1)); |
| 624 } | 628 } |
| 625 case BUFFER_ALLOCATION_FRONT_ONLY: { | 629 |
| 626 ResizeSurface(gfx::Size(1,1)); | 630 void GLXImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
| 627 break; | 631 if (frontbuffer_suggested_allocation_ == allocated) |
| 628 } | 632 return; |
| 629 case BUFFER_ALLOCATION_NONE: { | 633 frontbuffer_suggested_allocation_ = allocated; |
| 630 ResizeSurface(gfx::Size(1,1)); | 634 |
| 631 if (bound_) | 635 // We recreate frontbuffer by recreating backbuffer and swapping. |
| 632 ReleaseSurface(); | 636 // But we release frontbuffer by telling UI to release its handle on it. |
| 633 break; | 637 if (!frontbuffer_suggested_allocation_ && bound_) |
| 634 } | 638 ReleaseSurface(); |
| 635 default: | |
| 636 NOTREACHED(); | |
| 637 } | |
| 638 } | 639 } |
| 639 | 640 |
| 640 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { | 641 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { |
| 641 Display* dpy = static_cast<Display*>(GetDisplay()); | 642 Display* dpy = static_cast<Display*>(GetDisplay()); |
| 642 XResizeWindow(dpy, window_, size.width(), size.height()); | 643 XResizeWindow(dpy, window_, size.width(), size.height()); |
| 643 glXWaitX(); | 644 glXWaitX(); |
| 644 // Seems necessary to perform a swap after a resize | 645 // Seems necessary to perform a swap after a resize |
| 645 // in order to resize the front and back buffers (Intel driver bug). | 646 // 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. | 647 // 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) | 648 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) |
| 648 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 649 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
| 649 needs_resize_ = true; | 650 needs_resize_ = true; |
| 650 } | 651 } |
| 651 | 652 |
| 652 void GLXImageTransportSurface::OnResize(gfx::Size size) { | 653 void GLXImageTransportSurface::OnResize(gfx::Size size) { |
| 653 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); | 654 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); |
| 654 size_ = size; | 655 size_ = size; |
| 655 ResizeSurface(size_); | 656 ResizeSurface(size_); |
| 656 } | 657 } |
| 657 | 658 |
| 658 bool GLXImageTransportSurface::SwapBuffers() { | 659 bool GLXImageTransportSurface::SwapBuffers() { |
| 660 DCHECK(backbuffer_suggested_allocation_); | |
| 661 if (!frontbuffer_suggested_allocation_) | |
| 662 return true; | |
| 659 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 663 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
| 660 helper_->DeferToFence(base::Bind( | 664 helper_->DeferToFence(base::Bind( |
| 661 &GLXImageTransportSurface::SendBuffersSwapped, | 665 &GLXImageTransportSurface::SendBuffersSwapped, |
| 662 AsWeakPtr())); | 666 AsWeakPtr())); |
| 663 | 667 |
| 664 if (needs_resize_) { | 668 if (needs_resize_) { |
| 665 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 669 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 666 params.width = size_.width(); | 670 params.width = size_.width(); |
| 667 params.height = size_.height(); | 671 params.height = size_.height(); |
| 668 params.surface_handle = window_; | 672 params.surface_handle = window_; |
| 669 helper_->SendAcceleratedSurfaceNew(params); | 673 helper_->SendAcceleratedSurfaceNew(params); |
| 670 bound_ = true; | 674 bound_ = true; |
| 671 needs_resize_ = false; | 675 needs_resize_ = false; |
| 672 } | 676 } |
| 673 return true; | 677 return true; |
| 674 } | 678 } |
| 675 | 679 |
| 676 void GLXImageTransportSurface::SendBuffersSwapped() { | 680 void GLXImageTransportSurface::SendBuffersSwapped() { |
| 677 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 681 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 678 params.surface_handle = window_; | 682 params.surface_handle = window_; |
| 679 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 683 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 680 helper_->SetScheduled(false); | 684 helper_->SetScheduled(false); |
| 681 } | 685 } |
| 682 | 686 |
| 683 bool GLXImageTransportSurface::PostSubBuffer( | 687 bool GLXImageTransportSurface::PostSubBuffer( |
| 684 int x, int y, int width, int height) { | 688 int x, int y, int width, int height) { |
| 689 DCHECK(backbuffer_suggested_allocation_); | |
| 690 if (!frontbuffer_suggested_allocation_) | |
| 691 return true; | |
| 685 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); | 692 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); |
| 686 helper_->DeferToFence(base::Bind( | 693 helper_->DeferToFence(base::Bind( |
| 687 &GLXImageTransportSurface::SendPostSubBuffer, | 694 &GLXImageTransportSurface::SendPostSubBuffer, |
| 688 AsWeakPtr(), x, y, width, height)); | 695 AsWeakPtr(), x, y, width, height)); |
| 689 | 696 |
| 690 if (needs_resize_) { | 697 if (needs_resize_) { |
| 691 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 698 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 692 params.width = size_.width(); | 699 params.width = size_.width(); |
| 693 params.height = size_.height(); | 700 params.height = size_.height(); |
| 694 params.surface_handle = window_; | 701 params.surface_handle = window_; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 stub, | 946 stub, |
| 940 surface.get(), | 947 surface.get(), |
| 941 handle.transport); | 948 handle.transport); |
| 942 } | 949 } |
| 943 | 950 |
| 944 if (surface->Initialize()) | 951 if (surface->Initialize()) |
| 945 return surface; | 952 return surface; |
| 946 else | 953 else |
| 947 return NULL; | 954 return NULL; |
| 948 } | 955 } |
| OLD | NEW |