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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
| 6 | 6 |
| 7 #include "content/common/gpu/image_transport_surface.h" | 7 #include "content/common/gpu/image_transport_surface.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 PbufferImageTransportSurface(GpuChannelManager* manager, | 33 PbufferImageTransportSurface(GpuChannelManager* manager, |
| 34 GpuCommandBufferStub* stub); | 34 GpuCommandBufferStub* stub); |
| 35 | 35 |
| 36 // gfx::GLSurface implementation | 36 // gfx::GLSurface implementation |
| 37 virtual bool Initialize() OVERRIDE; | 37 virtual bool Initialize() OVERRIDE; |
| 38 virtual void Destroy() OVERRIDE; | 38 virtual void Destroy() OVERRIDE; |
| 39 virtual bool IsOffscreen() OVERRIDE; | 39 virtual bool IsOffscreen() OVERRIDE; |
| 40 virtual bool SwapBuffers() OVERRIDE; | 40 virtual bool SwapBuffers() OVERRIDE; |
| 41 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 41 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 42 virtual std::string GetExtensions() OVERRIDE; | 42 virtual std::string GetExtensions() OVERRIDE; |
| 43 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 43 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 44 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; | |
| 44 | 45 |
| 45 protected: | 46 protected: |
| 46 // ImageTransportSurface implementation | 47 // ImageTransportSurface implementation |
| 47 virtual void OnNewSurfaceACK(uint64 surface_handle, | 48 virtual void OnNewSurfaceACK(uint64 surface_handle, |
| 48 TransportDIB::Handle shm_handle) OVERRIDE; | 49 TransportDIB::Handle shm_handle) OVERRIDE; |
| 49 virtual void OnBuffersSwappedACK() OVERRIDE; | 50 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 50 virtual void OnPostSubBufferACK() OVERRIDE; | 51 virtual void OnPostSubBufferACK() OVERRIDE; |
| 51 virtual void OnResizeViewACK() OVERRIDE; | 52 virtual void OnResizeViewACK() OVERRIDE; |
| 52 virtual void OnResize(gfx::Size size) OVERRIDE; | 53 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 virtual ~PbufferImageTransportSurface(); | 56 virtual ~PbufferImageTransportSurface(); |
| 56 void SendBuffersSwapped(); | 57 void SendBuffersSwapped(); |
| 57 void DestroySurface(); | 58 void DestroySurface(); |
| 59 void AdjustBufferAllocations(); | |
| 58 | 60 |
| 59 // Tracks the current buffer allocation state. | 61 // Tracks the current buffer allocation state. |
| 60 BufferAllocationState buffer_allocation_state_; | 62 bool backbuffer_suggested_allocation_; |
| 63 bool frontbuffer_suggested_allocation_; | |
| 61 | 64 |
| 62 // Size to resize to when the surface becomes visible. | 65 // Size to resize to when the surface becomes visible. |
| 63 gfx::Size visible_size_; | 66 gfx::Size visible_size_; |
| 64 | 67 |
| 65 scoped_ptr<ImageTransportHelper> helper_; | 68 scoped_ptr<ImageTransportHelper> helper_; |
| 66 | 69 |
| 67 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); | 70 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); |
| 68 }; | 71 }; |
| 69 | 72 |
| 70 PbufferImageTransportSurface::PbufferImageTransportSurface( | 73 PbufferImageTransportSurface::PbufferImageTransportSurface( |
| 71 GpuChannelManager* manager, | 74 GpuChannelManager* manager, |
| 72 GpuCommandBufferStub* stub) | 75 GpuCommandBufferStub* stub) |
| 73 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1))), | 76 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1))), |
| 74 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK) { | 77 backbuffer_suggested_allocation_(true), |
| 78 frontbuffer_suggested_allocation_(true) { | |
| 75 helper_.reset(new ImageTransportHelper(this, | 79 helper_.reset(new ImageTransportHelper(this, |
| 76 manager, | 80 manager, |
| 77 stub, | 81 stub, |
| 78 gfx::kNullPluginWindow)); | 82 gfx::kNullPluginWindow)); |
| 79 } | 83 } |
| 80 | 84 |
| 81 PbufferImageTransportSurface::~PbufferImageTransportSurface() { | 85 PbufferImageTransportSurface::~PbufferImageTransportSurface() { |
| 82 Destroy(); | 86 Destroy(); |
| 83 } | 87 } |
| 84 | 88 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 115 | 119 |
| 116 return true; | 120 return true; |
| 117 } | 121 } |
| 118 | 122 |
| 119 bool PbufferImageTransportSurface::PostSubBuffer( | 123 bool PbufferImageTransportSurface::PostSubBuffer( |
| 120 int x, int y, int width, int height) { | 124 int x, int y, int width, int height) { |
| 121 NOTREACHED(); | 125 NOTREACHED(); |
| 122 return false; | 126 return false; |
| 123 } | 127 } |
| 124 | 128 |
| 125 void PbufferImageTransportSurface::SetBufferAllocation( | 129 void PbufferImageTransportSurface::SetBackbufferAllocation(bool allocation) { |
| 126 BufferAllocationState state) { | 130 if (backbuffer_suggested_allocation_ == allocation) |
| 127 if (buffer_allocation_state_ == state) | |
| 128 return; | 131 return; |
| 129 buffer_allocation_state_ = state; | 132 backbuffer_suggested_allocation_ = allocation; |
| 133 AdjustBufferAllocations(); | |
| 134 } | |
| 130 | 135 |
| 131 switch (state) { | 136 void PbufferImageTransportSurface::SetFrontbufferAllocation(bool allocation) { |
| 132 case BUFFER_ALLOCATION_FRONT_AND_BACK: | 137 if (frontbuffer_suggested_allocation_ == allocation) |
| 133 Resize(visible_size_); | 138 return; |
| 134 break; | 139 frontbuffer_suggested_allocation_ = allocation; |
| 140 AdjustBufferAllocations(); | |
| 141 } | |
| 135 | 142 |
| 136 case BUFFER_ALLOCATION_FRONT_ONLY: | 143 void PbufferImageTransportSurface::AdjustBufferAllocations() { |
| 137 Resize(gfx::Size(1, 1)); | 144 if (backbuffer_suggested_allocation_) { |
| 138 break; | 145 Resize(visible_size_); |
|
jonathan.backer
2012/05/09 18:13:01
DCHECK that we should have a front buffer?
mmocny
2012/05/09 18:59:15
Again, I don't think so.
Previously we would set B
| |
| 139 | 146 } else { |
| 140 case BUFFER_ALLOCATION_NONE: | 147 Resize(gfx::Size(1, 1)); |
| 141 Resize(gfx::Size(1, 1)); | 148 if (!frontbuffer_suggested_allocation_) |
| 142 helper_->Suspend(); | 149 helper_->Suspend(); |
| 143 break; | |
| 144 | |
| 145 default: | |
| 146 NOTREACHED(); | |
| 147 } | 150 } |
| 148 DestroySurface(); | 151 DestroySurface(); |
| 149 } | 152 } |
| 150 | 153 |
| 151 void PbufferImageTransportSurface::DestroySurface() { | 154 void PbufferImageTransportSurface::DestroySurface() { |
| 152 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 155 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| 153 helper_->SendAcceleratedSurfaceRelease(params); | 156 helper_->SendAcceleratedSurfaceRelease(params); |
| 154 } | 157 } |
| 155 | 158 |
| 156 std::string PbufferImageTransportSurface::GetExtensions() { | 159 std::string PbufferImageTransportSurface::GetExtensions() { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 181 uint64 surface_handle, | 184 uint64 surface_handle, |
| 182 TransportDIB::Handle shm_handle) { | 185 TransportDIB::Handle shm_handle) { |
| 183 NOTREACHED(); | 186 NOTREACHED(); |
| 184 } | 187 } |
| 185 | 188 |
| 186 void PbufferImageTransportSurface::OnResizeViewACK() { | 189 void PbufferImageTransportSurface::OnResizeViewACK() { |
| 187 NOTREACHED(); | 190 NOTREACHED(); |
| 188 } | 191 } |
| 189 | 192 |
| 190 void PbufferImageTransportSurface::OnResize(gfx::Size size) { | 193 void PbufferImageTransportSurface::OnResize(gfx::Size size) { |
| 191 if (buffer_allocation_state_ == BUFFER_ALLOCATION_FRONT_AND_BACK) | 194 if (backbuffer_suggested_allocation_ && frontbuffer_suggested_allocation_) |
|
jonathan.backer
2012/05/09 18:13:01
I think that it may make more sense to DCHECK that
mmocny
2012/05/09 18:59:15
Fair enough. Shouldn't we DCHECK for both?
Will w
jonathan.backer
2012/05/10 21:37:48
AFAIK, we shouldn't resize when not visible. I thi
| |
| 192 Resize(size); | 195 Resize(size); |
| 193 | 196 |
| 194 DestroySurface(); | 197 DestroySurface(); |
| 195 | 198 |
| 196 visible_size_ = size; | 199 visible_size_ = size; |
| 197 } | 200 } |
| 198 | 201 |
| 199 } // namespace anonymous | 202 } // namespace anonymous |
| 200 | 203 |
| 201 // static | 204 // static |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 228 handle.transport); | 231 handle.transport); |
| 229 } | 232 } |
| 230 | 233 |
| 231 if (surface->Initialize()) | 234 if (surface->Initialize()) |
| 232 return surface; | 235 return surface; |
| 233 else | 236 else |
| 234 return NULL; | 237 return NULL; |
| 235 } | 238 } |
| 236 | 239 |
| 237 #endif // ENABLE_GPU | 240 #endif // ENABLE_GPU |
| OLD | NEW |