Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: content/browser/compositor/onscreen_display_client.cc

Issue 578383004: Limit outstanding surface draw swaps to max_frames_pending. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/compositor/onscreen_display_client.h" 5 #include "content/browser/compositor/onscreen_display_client.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "cc/output/output_surface.h" 8 #include "cc/output/output_surface.h"
9 #include "cc/surfaces/surface_factory.h" 9 #include "cc/surfaces/surface_factory.h"
10 #include "cc/surfaces/surface_manager.h" 10 #include "cc/surfaces/surface_manager.h"
11 #include "content/common/host_shared_bitmap_manager.h" 11 #include "content/common/host_shared_bitmap_manager.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 OnscreenDisplayClient::OnscreenDisplayClient( 15 OnscreenDisplayClient::OnscreenDisplayClient(
16 scoped_ptr<cc::OutputSurface> output_surface, 16 scoped_ptr<cc::OutputSurface> output_surface,
17 cc::SurfaceManager* manager, 17 cc::SurfaceManager* manager,
18 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 18 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
19 : output_surface_(output_surface.Pass()), 19 : output_surface_(output_surface.Pass()),
20 display_( 20 display_(
21 new cc::Display(this, manager, HostSharedBitmapManager::current())), 21 new cc::Display(this, manager, HostSharedBitmapManager::current())),
22 task_runner_(task_runner), 22 task_runner_(task_runner),
23 scheduled_draw_(false), 23 scheduled_draw_(false),
24 deferred_draw_(false),
25 pending_frames_(0),
24 weak_ptr_factory_(this) { 26 weak_ptr_factory_(this) {
25 } 27 }
26 28
27 OnscreenDisplayClient::~OnscreenDisplayClient() { 29 OnscreenDisplayClient::~OnscreenDisplayClient() {
28 } 30 }
29 31
30 scoped_ptr<cc::OutputSurface> OnscreenDisplayClient::CreateOutputSurface() { 32 scoped_ptr<cc::OutputSurface> OnscreenDisplayClient::CreateOutputSurface() {
31 DCHECK(output_surface_.get()); 33 DCHECK(output_surface_.get());
32 return output_surface_.Pass(); 34 return output_surface_.Pass();
33 } 35 }
34 36
35 void OnscreenDisplayClient::DisplayDamaged() { 37 void OnscreenDisplayClient::DisplayDamaged() {
36 if (scheduled_draw_) 38 if (scheduled_draw_ || deferred_draw_)
37 return; 39 return;
38 TRACE_EVENT0("content", "OnscreenDisplayClient::DisplayDamaged"); 40 TRACE_EVENT0("content", "OnscreenDisplayClient::DisplayDamaged");
41 if (pending_frames_ >= display_->GetMaxFramesPending()) {
42 deferred_draw_ = true;
43 } else {
44 ScheduleDraw();
45 }
46 }
47
48 void OnscreenDisplayClient::ScheduleDraw() {
49 DCHECK(!deferred_draw_);
50 DCHECK(!scheduled_draw_);
39 scheduled_draw_ = true; 51 scheduled_draw_ = true;
40 task_runner_->PostTask( 52 task_runner_->PostTask(
41 FROM_HERE, 53 FROM_HERE,
42 base::Bind(&OnscreenDisplayClient::Draw, weak_ptr_factory_.GetWeakPtr())); 54 base::Bind(&OnscreenDisplayClient::Draw, weak_ptr_factory_.GetWeakPtr()));
43 } 55 }
44 56
45 void OnscreenDisplayClient::Draw() { 57 void OnscreenDisplayClient::Draw() {
46 TRACE_EVENT0("content", "OnscreenDisplayClient::Draw"); 58 TRACE_EVENT0("content", "OnscreenDisplayClient::Draw");
47 scheduled_draw_ = false; 59 scheduled_draw_ = false;
48 display_->Draw(); 60 display_->Draw();
49 } 61 }
50 62
63 void OnscreenDisplayClient::DidSwapBuffers() {
64 pending_frames_++;
65 }
66
67 void OnscreenDisplayClient::DidSwapBuffersComplete() {
68 pending_frames_--;
69 if ((pending_frames_ < display_->GetMaxFramesPending()) && deferred_draw_) {
70 deferred_draw_ = false;
71 ScheduleDraw();
72 }
73 }
74
51 } // namespace content 75 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/compositor/onscreen_display_client.h ('k') | mojo/services/surfaces/surfaces_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698