Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_fbo_mac.h" | 5 #include "content/common/gpu/image_transport_surface_fbo_mac.h" |
| 6 | 6 |
| 7 #include "content/common/gpu/gpu_messages.h" | 7 #include "content/common/gpu/gpu_messages.h" |
| 8 #include "content/common/gpu/image_transport_surface_calayer_mac.h" | 8 #include "content/common/gpu/image_transport_surface_calayer_mac.h" |
| 9 #include "content/common/gpu/image_transport_surface_iosurface_mac.h" | 9 #include "content/common/gpu/image_transport_surface_iosurface_mac.h" |
| 10 #include "ui/base/cocoa/remote_layer_api.h" | 10 #include "ui/base/cocoa/remote_layer_api.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 gfx::PluginWindowHandle handle) | 21 gfx::PluginWindowHandle handle) |
| 22 : backbuffer_suggested_allocation_(true), | 22 : backbuffer_suggested_allocation_(true), |
| 23 frontbuffer_suggested_allocation_(true), | 23 frontbuffer_suggested_allocation_(true), |
| 24 fbo_id_(0), | 24 fbo_id_(0), |
| 25 texture_id_(0), | 25 texture_id_(0), |
| 26 depth_stencil_renderbuffer_id_(0), | 26 depth_stencil_renderbuffer_id_(0), |
| 27 has_complete_framebuffer_(false), | 27 has_complete_framebuffer_(false), |
| 28 context_(NULL), | 28 context_(NULL), |
| 29 scale_factor_(1.f), | 29 scale_factor_(1.f), |
| 30 made_current_(false), | 30 made_current_(false), |
| 31 is_swap_buffers_pending_(false), | 31 is_swap_buffers_send_pending_(false) { |
| 32 did_unschedule_(false) { | |
| 33 if (ui::RemoteLayerAPISupported()) | 32 if (ui::RemoteLayerAPISupported()) |
| 34 storage_provider_.reset(new CALayerStorageProvider(this)); | 33 storage_provider_.reset(new CALayerStorageProvider(this)); |
| 35 else | 34 else |
| 36 storage_provider_.reset(new IOSurfaceStorageProvider(this)); | 35 storage_provider_.reset(new IOSurfaceStorageProvider(this)); |
| 37 helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); | 36 helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); |
| 38 } | 37 } |
| 39 | 38 |
| 40 ImageTransportSurfaceFBO::~ImageTransportSurfaceFBO() { | 39 ImageTransportSurfaceFBO::~ImageTransportSurfaceFBO() { |
| 41 } | 40 } |
| 42 | 41 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 55 return true; | 54 return true; |
| 56 } | 55 } |
| 57 | 56 |
| 58 void ImageTransportSurfaceFBO::Destroy() { | 57 void ImageTransportSurfaceFBO::Destroy() { |
| 59 DestroyFramebuffer(); | 58 DestroyFramebuffer(); |
| 60 | 59 |
| 61 helper_->Destroy(); | 60 helper_->Destroy(); |
| 62 } | 61 } |
| 63 | 62 |
| 64 bool ImageTransportSurfaceFBO::DeferDraws() { | 63 bool ImageTransportSurfaceFBO::DeferDraws() { |
| 65 // The command buffer hit a draw/clear command that could clobber the | 64 storage_provider_->WillWriteToBackbuffer(); |
| 66 // IOSurface in use by an earlier SwapBuffers. If a Swap is pending, abort | 65 // We should not have a pending send when we are drawing the next frame. |
| 67 // processing of the command by returning true and unschedule until the Swap | 66 DCHECK(!is_swap_buffers_send_pending_); |
|
piman
2014/08/27 22:13:05
Is that DCHECK also invalid while the TODO in CALa
ccameron
2014/08/27 22:46:08
This is still valid.
At the moment it is valid, b
| |
| 68 // Ack arrives. | |
| 69 if(did_unschedule_) | |
| 70 return true; // Still unscheduled, so just return true. | |
| 71 if (is_swap_buffers_pending_) { | |
| 72 did_unschedule_ = true; | |
| 73 helper_->SetScheduled(false); | |
| 74 return true; | |
| 75 } | |
| 76 return false; | 67 return false; |
| 77 } | 68 } |
| 78 | 69 |
| 79 bool ImageTransportSurfaceFBO::IsOffscreen() { | 70 bool ImageTransportSurfaceFBO::IsOffscreen() { |
| 80 return false; | 71 return false; |
| 81 } | 72 } |
| 82 | 73 |
| 83 bool ImageTransportSurfaceFBO::OnMakeCurrent(gfx::GLContext* context) { | 74 bool ImageTransportSurfaceFBO::OnMakeCurrent(gfx::GLContext* context) { |
| 84 context_ = context; | 75 context_ = context; |
| 85 | 76 |
| 86 if (made_current_) | 77 if (made_current_) |
| 87 return true; | 78 return true; |
| 88 | 79 |
| 89 OnResize(gfx::Size(1, 1), 1.f); | 80 OnResize(gfx::Size(1, 1), 1.f); |
| 90 | 81 |
| 91 made_current_ = true; | 82 made_current_ = true; |
| 92 return true; | 83 return true; |
| 93 } | 84 } |
| 94 | 85 |
| 95 unsigned int ImageTransportSurfaceFBO::GetBackingFrameBufferObject() { | 86 unsigned int ImageTransportSurfaceFBO::GetBackingFrameBufferObject() { |
| 96 return fbo_id_; | 87 return fbo_id_; |
| 97 } | 88 } |
| 98 | 89 |
| 99 bool ImageTransportSurfaceFBO::SetBackbufferAllocation(bool allocation) { | 90 bool ImageTransportSurfaceFBO::SetBackbufferAllocation(bool allocation) { |
| 100 if (backbuffer_suggested_allocation_ == allocation) | 91 if (backbuffer_suggested_allocation_ == allocation) |
| 101 return true; | 92 return true; |
| 102 backbuffer_suggested_allocation_ = allocation; | 93 backbuffer_suggested_allocation_ = allocation; |
| 103 AdjustBufferAllocation(); | 94 AdjustBufferAllocation(); |
| 95 if (!allocation) | |
| 96 storage_provider_->DiscardBackbuffer(); | |
| 104 return true; | 97 return true; |
| 105 } | 98 } |
| 106 | 99 |
| 107 void ImageTransportSurfaceFBO::SetFrontbufferAllocation(bool allocation) { | 100 void ImageTransportSurfaceFBO::SetFrontbufferAllocation(bool allocation) { |
| 108 if (frontbuffer_suggested_allocation_ == allocation) | 101 if (frontbuffer_suggested_allocation_ == allocation) |
| 109 return; | 102 return; |
| 110 frontbuffer_suggested_allocation_ = allocation; | 103 frontbuffer_suggested_allocation_ = allocation; |
| 111 AdjustBufferAllocation(); | 104 AdjustBufferAllocation(); |
| 112 } | 105 } |
| 113 | 106 |
| 114 void ImageTransportSurfaceFBO::AdjustBufferAllocation() { | 107 void ImageTransportSurfaceFBO::AdjustBufferAllocation() { |
| 115 // On mac, the frontbuffer and backbuffer are the same buffer. The buffer is | 108 // On mac, the frontbuffer and backbuffer are the same buffer. The buffer is |
| 116 // free'd when both the browser and gpu processes have Unref'd the IOSurface. | 109 // free'd when both the browser and gpu processes have Unref'd the IOSurface. |
| 117 if (!backbuffer_suggested_allocation_ && | 110 if (!backbuffer_suggested_allocation_ && |
| 118 !frontbuffer_suggested_allocation_ && | 111 !frontbuffer_suggested_allocation_ && |
| 119 has_complete_framebuffer_) { | 112 has_complete_framebuffer_) { |
| 120 DestroyFramebuffer(); | 113 DestroyFramebuffer(); |
| 121 helper_->Suspend(); | 114 helper_->Suspend(); |
| 122 } else if (backbuffer_suggested_allocation_ && !has_complete_framebuffer_) { | 115 } else if (backbuffer_suggested_allocation_ && !has_complete_framebuffer_) { |
| 123 CreateFramebuffer(); | 116 CreateFramebuffer(); |
| 124 } | 117 } |
| 125 } | 118 } |
| 126 | 119 |
| 127 bool ImageTransportSurfaceFBO::SwapBuffers() { | 120 bool ImageTransportSurfaceFBO::SwapBuffers() { |
| 128 DCHECK(backbuffer_suggested_allocation_); | 121 DCHECK(backbuffer_suggested_allocation_); |
| 129 if (!frontbuffer_suggested_allocation_) | 122 if (!frontbuffer_suggested_allocation_) |
| 130 return true; | 123 return true; |
| 131 glFlush(); | 124 glFlush(); |
| 132 | 125 |
| 133 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 126 // It is the responsibility of the storage provider to send the swap IPC. |
| 134 params.surface_handle = storage_provider_->GetSurfaceHandle(); | 127 is_swap_buffers_send_pending_ = true; |
| 135 params.size = GetSize(); | 128 storage_provider_->SwapBuffers(size_, scale_factor_); |
| 136 params.scale_factor = scale_factor_; | |
| 137 params.latency_info.swap(latency_info_); | |
| 138 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
| 139 | |
| 140 DCHECK(!is_swap_buffers_pending_); | |
| 141 is_swap_buffers_pending_ = true; | |
| 142 | |
| 143 storage_provider_->WillSwapBuffers(); | |
| 144 return true; | 129 return true; |
| 145 } | 130 } |
| 146 | 131 |
| 132 void ImageTransportSurfaceFBO::SendSwapBuffers(uint64 surface_handle, | |
| 133 const gfx::Size pixel_size, | |
| 134 float scale_factor) { | |
| 135 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
| 136 params.surface_handle = surface_handle; | |
| 137 params.size = pixel_size; | |
| 138 params.scale_factor = scale_factor; | |
| 139 params.latency_info.swap(latency_info_); | |
| 140 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
| 141 is_swap_buffers_send_pending_ = false; | |
| 142 } | |
| 143 | |
| 147 bool ImageTransportSurfaceFBO::PostSubBuffer( | 144 bool ImageTransportSurfaceFBO::PostSubBuffer( |
| 148 int x, int y, int width, int height) { | 145 int x, int y, int width, int height) { |
| 149 // Mac does not support sub-buffer swaps. | 146 // Mac does not support sub-buffer swaps. |
| 150 NOTREACHED(); | 147 NOTREACHED(); |
| 151 return false; | 148 return false; |
| 152 } | 149 } |
| 153 | 150 |
| 154 bool ImageTransportSurfaceFBO::SupportsPostSubBuffer() { | 151 bool ImageTransportSurfaceFBO::SupportsPostSubBuffer() { |
| 155 return true; | 152 return true; |
| 156 } | 153 } |
| 157 | 154 |
| 158 gfx::Size ImageTransportSurfaceFBO::GetSize() { | 155 gfx::Size ImageTransportSurfaceFBO::GetSize() { |
| 159 return size_; | 156 return size_; |
| 160 } | 157 } |
| 161 | 158 |
| 162 void* ImageTransportSurfaceFBO::GetHandle() { | 159 void* ImageTransportSurfaceFBO::GetHandle() { |
| 163 return NULL; | 160 return NULL; |
| 164 } | 161 } |
| 165 | 162 |
| 166 void* ImageTransportSurfaceFBO::GetDisplay() { | 163 void* ImageTransportSurfaceFBO::GetDisplay() { |
| 167 return NULL; | 164 return NULL; |
| 168 } | 165 } |
| 169 | 166 |
| 170 void ImageTransportSurfaceFBO::OnBufferPresented( | 167 void ImageTransportSurfaceFBO::OnBufferPresented( |
| 171 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { | 168 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { |
| 172 context_->share_group()->SetRendererID(params.renderer_id); | 169 context_->share_group()->SetRendererID(params.renderer_id); |
| 173 storage_provider_->CanFreeSwappedBuffer(); | 170 storage_provider_->SwapBuffersAckedByBrowser(); |
| 174 } | |
| 175 | |
| 176 void ImageTransportSurfaceFBO::UnblockContextAfterPendingSwap() { | |
| 177 DCHECK(is_swap_buffers_pending_); | |
| 178 is_swap_buffers_pending_ = false; | |
| 179 if (did_unschedule_) { | |
| 180 did_unschedule_ = false; | |
| 181 helper_->SetScheduled(true); | |
| 182 } | |
| 183 } | 171 } |
| 184 | 172 |
| 185 void ImageTransportSurfaceFBO::OnResize(gfx::Size size, | 173 void ImageTransportSurfaceFBO::OnResize(gfx::Size size, |
| 186 float scale_factor) { | 174 float scale_factor) { |
| 187 TRACE_EVENT2("gpu", "ImageTransportSurfaceFBO::OnResize", | 175 TRACE_EVENT2("gpu", "ImageTransportSurfaceFBO::OnResize", |
| 188 "old_width", size_.width(), "new_width", size.width()); | 176 "old_width", size_.width(), "new_width", size.width()); |
| 189 // Caching |context_| from OnMakeCurrent. It should still be current. | 177 // Caching |context_| from OnMakeCurrent. It should still be current. |
| 190 DCHECK(context_->IsCurrent(this)); | 178 DCHECK(context_->IsCurrent(this)); |
| 191 | 179 |
| 192 size_ = size; | 180 size_ = size; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 return; | 313 return; |
| 326 } | 314 } |
| 327 | 315 |
| 328 has_complete_framebuffer_ = true; | 316 has_complete_framebuffer_ = true; |
| 329 | 317 |
| 330 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, previous_texture_id); | 318 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, previous_texture_id); |
| 331 // The FBO remains bound for this GL context. | 319 // The FBO remains bound for this GL context. |
| 332 } | 320 } |
| 333 | 321 |
| 334 } // namespace content | 322 } // namespace content |
| OLD | NEW |