| 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/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // GLSurface implementation | 30 // GLSurface implementation |
| 31 virtual bool Initialize() OVERRIDE; | 31 virtual bool Initialize() OVERRIDE; |
| 32 virtual void Destroy() OVERRIDE; | 32 virtual void Destroy() OVERRIDE; |
| 33 virtual bool IsOffscreen() OVERRIDE; | 33 virtual bool IsOffscreen() OVERRIDE; |
| 34 virtual bool SwapBuffers() OVERRIDE; | 34 virtual bool SwapBuffers() OVERRIDE; |
| 35 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 35 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 36 virtual std::string GetExtensions() OVERRIDE; | 36 virtual std::string GetExtensions() OVERRIDE; |
| 37 virtual gfx::Size GetSize() OVERRIDE; | 37 virtual gfx::Size GetSize() OVERRIDE; |
| 38 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 38 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 39 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 39 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
| 40 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 40 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 41 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
| 41 | 42 |
| 42 protected: | 43 protected: |
| 43 // ImageTransportSurface implementation | 44 // ImageTransportSurface implementation |
| 44 virtual void OnNewSurfaceACK(uint64 surface_handle, | 45 virtual void OnNewSurfaceACK(uint64 surface_handle, |
| 45 TransportDIB::Handle shm_handle) OVERRIDE; | 46 TransportDIB::Handle shm_handle) OVERRIDE; |
| 46 virtual void OnBuffersSwappedACK() OVERRIDE; | 47 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 47 virtual void OnPostSubBufferACK() OVERRIDE; | 48 virtual void OnPostSubBufferACK() OVERRIDE; |
| 48 virtual void OnResizeViewACK() OVERRIDE; | 49 virtual void OnResizeViewACK() OVERRIDE; |
| 49 virtual void OnResize(gfx::Size size) OVERRIDE; | 50 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 virtual ~IOSurfaceImageTransportSurface() OVERRIDE; | 53 virtual ~IOSurfaceImageTransportSurface() OVERRIDE; |
| 53 | 54 |
| 54 void UnrefIOSurface(); | 55 void UnrefIOSurface(); |
| 55 void CreateIOSurface(); | 56 void CreateIOSurface(); |
| 56 | 57 |
| 57 BufferAllocationState buffer_allocation_state_; | 58 // Tracks the current buffer allocation state. |
| 59 bool backbuffer_suggested_allocation_; |
| 60 bool frontbuffer_suggested_allocation_; |
| 58 | 61 |
| 59 uint32 fbo_id_; | 62 uint32 fbo_id_; |
| 60 GLuint texture_id_; | 63 GLuint texture_id_; |
| 61 | 64 |
| 62 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; | 65 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; |
| 63 | 66 |
| 64 // The id of |io_surface_| or 0 if that's NULL. | 67 // The id of |io_surface_| or 0 if that's NULL. |
| 65 uint64 io_surface_handle_; | 68 uint64 io_surface_handle_; |
| 66 | 69 |
| 67 // Weak pointer to the context that this was last made current to. | 70 // Weak pointer to the context that this was last made current to. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 90 base::mac::ScopedCFTypeRef<CFNumberRef> number( | 93 base::mac::ScopedCFTypeRef<CFNumberRef> number( |
| 91 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 94 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
| 92 CFDictionaryAddValue(dictionary, key, number.get()); | 95 CFDictionaryAddValue(dictionary, key, number.get()); |
| 93 } | 96 } |
| 94 | 97 |
| 95 IOSurfaceImageTransportSurface::IOSurfaceImageTransportSurface( | 98 IOSurfaceImageTransportSurface::IOSurfaceImageTransportSurface( |
| 96 GpuChannelManager* manager, | 99 GpuChannelManager* manager, |
| 97 GpuCommandBufferStub* stub, | 100 GpuCommandBufferStub* stub, |
| 98 gfx::PluginWindowHandle handle) | 101 gfx::PluginWindowHandle handle) |
| 99 : gfx::NoOpGLSurfaceCGL(gfx::Size(1, 1)), | 102 : gfx::NoOpGLSurfaceCGL(gfx::Size(1, 1)), |
| 100 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 103 backbuffer_suggested_allocation_(true), |
| 104 frontbuffer_suggested_allocation_(true), |
| 101 fbo_id_(0), | 105 fbo_id_(0), |
| 102 texture_id_(0), | 106 texture_id_(0), |
| 103 io_surface_handle_(0), | 107 io_surface_handle_(0), |
| 104 context_(NULL), | 108 context_(NULL), |
| 105 made_current_(false) { | 109 made_current_(false) { |
| 106 helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); | 110 helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); |
| 107 } | 111 } |
| 108 | 112 |
| 109 IOSurfaceImageTransportSurface::~IOSurfaceImageTransportSurface() { | 113 IOSurfaceImageTransportSurface::~IOSurfaceImageTransportSurface() { |
| 110 Destroy(); | 114 Destroy(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 OnResize(gfx::Size(1, 1)); | 155 OnResize(gfx::Size(1, 1)); |
| 152 | 156 |
| 153 made_current_ = true; | 157 made_current_ = true; |
| 154 return true; | 158 return true; |
| 155 } | 159 } |
| 156 | 160 |
| 157 unsigned int IOSurfaceImageTransportSurface::GetBackingFrameBufferObject() { | 161 unsigned int IOSurfaceImageTransportSurface::GetBackingFrameBufferObject() { |
| 158 return fbo_id_; | 162 return fbo_id_; |
| 159 } | 163 } |
| 160 | 164 |
| 161 void IOSurfaceImageTransportSurface::SetBufferAllocation( | 165 void IOSurfaceImageTransportSurface::SetBackbufferAllocation(bool allocation) { |
| 162 BufferAllocationState state) { | 166 if (backbuffer_suggested_allocation_ == allocation) |
| 163 if (buffer_allocation_state_ == state) | |
| 164 return; | 167 return; |
| 165 buffer_allocation_state_ = state; | 168 backbuffer_suggested_allocation_ = allocation; |
| 166 | 169 |
| 167 switch (state) { | 170 if (backbuffer_suggested_allocation_) |
| 168 case BUFFER_ALLOCATION_FRONT_AND_BACK: | 171 CreateIOSurface(); |
| 169 CreateIOSurface(); | 172 else |
| 170 break; | 173 UnrefIOSurface(); |
| 174 } |
| 171 | 175 |
| 172 case BUFFER_ALLOCATION_FRONT_ONLY: | 176 void IOSurfaceImageTransportSurface::SetFrontbufferAllocation(bool allocation) { |
| 173 break; | 177 if (frontbuffer_suggested_allocation_ == allocation) |
| 178 return; |
| 179 frontbuffer_suggested_allocation_ = allocation; |
| 174 | 180 |
| 175 case BUFFER_ALLOCATION_NONE: | 181 // We recreate frontbuffer by recreating backbuffer and swapping. |
| 176 UnrefIOSurface(); | 182 // But we release frontbuffer by telling UI to release its handle on it. |
| 177 helper_->Suspend(); | 183 if (!frontbuffer_suggested_allocation_) |
| 178 break; | 184 helper_->Suspend(); |
| 179 | |
| 180 default: | |
| 181 NOTREACHED(); | |
| 182 } | |
| 183 } | 185 } |
| 184 | 186 |
| 185 bool IOSurfaceImageTransportSurface::SwapBuffers() { | 187 bool IOSurfaceImageTransportSurface::SwapBuffers() { |
| 188 DCHECK(backbuffer_suggested_allocation_); |
| 189 if (!frontbuffer_suggested_allocation_) |
| 190 return true; |
| 186 glFlush(); | 191 glFlush(); |
| 187 | 192 |
| 188 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 193 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 189 params.surface_handle = io_surface_handle_; | 194 params.surface_handle = io_surface_handle_; |
| 190 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 195 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 191 | 196 |
| 192 helper_->SetScheduled(false); | 197 helper_->SetScheduled(false); |
| 193 return true; | 198 return true; |
| 194 } | 199 } |
| 195 | 200 |
| 196 bool IOSurfaceImageTransportSurface::PostSubBuffer( | 201 bool IOSurfaceImageTransportSurface::PostSubBuffer( |
| 197 int x, int y, int width, int height) { | 202 int x, int y, int width, int height) { |
| 203 DCHECK(backbuffer_suggested_allocation_); |
| 204 if (!frontbuffer_suggested_allocation_) |
| 205 return true; |
| 198 glFlush(); | 206 glFlush(); |
| 199 | 207 |
| 200 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; | 208 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; |
| 201 params.surface_handle = io_surface_handle_; | 209 params.surface_handle = io_surface_handle_; |
| 202 params.x = x; | 210 params.x = x; |
| 203 params.y = y; | 211 params.y = y; |
| 204 params.width = width; | 212 params.width = width; |
| 205 params.height = height; | 213 params.height = height; |
| 206 helper_->SendAcceleratedSurfacePostSubBuffer(params); | 214 helper_->SendAcceleratedSurfacePostSubBuffer(params); |
| 207 | 215 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 NOTREACHED(); | 374 NOTREACHED(); |
| 367 return NULL; | 375 return NULL; |
| 368 } | 376 } |
| 369 if (surface->Initialize()) | 377 if (surface->Initialize()) |
| 370 return surface; | 378 return surface; |
| 371 else | 379 else |
| 372 return NULL; | 380 return NULL; |
| 373 } | 381 } |
| 374 | 382 |
| 375 #endif // defined(USE_GPU) | 383 #endif // defined(USE_GPU) |
| OLD | NEW |