| 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> | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/bind.h" | 7 #include "base/bind.h" |
| 13 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 14 #include "base/logging.h" | |
| 15 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | |
| 17 #include "base/strings/string_split.h" | |
| 18 #include "base/strings/string_util.h" | |
| 19 #include "cc/output/compositor_frame.h" | |
| 20 #include "cc/output/compositor_frame_ack.h" | |
| 21 #include "cc/output/managed_memory_policy.h" | 10 #include "cc/output/managed_memory_policy.h" |
| 22 #include "cc/output/output_surface_client.h" | 11 #include "cc/output/output_surface_client.h" |
| 23 #include "cc/scheduler/delay_based_time_source.h" | |
| 24 #include "gpu/GLES2/gl2extchromium.h" | 12 #include "gpu/GLES2/gl2extchromium.h" |
| 25 #include "gpu/command_buffer/client/context_support.h" | |
| 26 #include "gpu/command_buffer/client/gles2_interface.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
| 27 #include "ui/gfx/frame_time.h" | |
| 28 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 29 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 30 | 16 |
| 31 using std::set; | |
| 32 using std::string; | |
| 33 using std::vector; | |
| 34 | 17 |
| 35 namespace cc { | 18 namespace cc { |
| 36 | 19 |
| 37 OutputSurface::OutputSurface( | 20 OutputSurface::OutputSurface( |
| 38 const scoped_refptr<ContextProvider>& context_provider) | 21 const scoped_refptr<ContextProvider>& context_provider) |
| 39 : client_(NULL), | 22 : client_(NULL), |
| 40 context_provider_(context_provider), | 23 context_provider_(context_provider), |
| 41 device_scale_factor_(-1), | 24 device_scale_factor_(-1), |
| 42 external_stencil_test_enabled_(false), | 25 external_stencil_test_enabled_(false), |
| 43 weak_ptr_factory_(this) { | 26 weak_ptr_factory_(this) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 198 |
| 216 gfx::Size OutputSurface::SurfaceSize() const { | 199 gfx::Size OutputSurface::SurfaceSize() const { |
| 217 return surface_size_; | 200 return surface_size_; |
| 218 } | 201 } |
| 219 | 202 |
| 220 void OutputSurface::BindFramebuffer() { | 203 void OutputSurface::BindFramebuffer() { |
| 221 DCHECK(context_provider_.get()); | 204 DCHECK(context_provider_.get()); |
| 222 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0); | 205 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0); |
| 223 } | 206 } |
| 224 | 207 |
| 225 void OutputSurface::SwapBuffers(CompositorFrame* frame) { | |
| 226 // TODO(sievers): Make OutputSurface::SwapBuffers() pure virtual. | |
| 227 // The implementation here is used for tests only. | |
| 228 if (frame->software_frame_data) { | |
| 229 PostSwapBuffersComplete(); | |
| 230 client_->DidSwapBuffers(); | |
| 231 return; | |
| 232 } | |
| 233 | |
| 234 DCHECK(context_provider_.get()); | |
| 235 DCHECK(frame->gl_frame_data); | |
| 236 | |
| 237 if (frame->gl_frame_data->sub_buffer_rect == | |
| 238 gfx::Rect(frame->gl_frame_data->size)) { | |
| 239 context_provider_->ContextSupport()->Swap(); | |
| 240 } else { | |
| 241 context_provider_->ContextSupport()->PartialSwapBuffers( | |
| 242 frame->gl_frame_data->sub_buffer_rect); | |
| 243 } | |
| 244 uint32_t sync_point = | |
| 245 context_provider_->ContextGL()->InsertSyncPointCHROMIUM(); | |
| 246 context_provider_->ContextSupport()->SignalSyncPoint( | |
| 247 sync_point, | |
| 248 base::Bind(&OutputSurface::OnSwapBuffersComplete, | |
| 249 weak_ptr_factory_.GetWeakPtr())); | |
| 250 | |
| 251 client_->DidSwapBuffers(); | |
| 252 } | |
| 253 | |
| 254 void OutputSurface::PostSwapBuffersComplete() { | 208 void OutputSurface::PostSwapBuffersComplete() { |
| 255 base::MessageLoop::current()->PostTask( | 209 base::MessageLoop::current()->PostTask( |
| 256 FROM_HERE, | 210 FROM_HERE, |
| 257 base::Bind(&OutputSurface::OnSwapBuffersComplete, | 211 base::Bind(&OutputSurface::OnSwapBuffersComplete, |
| 258 weak_ptr_factory_.GetWeakPtr())); | 212 weak_ptr_factory_.GetWeakPtr())); |
| 259 } | 213 } |
| 260 | 214 |
| 261 // We don't post tasks bound to the client directly since they might run | 215 // We don't post tasks bound to the client directly since they might run |
| 262 // after the OutputSurface has been destroyed. | 216 // after the OutputSurface has been destroyed. |
| 263 void OutputSurface::OnSwapBuffersComplete() { | 217 void OutputSurface::OnSwapBuffersComplete() { |
| 264 client_->DidSwapBuffersComplete(); | 218 client_->DidSwapBuffersComplete(); |
| 265 } | 219 } |
| 266 | 220 |
| 267 void OutputSurface::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { | 221 void OutputSurface::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { |
| 268 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", | 222 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", |
| 269 "bytes_limit_when_visible", policy.bytes_limit_when_visible); | 223 "bytes_limit_when_visible", policy.bytes_limit_when_visible); |
| 270 // Just ignore the memory manager when it says to set the limit to zero | 224 // Just ignore the memory manager when it says to set the limit to zero |
| 271 // bytes. This will happen when the memory manager thinks that the renderer | 225 // bytes. This will happen when the memory manager thinks that the renderer |
| 272 // is not visible (which the renderer knows better). | 226 // is not visible (which the renderer knows better). |
| 273 if (policy.bytes_limit_when_visible) | 227 if (policy.bytes_limit_when_visible) |
| 274 client_->SetMemoryPolicy(policy); | 228 client_->SetMemoryPolicy(policy); |
| 275 } | 229 } |
| 276 | 230 |
| 277 } // namespace cc | 231 } // namespace cc |
| OLD | NEW |