| 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 SetVisibility(VisibilityState visibility_state) OVERRIDE; | 96 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; |
| 97 | 97 |
| 98 protected: | 98 protected: |
| 99 // ImageTransportSurface implementation | 99 // ImageTransportSurface implementation |
| 100 virtual void OnNewSurfaceACK( | 100 virtual void OnNewSurfaceACK( |
| 101 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 101 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
| 102 virtual void OnBuffersSwappedACK() OVERRIDE; | 102 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 103 virtual void OnPostSubBufferACK() OVERRIDE; | 103 virtual void OnPostSubBufferACK() OVERRIDE; |
| 104 virtual void OnResizeViewACK() OVERRIDE; | 104 virtual void OnResizeViewACK() OVERRIDE; |
| 105 virtual void OnResize(gfx::Size size) OVERRIDE; | 105 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 virtual ~EGLImageTransportSurface() OVERRIDE; | 108 virtual ~EGLImageTransportSurface() OVERRIDE; |
| 109 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); | 109 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); |
| 110 void SendBuffersSwapped(); | 110 void SendBuffersSwapped(); |
| 111 void SendPostSubBuffer(int x, int y, int width, int height); | 111 void SendPostSubBuffer(int x, int y, int width, int height); |
| 112 | 112 |
| 113 // Tracks the current surface visibility state. | 113 // Tracks the current buffer allocation state. |
| 114 VisibilityState visibility_state_; | 114 BufferAllocationState buffer_allocation_state_; |
| 115 | 115 |
| 116 uint32 fbo_id_; | 116 uint32 fbo_id_; |
| 117 | 117 |
| 118 scoped_refptr<EGLAcceleratedSurface> back_surface_; | 118 scoped_refptr<EGLAcceleratedSurface> back_surface_; |
| 119 scoped_refptr<EGLAcceleratedSurface> front_surface_; | 119 scoped_refptr<EGLAcceleratedSurface> front_surface_; |
| 120 gfx::Rect previous_damage_rect_; | 120 gfx::Rect previous_damage_rect_; |
| 121 | 121 |
| 122 // Whether or not we've successfully made the surface current once. | 122 // Whether or not we've successfully made the surface current once. |
| 123 bool made_current_; | 123 bool made_current_; |
| 124 | 124 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 138 GpuCommandBufferStub* stub); | 138 GpuCommandBufferStub* stub); |
| 139 | 139 |
| 140 // gfx::GLSurface implementation: | 140 // gfx::GLSurface implementation: |
| 141 virtual bool Initialize() OVERRIDE; | 141 virtual bool Initialize() OVERRIDE; |
| 142 virtual void Destroy() OVERRIDE; | 142 virtual void Destroy() OVERRIDE; |
| 143 virtual bool SwapBuffers() OVERRIDE; | 143 virtual bool SwapBuffers() OVERRIDE; |
| 144 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 144 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 145 virtual std::string GetExtensions(); | 145 virtual std::string GetExtensions(); |
| 146 virtual gfx::Size GetSize() OVERRIDE; | 146 virtual gfx::Size GetSize() OVERRIDE; |
| 147 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 147 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 148 virtual void SetVisibility(VisibilityState visibility_state) OVERRIDE; | 148 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; |
| 149 | 149 |
| 150 protected: | 150 protected: |
| 151 // ImageTransportSurface implementation: | 151 // ImageTransportSurface implementation: |
| 152 virtual void OnNewSurfaceACK( | 152 virtual void OnNewSurfaceACK( |
| 153 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 153 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
| 154 virtual void OnBuffersSwappedACK() OVERRIDE; | 154 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 155 virtual void OnPostSubBufferACK() OVERRIDE; | 155 virtual void OnPostSubBufferACK() OVERRIDE; |
| 156 virtual void OnResizeViewACK() OVERRIDE; | 156 virtual void OnResizeViewACK() OVERRIDE; |
| 157 virtual void OnResize(gfx::Size size) OVERRIDE; | 157 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 virtual ~GLXImageTransportSurface(); | 160 virtual ~GLXImageTransportSurface(); |
| 161 | 161 |
| 162 // Tell the browser to release the surface. | 162 // Tell the browser to release the surface. |
| 163 void ReleaseSurface(); | 163 void ReleaseSurface(); |
| 164 | 164 |
| 165 void SendBuffersSwapped(); | 165 void SendBuffersSwapped(); |
| 166 void SendPostSubBuffer(int x, int y, int width, int height); | 166 void SendPostSubBuffer(int x, int y, int width, int height); |
| 167 | 167 |
| 168 void ResizeSurface(gfx::Size size); | 168 void ResizeSurface(gfx::Size size); |
| 169 | 169 |
| 170 // Tracks the current surface visibility state. | 170 // Tracks the current buffer allocation state. |
| 171 VisibilityState visibility_state_; | 171 BufferAllocationState buffer_allocation_state_; |
| 172 | 172 |
| 173 XID dummy_parent_; | 173 XID dummy_parent_; |
| 174 gfx::Size size_; | 174 gfx::Size size_; |
| 175 | 175 |
| 176 // Whether or not the image has been bound on the browser side. | 176 // Whether or not the image has been bound on the browser side. |
| 177 bool bound_; | 177 bool bound_; |
| 178 | 178 |
| 179 // Whether or not we need to send a resize on the next swap. | 179 // Whether or not we need to send a resize on the next swap. |
| 180 bool needs_resize_; | 180 bool needs_resize_; |
| 181 | 181 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 EGLAcceleratedSurface::~EGLAcceleratedSurface() { | 263 EGLAcceleratedSurface::~EGLAcceleratedSurface() { |
| 264 glDeleteTextures(1, &texture_); | 264 glDeleteTextures(1, &texture_); |
| 265 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); | 265 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); |
| 266 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); | 266 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); |
| 267 } | 267 } |
| 268 | 268 |
| 269 EGLImageTransportSurface::EGLImageTransportSurface( | 269 EGLImageTransportSurface::EGLImageTransportSurface( |
| 270 GpuChannelManager* manager, | 270 GpuChannelManager* manager, |
| 271 GpuCommandBufferStub* stub) | 271 GpuCommandBufferStub* stub) |
| 272 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), | 272 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), |
| 273 visibility_state_(VISIBILITY_STATE_FOREGROUND), | 273 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), |
| 274 fbo_id_(0), | 274 fbo_id_(0), |
| 275 made_current_(false) { | 275 made_current_(false) { |
| 276 helper_.reset(new ImageTransportHelper(this, | 276 helper_.reset(new ImageTransportHelper(this, |
| 277 manager, | 277 manager, |
| 278 stub, | 278 stub, |
| 279 gfx::kNullPluginWindow)); | 279 gfx::kNullPluginWindow)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 EGLImageTransportSurface::~EGLImageTransportSurface() { | 282 EGLImageTransportSurface::~EGLImageTransportSurface() { |
| 283 Destroy(); | 283 Destroy(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 326 } |
| 327 | 327 |
| 328 made_current_ = true; | 328 made_current_ = true; |
| 329 return true; | 329 return true; |
| 330 } | 330 } |
| 331 | 331 |
| 332 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { | 332 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { |
| 333 return fbo_id_; | 333 return fbo_id_; |
| 334 } | 334 } |
| 335 | 335 |
| 336 void EGLImageTransportSurface::SetVisibility(VisibilityState visibility_state) { | 336 void EGLImageTransportSurface::SetBufferAllocation( |
| 337 if (visibility_state_ == visibility_state) | 337 BufferAllocationState state) { |
| 338 if (buffer_allocation_state_ == state) |
| 338 return; | 339 return; |
| 339 visibility_state_ = visibility_state; | 340 buffer_allocation_state_ = state; |
| 340 | 341 |
| 341 switch (visibility_state) { | 342 switch (state) { |
| 342 case VISIBILITY_STATE_FOREGROUND: | 343 case BUFFER_ALLOCATION_FRONT_AND_BACK: |
| 343 if (!back_surface_.get() && front_surface_.get()) | 344 if (!back_surface_.get() && front_surface_.get()) |
| 344 OnResize(front_surface_->size()); | 345 OnResize(front_surface_->size()); |
| 345 break; | 346 break; |
| 346 | 347 |
| 347 case VISIBILITY_STATE_BACKGROUND: | 348 case BUFFER_ALLOCATION_FRONT_ONLY: |
| 348 if (back_surface_.get() && front_surface_.get()) | 349 if (back_surface_.get() && front_surface_.get()) |
| 349 ReleaseSurface(&back_surface_); | 350 ReleaseSurface(&back_surface_); |
| 350 break; | 351 break; |
| 351 | 352 |
| 352 case VISIBILITY_STATE_HIBERNATED: | 353 case BUFFER_ALLOCATION_NONE: |
| 353 if (back_surface_.get() && front_surface_.get()) | 354 if (back_surface_.get() && front_surface_.get()) |
| 354 ReleaseSurface(&back_surface_); | 355 ReleaseSurface(&back_surface_); |
| 355 break; | 356 break; |
| 356 | 357 |
| 357 default: | 358 default: |
| 358 NOTREACHED(); | 359 NOTREACHED(); |
| 359 } | 360 } |
| 360 } | 361 } |
| 361 | 362 |
| 362 void EGLImageTransportSurface::ReleaseSurface( | 363 void EGLImageTransportSurface::ReleaseSurface( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } | 512 } |
| 512 | 513 |
| 513 void EGLImageTransportSurface::OnResizeViewACK() { | 514 void EGLImageTransportSurface::OnResizeViewACK() { |
| 514 NOTREACHED(); | 515 NOTREACHED(); |
| 515 } | 516 } |
| 516 | 517 |
| 517 GLXImageTransportSurface::GLXImageTransportSurface( | 518 GLXImageTransportSurface::GLXImageTransportSurface( |
| 518 GpuChannelManager* manager, | 519 GpuChannelManager* manager, |
| 519 GpuCommandBufferStub* stub) | 520 GpuCommandBufferStub* stub) |
| 520 : gfx::NativeViewGLSurfaceGLX(), | 521 : gfx::NativeViewGLSurfaceGLX(), |
| 521 visibility_state_(VISIBILITY_STATE_FOREGROUND), | 522 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), |
| 522 dummy_parent_(0), | 523 dummy_parent_(0), |
| 523 size_(1, 1), | 524 size_(1, 1), |
| 524 bound_(false), | 525 bound_(false), |
| 525 needs_resize_(false), | 526 needs_resize_(false), |
| 526 made_current_(false) { | 527 made_current_(false) { |
| 527 helper_.reset(new ImageTransportHelper(this, | 528 helper_.reset(new ImageTransportHelper(this, |
| 528 manager, | 529 manager, |
| 529 stub, | 530 stub, |
| 530 gfx::kNullPluginWindow)); | 531 gfx::kNullPluginWindow)); |
| 531 } | 532 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 } | 596 } |
| 596 | 597 |
| 597 void GLXImageTransportSurface::ReleaseSurface() { | 598 void GLXImageTransportSurface::ReleaseSurface() { |
| 598 DCHECK(bound_); | 599 DCHECK(bound_); |
| 599 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 600 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| 600 params.identifier = window_; | 601 params.identifier = window_; |
| 601 helper_->SendAcceleratedSurfaceRelease(params); | 602 helper_->SendAcceleratedSurfaceRelease(params); |
| 602 bound_ = false; | 603 bound_ = false; |
| 603 } | 604 } |
| 604 | 605 |
| 605 void GLXImageTransportSurface::SetVisibility(VisibilityState visibility_state) { | 606 void GLXImageTransportSurface::SetBufferAllocation( |
| 606 if (visibility_state_ == visibility_state) | 607 BufferAllocationState state) { |
| 608 if (buffer_allocation_state_ == state) |
| 607 return; | 609 return; |
| 608 visibility_state_ = visibility_state; | 610 buffer_allocation_state_ = state; |
| 609 | 611 |
| 610 switch (visibility_state) { | 612 switch (state) { |
| 611 case VISIBILITY_STATE_FOREGROUND: { | 613 case BUFFER_ALLOCATION_FRONT_AND_BACK: { |
| 612 ResizeSurface(size_); | 614 ResizeSurface(size_); |
| 613 break; | 615 break; |
| 614 } | 616 } |
| 615 case VISIBILITY_STATE_BACKGROUND: { | 617 case BUFFER_ALLOCATION_FRONT_ONLY: { |
| 616 ResizeSurface(gfx::Size(1,1)); | 618 ResizeSurface(gfx::Size(1,1)); |
| 617 break; | 619 break; |
| 618 } | 620 } |
| 619 case VISIBILITY_STATE_HIBERNATED: { | 621 case BUFFER_ALLOCATION_NONE: { |
| 620 ResizeSurface(gfx::Size(1,1)); | 622 ResizeSurface(gfx::Size(1,1)); |
| 621 if (bound_) | 623 if (bound_) |
| 622 ReleaseSurface(); | 624 ReleaseSurface(); |
| 623 break; | 625 break; |
| 624 } | 626 } |
| 625 default: | 627 default: |
| 626 NOTREACHED(); | 628 NOTREACHED(); |
| 627 } | 629 } |
| 628 } | 630 } |
| 629 | 631 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 stub, | 931 stub, |
| 930 surface.get(), | 932 surface.get(), |
| 931 handle.transport); | 933 handle.transport); |
| 932 } | 934 } |
| 933 | 935 |
| 934 if (surface->Initialize()) | 936 if (surface->Initialize()) |
| 935 return surface; | 937 return surface; |
| 936 else | 938 else |
| 937 return NULL; | 939 return NULL; |
| 938 } | 940 } |
| OLD | NEW |