Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / compositor / onscreen_display_client.cc
blobd5806fdf8d99244acdc003bd0f6bb63a10955f82
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
3 // found in the LICENSE file.
5 #include "content/browser/compositor/onscreen_display_client.h"
7 #include "base/debug/trace_event.h"
8 #include "cc/output/output_surface.h"
9 #include "cc/surfaces/surface_factory.h"
10 #include "cc/surfaces/surface_manager.h"
11 #include "content/browser/compositor/surface_display_output_surface.h"
12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
13 #include "content/common/host_shared_bitmap_manager.h"
15 namespace content {
17 OnscreenDisplayClient::OnscreenDisplayClient(
18 scoped_ptr<cc::OutputSurface> output_surface,
19 cc::SurfaceManager* manager,
20 const cc::RendererSettings& settings,
21 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
22 : output_surface_(output_surface.Pass()),
23 display_(new cc::Display(this,
24 manager,
25 HostSharedBitmapManager::current(),
26 BrowserGpuMemoryBufferManager::current(),
27 settings)),
28 task_runner_(task_runner),
29 scheduled_draw_(false),
30 output_surface_lost_(false),
31 deferred_draw_(false),
32 pending_frames_(0),
33 weak_ptr_factory_(this) {
36 OnscreenDisplayClient::~OnscreenDisplayClient() {
39 bool OnscreenDisplayClient::Initialize() {
40 return display_->Initialize(output_surface_.Pass());
43 void OnscreenDisplayClient::CommitVSyncParameters(base::TimeTicks timebase,
44 base::TimeDelta interval) {
45 surface_display_output_surface_->ReceivedVSyncParameters(timebase, interval);
48 void OnscreenDisplayClient::DisplayDamaged() {
49 if (scheduled_draw_ || deferred_draw_)
50 return;
51 TRACE_EVENT0("content", "OnscreenDisplayClient::DisplayDamaged");
52 if (pending_frames_ >= display_->GetMaxFramesPending()) {
53 deferred_draw_ = true;
54 } else {
55 ScheduleDraw();
59 void OnscreenDisplayClient::ScheduleDraw() {
60 DCHECK(!deferred_draw_);
61 DCHECK(!scheduled_draw_);
62 scheduled_draw_ = true;
63 task_runner_->PostTask(
64 FROM_HERE,
65 base::Bind(&OnscreenDisplayClient::Draw, weak_ptr_factory_.GetWeakPtr()));
68 void OnscreenDisplayClient::OutputSurfaceLost() {
69 output_surface_lost_ = true;
70 surface_display_output_surface_->DidLoseOutputSurface();
73 void OnscreenDisplayClient::Draw() {
74 TRACE_EVENT0("content", "OnscreenDisplayClient::Draw");
75 if (output_surface_lost_)
76 return;
77 scheduled_draw_ = false;
78 display_->Draw();
81 void OnscreenDisplayClient::DidSwapBuffers() {
82 pending_frames_++;
85 void OnscreenDisplayClient::DidSwapBuffersComplete() {
86 pending_frames_--;
87 if ((pending_frames_ < display_->GetMaxFramesPending()) && deferred_draw_) {
88 deferred_draw_ = false;
89 ScheduleDraw();
93 void OnscreenDisplayClient::SetMemoryPolicy(
94 const cc::ManagedMemoryPolicy& policy) {
95 surface_display_output_surface_->SetMemoryPolicy(policy);
98 } // namespace content