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

Side by Side Diff: cc/output/output_surface.cc

Issue 15836005: cc: Emulate BeginFrame in OutputSurfaces that don't support it natively (Closed) Base URL: http://git.chromium.org/chromium/src.git@nofrc
Patch Set: Created 7 years, 6 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 (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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
14 #include "cc/output/output_surface_client.h" 15 #include "cc/output/output_surface_client.h"
16 #include "cc/scheduler/delay_based_time_source.h"
15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" 17 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
16 #include "third_party/khronos/GLES2/gl2.h" 18 #include "third_party/khronos/GLES2/gl2.h"
17 #include "third_party/khronos/GLES2/gl2ext.h" 19 #include "third_party/khronos/GLES2/gl2ext.h"
18 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
19 #include "ui/gfx/size.h" 21 #include "ui/gfx/size.h"
20 22
21 using std::set; 23 using std::set;
22 using std::string; 24 using std::string;
23 using std::vector; 25 using std::vector;
24 26
25 namespace cc { 27 namespace cc {
26 28
27 class OutputSurfaceCallbacks 29 class OutputSurfaceCallbacks
28 : public WebKit::WebGraphicsContext3D:: 30 : public WebKit::WebGraphicsContext3D::
29 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM, 31 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM,
30 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { 32 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
31 public: 33 public:
32 explicit OutputSurfaceCallbacks(OutputSurfaceClient* client) 34 explicit OutputSurfaceCallbacks(OutputSurface* client)
33 : client_(client) {} 35 : client_(client) {}
34 36
35 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation. 37 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation.
36 virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); } 38 virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); }
37 39
38 // WK:WGC3D::WGContextLostCallback implementation. 40 // WK:WGC3D::WGContextLostCallback implementation.
39 virtual void onContextLost() { client_->DidLoseOutputSurface(); } 41 virtual void onContextLost() { client_->DidLoseOutputSurface(); }
40 42
41 private: 43 private:
42 OutputSurfaceClient* client_; 44 OutputSurface* client_;
43 }; 45 };
44 46
45 OutputSurface::OutputSurface( 47 OutputSurface::OutputSurface(
46 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) 48 scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
47 : client_(NULL), 49 : client_(NULL),
48 context3d_(context3d.Pass()), 50 context3d_(context3d.Pass()),
49 has_gl_discard_backbuffer_(false) { 51 has_gl_discard_backbuffer_(false),
52 pending_begin_frames_(0) {
50 } 53 }
51 54
52 OutputSurface::OutputSurface( 55 OutputSurface::OutputSurface(
53 scoped_ptr<cc::SoftwareOutputDevice> software_device) 56 scoped_ptr<cc::SoftwareOutputDevice> software_device)
54 : client_(NULL), 57 : client_(NULL),
55 software_device_(software_device.Pass()), 58 software_device_(software_device.Pass()),
56 has_gl_discard_backbuffer_(false) { 59 has_gl_discard_backbuffer_(false),
60 pending_begin_frames_(0) {
57 } 61 }
58 62
59 OutputSurface::OutputSurface( 63 OutputSurface::OutputSurface(
60 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 64 scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
61 scoped_ptr<cc::SoftwareOutputDevice> software_device) 65 scoped_ptr<cc::SoftwareOutputDevice> software_device)
62 : client_(NULL), 66 : client_(NULL),
63 context3d_(context3d.Pass()), 67 context3d_(context3d.Pass()),
64 software_device_(software_device.Pass()), 68 software_device_(software_device.Pass()),
65 has_gl_discard_backbuffer_(false) { 69 has_gl_discard_backbuffer_(false),
70 pending_begin_frames_(0) {
71 }
72
73 void OutputSurface::InitializeBeginFrameEmulation(
74 Thread* thread,
75 bool throttle_frame_production,
76 base::TimeDelta interval,
77 int max_frames_pending,
78 bool swap_buffers_complete_supported) {
79 DCHECK(!frame_rate_controller_);
80 if (throttle_frame_production){
81 frame_rate_controller_.reset(
82 new FrameRateController(
83 DelayBasedTimeSource::Create(interval, thread)));
84 } else {
85 frame_rate_controller_.reset(new FrameRateController(thread));
86 }
87
88 frame_rate_controller_->SetClient(this);
89 frame_rate_controller_->SetSwapBuffersCompleteSupported(
90 swap_buffers_complete_supported);
91 frame_rate_controller_->SetMaxFramesPending(max_frames_pending);
92 }
93
94 void OutputSurface::OnVSyncParametersChanged(base::TimeTicks timebase,
95 base::TimeDelta interval) {
96 TRACE_EVENT2("cc", "OutputSurface::OnVSyncParametersChanged",
97 "timebase", (timebase - base::TimeTicks()).InSecondsF(),
98 "interval", interval.InSecondsF());
99 frame_rate_controller_->SetTimebaseAndInterval(timebase, interval);
100 }
101
102 void OutputSurface::FrameRateControllerTick(bool throttled) {
103 if (!throttled)
104 BeginFrame(frame_rate_controller_->LastTickTime());
105 }
106
107 // Forwarded to OutputSurfaceClient
108 void OutputSurface::SetNeedsRedrawRect(gfx::Rect damage_rect) {
109 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect");
110 client_->SetNeedsRedrawRect(damage_rect);
111 }
112
113 void OutputSurface::SetNeedsBeginFrame(bool enable) {
114 frame_rate_controller_->SetActive(enable);
115 }
116
117 void OutputSurface::BeginFrame(base::TimeTicks frame_time) {
118 // TODO(brianderson): Remove this early return once Android has
119 // Browser-side throttling.
120 //if (pending_begin_frames_ >= frame_rate_controller_->MaxFramesPending())
brianderson 2013/06/01 04:30:29 This should be uncommented and tested on Android.
Sami 2013/06/03 17:30:33 Do you have an idea what we'd need in the browser
brianderson 2013/06/03 18:51:40 Daniel is working on a patch to do that here: http
121 // return;
122 TRACE_EVENT0("cc", "OutputSurface::BeginFrame");
123 pending_begin_frames_++;
124 frame_rate_controller_->WillSwapBuffers();
125 client_->BeginFrame(frame_time);
126 }
127
128 void OutputSurface::OnSendFrameToParentCompositorAck(
129 const CompositorFrameAck& ack) {
130 TRACE_EVENT0("cc", "OutputSurface::OnSendFrameToParentCompositorAck");
131 client_->OnSendFrameToParentCompositorAck(ack);
132 }
133
134 void OutputSurface::OnSwapBuffersComplete() {
135 TRACE_EVENT0("cc", "OutputSurface::OnSwapBuffersComplete");
136 pending_begin_frames_--;
137 client_->OnSwapBuffersComplete();
138 frame_rate_controller_->DidSwapBuffersComplete();
139 }
140
141 void OutputSurface::DidLoseOutputSurface() {
142 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface");
143 pending_begin_frames_ = 0;
144 client_->DidLoseOutputSurface();
66 } 145 }
67 146
68 OutputSurface::~OutputSurface() { 147 OutputSurface::~OutputSurface() {
148 if (frame_rate_controller_)
149 frame_rate_controller_->SetActive(false);
69 } 150 }
70 151
71 bool OutputSurface::ForcedDrawToSoftwareDevice() const { 152 bool OutputSurface::ForcedDrawToSoftwareDevice() const {
72 return false; 153 return false;
73 } 154 }
74 155
75 bool OutputSurface::BindToClient( 156 bool OutputSurface::BindToClient(cc::OutputSurfaceClient* client) {
76 cc::OutputSurfaceClient* client) {
77 DCHECK(client); 157 DCHECK(client);
78 if (context3d_ && !context3d_->makeContextCurrent()) 158 if (context3d_ && !context3d_->makeContextCurrent())
79 return false; 159 return false;
80 client_ = client; 160 client_ = client;
81 if (!context3d_) 161 if (!context3d_)
82 return true; 162 return true;
83 string extensions_string = UTF16ToASCII(context3d_->getString(GL_EXTENSIONS)); 163 string extensions_string = UTF16ToASCII(context3d_->getString(GL_EXTENSIONS));
84 vector<string> extensions_list; 164 vector<string> extensions_list;
85 base::SplitString(extensions_string, ' ', &extensions_list); 165 base::SplitString(extensions_string, ' ', &extensions_list);
86 set<string> extensions(extensions_list.begin(), extensions_list.end()); 166 set<string> extensions(extensions_list.begin(), extensions_list.end());
87 167
88 has_gl_discard_backbuffer_ = 168 has_gl_discard_backbuffer_ =
89 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0; 169 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0;
90 170
91 callbacks_.reset(new OutputSurfaceCallbacks(client_)); 171 callbacks_.reset(new OutputSurfaceCallbacks(this));
92 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); 172 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get());
93 context3d_->setContextLostCallback(callbacks_.get()); 173 context3d_->setContextLostCallback(callbacks_.get());
94 174
95 return true; 175 return true;
96 } 176 }
97 177
98 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) { 178 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) {
99 NOTIMPLEMENTED(); 179 NOTIMPLEMENTED();
100 } 180 }
101 181
(...skipping 27 matching lines...) Expand all
129 } 209 }
130 210
131 void OutputSurface::PostSubBuffer(gfx::Rect rect, 211 void OutputSurface::PostSubBuffer(gfx::Rect rect,
132 const ui::LatencyInfo& latency_info) { 212 const ui::LatencyInfo& latency_info) {
133 DCHECK(context3d_); 213 DCHECK(context3d_);
134 context3d_->postSubBufferCHROMIUM( 214 context3d_->postSubBufferCHROMIUM(
135 rect.x(), rect.y(), rect.width(), rect.height()); 215 rect.x(), rect.y(), rect.width(), rect.height());
136 } 216 }
137 217
138 } // namespace cc 218 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698