| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "cc/output/output_surface.h" | 5 #include "cc/output/output_surface.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 bool OutputSurface::HasExternalStencilTest() const { | 111 bool OutputSurface::HasExternalStencilTest() const { |
| 112 return external_stencil_test_enabled_; | 112 return external_stencil_test_enabled_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { | 115 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { |
| 116 DCHECK(client); | 116 DCHECK(client); |
| 117 client_ = client; | 117 client_ = client; |
| 118 bool success = true; | 118 bool success = true; |
| 119 | 119 |
| 120 if (context_provider_) { | 120 if (context_provider_.get()) { |
| 121 success = context_provider_->BindToCurrentThread(); | 121 success = context_provider_->BindToCurrentThread(); |
| 122 if (success) | 122 if (success) |
| 123 SetUpContext3d(); | 123 SetUpContext3d(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 if (!success) | 126 if (!success) |
| 127 client_ = NULL; | 127 client_ = NULL; |
| 128 | 128 |
| 129 return success; | 129 return success; |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool OutputSurface::InitializeAndSetContext3d( | 132 bool OutputSurface::InitializeAndSetContext3d( |
| 133 scoped_refptr<ContextProvider> context_provider) { | 133 scoped_refptr<ContextProvider> context_provider) { |
| 134 DCHECK(!context_provider_); | 134 DCHECK(!context_provider_.get()); |
| 135 DCHECK(context_provider); | 135 DCHECK(context_provider.get()); |
| 136 DCHECK(client_); | 136 DCHECK(client_); |
| 137 | 137 |
| 138 bool success = false; | 138 bool success = false; |
| 139 if (context_provider->BindToCurrentThread()) { | 139 if (context_provider->BindToCurrentThread()) { |
| 140 context_provider_ = context_provider; | 140 context_provider_ = context_provider; |
| 141 SetUpContext3d(); | 141 SetUpContext3d(); |
| 142 client_->DeferredInitialize(); | 142 client_->DeferredInitialize(); |
| 143 success = true; | 143 success = true; |
| 144 } | 144 } |
| 145 | 145 |
| 146 if (!success) | 146 if (!success) |
| 147 ResetContext3d(); | 147 ResetContext3d(); |
| 148 | 148 |
| 149 return success; | 149 return success; |
| 150 } | 150 } |
| 151 | 151 |
| 152 void OutputSurface::ReleaseGL() { | 152 void OutputSurface::ReleaseGL() { |
| 153 DCHECK(client_); | 153 DCHECK(client_); |
| 154 DCHECK(context_provider_); | 154 DCHECK(context_provider_.get()); |
| 155 client_->ReleaseGL(); | 155 client_->ReleaseGL(); |
| 156 DCHECK(!context_provider_); | 156 DCHECK(!context_provider_.get()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void OutputSurface::SetUpContext3d() { | 159 void OutputSurface::SetUpContext3d() { |
| 160 DCHECK(context_provider_); | 160 DCHECK(context_provider_.get()); |
| 161 DCHECK(client_); | 161 DCHECK(client_); |
| 162 | 162 |
| 163 context_provider_->SetLostContextCallback( | 163 context_provider_->SetLostContextCallback( |
| 164 base::Bind(&OutputSurface::DidLoseOutputSurface, | 164 base::Bind(&OutputSurface::DidLoseOutputSurface, |
| 165 base::Unretained(this))); | 165 base::Unretained(this))); |
| 166 context_provider_->ContextSupport()->SetSwapBuffersCompleteCallback( | 166 context_provider_->ContextSupport()->SetSwapBuffersCompleteCallback( |
| 167 base::Bind(&OutputSurface::OnSwapBuffersComplete, | 167 base::Bind(&OutputSurface::OnSwapBuffersComplete, |
| 168 base::Unretained(this))); | 168 base::Unretained(this))); |
| 169 context_provider_->SetMemoryPolicyChangedCallback( | 169 context_provider_->SetMemoryPolicyChangedCallback( |
| 170 base::Bind(&OutputSurface::SetMemoryPolicy, | 170 base::Bind(&OutputSurface::SetMemoryPolicy, |
| 171 base::Unretained(this))); | 171 base::Unretained(this))); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void OutputSurface::ReleaseContextProvider() { | 174 void OutputSurface::ReleaseContextProvider() { |
| 175 DCHECK(client_); | 175 DCHECK(client_); |
| 176 DCHECK(context_provider_); | 176 DCHECK(context_provider_.get()); |
| 177 ResetContext3d(); | 177 ResetContext3d(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void OutputSurface::ResetContext3d() { | 180 void OutputSurface::ResetContext3d() { |
| 181 if (context_provider_.get()) { | 181 if (context_provider_.get()) { |
| 182 context_provider_->SetLostContextCallback( | 182 context_provider_->SetLostContextCallback( |
| 183 ContextProvider::LostContextCallback()); | 183 ContextProvider::LostContextCallback()); |
| 184 context_provider_->SetMemoryPolicyChangedCallback( | 184 context_provider_->SetMemoryPolicyChangedCallback( |
| 185 ContextProvider::MemoryPolicyChangedCallback()); | 185 ContextProvider::MemoryPolicyChangedCallback()); |
| 186 if (gpu::ContextSupport* support = context_provider_->ContextSupport()) | 186 if (gpu::ContextSupport* support = context_provider_->ContextSupport()) |
| 187 support->SetSwapBuffersCompleteCallback(base::Closure()); | 187 support->SetSwapBuffersCompleteCallback(base::Closure()); |
| 188 } | 188 } |
| 189 context_provider_ = NULL; | 189 context_provider_ = NULL; |
| 190 } | 190 } |
| 191 | 191 |
| 192 void OutputSurface::EnsureBackbuffer() { | 192 void OutputSurface::EnsureBackbuffer() { |
| 193 if (software_device_) | 193 if (software_device_) |
| 194 software_device_->EnsureBackbuffer(); | 194 software_device_->EnsureBackbuffer(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void OutputSurface::DiscardBackbuffer() { | 197 void OutputSurface::DiscardBackbuffer() { |
| 198 if (context_provider_) | 198 if (context_provider_.get()) |
| 199 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); | 199 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); |
| 200 if (software_device_) | 200 if (software_device_) |
| 201 software_device_->DiscardBackbuffer(); | 201 software_device_->DiscardBackbuffer(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void OutputSurface::Reshape(const gfx::Size& size, float scale_factor) { | 204 void OutputSurface::Reshape(const gfx::Size& size, float scale_factor) { |
| 205 if (size == surface_size_ && scale_factor == device_scale_factor_) | 205 if (size == surface_size_ && scale_factor == device_scale_factor_) |
| 206 return; | 206 return; |
| 207 | 207 |
| 208 surface_size_ = size; | 208 surface_size_ = size; |
| 209 device_scale_factor_ = scale_factor; | 209 device_scale_factor_ = scale_factor; |
| 210 if (context_provider_) { | 210 if (context_provider_.get()) { |
| 211 context_provider_->ContextGL()->ResizeCHROMIUM( | 211 context_provider_->ContextGL()->ResizeCHROMIUM( |
| 212 size.width(), size.height(), scale_factor); | 212 size.width(), size.height(), scale_factor); |
| 213 } | 213 } |
| 214 if (software_device_) | 214 if (software_device_) |
| 215 software_device_->Resize(size, scale_factor); | 215 software_device_->Resize(size, scale_factor); |
| 216 } | 216 } |
| 217 | 217 |
| 218 gfx::Size OutputSurface::SurfaceSize() const { | 218 gfx::Size OutputSurface::SurfaceSize() const { |
| 219 return surface_size_; | 219 return surface_size_; |
| 220 } | 220 } |
| 221 | 221 |
| 222 void OutputSurface::BindFramebuffer() { | 222 void OutputSurface::BindFramebuffer() { |
| 223 DCHECK(context_provider_); | 223 DCHECK(context_provider_.get()); |
| 224 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0); | 224 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void OutputSurface::SwapBuffers(CompositorFrame* frame) { | 227 void OutputSurface::SwapBuffers(CompositorFrame* frame) { |
| 228 if (frame->software_frame_data) { | 228 if (frame->software_frame_data) { |
| 229 PostSwapBuffersComplete(); | 229 PostSwapBuffersComplete(); |
| 230 client_->DidSwapBuffers(); | 230 client_->DidSwapBuffers(); |
| 231 return; | 231 return; |
| 232 } | 232 } |
| 233 | 233 |
| 234 DCHECK(context_provider_); | 234 DCHECK(context_provider_.get()); |
| 235 DCHECK(frame->gl_frame_data); | 235 DCHECK(frame->gl_frame_data); |
| 236 | 236 |
| 237 if (frame->gl_frame_data->sub_buffer_rect == | 237 if (frame->gl_frame_data->sub_buffer_rect == |
| 238 gfx::Rect(frame->gl_frame_data->size)) { | 238 gfx::Rect(frame->gl_frame_data->size)) { |
| 239 context_provider_->ContextSupport()->Swap(); | 239 context_provider_->ContextSupport()->Swap(); |
| 240 } else { | 240 } else { |
| 241 context_provider_->ContextSupport()->PartialSwapBuffers( | 241 context_provider_->ContextSupport()->PartialSwapBuffers( |
| 242 frame->gl_frame_data->sub_buffer_rect); | 242 frame->gl_frame_data->sub_buffer_rect); |
| 243 } | 243 } |
| 244 | 244 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 262 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", | 262 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", |
| 263 "bytes_limit_when_visible", policy.bytes_limit_when_visible); | 263 "bytes_limit_when_visible", policy.bytes_limit_when_visible); |
| 264 // Just ignore the memory manager when it says to set the limit to zero | 264 // Just ignore the memory manager when it says to set the limit to zero |
| 265 // bytes. This will happen when the memory manager thinks that the renderer | 265 // bytes. This will happen when the memory manager thinks that the renderer |
| 266 // is not visible (which the renderer knows better). | 266 // is not visible (which the renderer knows better). |
| 267 if (policy.bytes_limit_when_visible) | 267 if (policy.bytes_limit_when_visible) |
| 268 client_->SetMemoryPolicy(policy); | 268 client_->SetMemoryPolicy(policy); |
| 269 } | 269 } |
| 270 | 270 |
| 271 } // namespace cc | 271 } // namespace cc |
| OLD | NEW |