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

Side by Side Diff: content/renderer/android/synchronous_compositor_output_surface.cc

Issue 14772021: cc::OutputSurfaceClient::InitializeForGL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dedup and refactor code Created 7 years, 7 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 | Annotate | Revision Log
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 "content/renderer/android/synchronous_compositor_output_surface.h" 5 #include "content/renderer/android/synchronous_compositor_output_surface.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
joth 2013/05/21 02:08:00 remove me?
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/compositor_frame_ack.h" 11 #include "cc/output/compositor_frame_ack.h"
12 #include "cc/output/context_provider.h"
12 #include "cc/output/output_surface_client.h" 13 #include "cc/output/output_surface_client.h"
13 #include "cc/output/software_output_device.h" 14 #include "cc/output/software_output_device.h"
14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 15 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
15 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
16 #include "content/public/renderer/android/synchronous_compositor_client.h" 17 #include "content/public/renderer/android/synchronous_compositor_client.h"
17 #include "content/public/renderer/content_renderer_client.h" 18 #include "content/public/renderer/content_renderer_client.h"
18 #include "skia/ext/refptr.h" 19 #include "skia/ext/refptr.h"
19 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
20 #include "third_party/skia/include/core/SkDevice.h" 21 #include "third_party/skia/include/core/SkDevice.h"
21 #include "third_party/skia/include/core/SkPicture.h" 22 #include "third_party/skia/include/core/SkPicture.h"
22 #include "ui/gfx/rect_conversions.h" 23 #include "ui/gfx/rect_conversions.h"
23 #include "ui/gfx/skia_util.h" 24 #include "ui/gfx/skia_util.h"
24 #include "ui/gfx/transform.h" 25 #include "ui/gfx/transform.h"
25 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 26 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
26 27
27 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; 28 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
28 29
29 namespace content { 30 namespace content {
30 31
31 namespace { 32 namespace {
32 33
33 // TODO(boliu): RenderThreadImpl should create in process contexts as well. 34 // TODO(boliu): RenderThreadImpl should create in process contexts as well.
34 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() { 35 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() {
35 if (!CommandLine::ForCurrentProcess()->HasSwitch("testing-webview-gl-mode"))
36 return scoped_ptr<WebKit::WebGraphicsContext3D>();
37
38 WebKit::WebGraphicsContext3D::Attributes attributes; 36 WebKit::WebGraphicsContext3D::Attributes attributes;
39 attributes.antialias = false; 37 attributes.antialias = false;
40 attributes.shareResources = true; 38 attributes.shareResources = true;
41 attributes.noAutomaticFlushes = true; 39 attributes.noAutomaticFlushes = true;
42 40
43 return scoped_ptr<WebKit::WebGraphicsContext3D>( 41 return scoped_ptr<WebKit::WebGraphicsContext3D>(
44 WebGraphicsContext3DInProcessCommandBufferImpl 42 WebGraphicsContext3DInProcessCommandBufferImpl
45 ::CreateViewContext(attributes, NULL)); 43 ::CreateViewContext(attributes, NULL));
46 } 44 }
47 45
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 private: 79 private:
82 SynchronousCompositorOutputSurface* surface_; 80 SynchronousCompositorOutputSurface* surface_;
83 SkDevice null_device_; 81 SkDevice null_device_;
84 SkCanvas null_canvas_; 82 SkCanvas null_canvas_;
85 83
86 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); 84 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice);
87 }; 85 };
88 86
89 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( 87 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface(
90 int32 routing_id) 88 int32 routing_id)
91 : cc::OutputSurface(CreateWebGraphicsContext3D(), 89 : cc::OutputSurface(
92 scoped_ptr<cc::SoftwareOutputDevice>( 90 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))),
93 new SoftwareDevice(this))),
94 compositor_client_(NULL), 91 compositor_client_(NULL),
95 routing_id_(routing_id), 92 routing_id_(routing_id),
96 vsync_enabled_(false), 93 vsync_enabled_(false),
97 did_swap_buffer_(false), 94 did_swap_buffer_(false),
98 current_sw_canvas_(NULL) { 95 current_sw_canvas_(NULL) {}
99 }
100 96
101 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { 97 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {
102 DCHECK(CalledOnValidThread()); 98 DCHECK(CalledOnValidThread());
103 if (compositor_client_) 99 if (compositor_client_)
104 compositor_client_->DidDestroyCompositor(this); 100 compositor_client_->DidDestroyCompositor(this);
105 } 101 }
106 102
107 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { 103 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const {
108 return current_sw_canvas_ != NULL; 104 return current_sw_canvas_ != NULL;
109 } 105 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 did_swap_buffer_ = true; 137 did_swap_buffer_ = true;
142 } 138 }
143 139
144 void SynchronousCompositorOutputSurface::SetClient( 140 void SynchronousCompositorOutputSurface::SetClient(
145 SynchronousCompositorClient* compositor_client) { 141 SynchronousCompositorClient* compositor_client) {
146 DCHECK(CalledOnValidThread()); 142 DCHECK(CalledOnValidThread());
147 compositor_client_ = compositor_client; 143 compositor_client_ = compositor_client;
148 UpdateCompositorClientSettings(); 144 UpdateCompositorClientSettings();
149 } 145 }
150 146
151 bool SynchronousCompositorOutputSurface::IsHwReady() {
152 return context3d() != NULL;
153 }
154
155 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 147 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
156 DCHECK(CalledOnValidThread()); 148 DCHECK(CalledOnValidThread());
157 DCHECK(canvas); 149 DCHECK(canvas);
158 DCHECK(!current_sw_canvas_); 150 DCHECK(!current_sw_canvas_);
159 current_sw_canvas_ = canvas; 151 current_sw_canvas_ = canvas;
160 152
161 SkRect canvas_clip; 153 SkRect canvas_clip;
162 gfx::Rect damage_area; 154 gfx::Rect damage_area;
163 if (canvas->getClipBounds(&canvas_clip)) { 155 if (canvas->getClipBounds(&canvas_clip)) {
164 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip)); 156 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip));
165 } else { 157 } else {
166 damage_area = gfx::Rect(kint16max, kint16max); 158 damage_area = gfx::Rect(kint16max, kint16max);
167 } 159 }
168 160
169 gfx::Transform transform; 161 gfx::Transform transform;
170 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 162 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
171 163
172 InvokeComposite(transform, damage_area); 164 InvokeComposite(transform, damage_area);
173 165
174 bool finished_draw = current_sw_canvas_ == NULL; 166 bool finished_draw = current_sw_canvas_ == NULL;
175 current_sw_canvas_ = NULL; 167 current_sw_canvas_ = NULL;
176 return finished_draw; 168 return finished_draw;
177 } 169 }
178 170
171 bool SynchronousCompositorOutputSurface::InitializeHwDraw() {
172 DCHECK(CalledOnValidThread());
173 DCHECK(client_);
174 DCHECK(!context3d_);
175
176 context3d_ = CreateWebGraphicsContext3D().Pass();
177
178 // TODO(boliu): Get a context provider in constructor and pass here.
179 bool result = client_->InitializeForGL(scoped_refptr<cc::ContextProvider>());
180 if (!result)
181 client_->DidLoseOutputSurface();
182 return result;
183 }
184
179 bool SynchronousCompositorOutputSurface::DemandDrawHw( 185 bool SynchronousCompositorOutputSurface::DemandDrawHw(
180 gfx::Size view_size, 186 gfx::Size view_size,
181 const gfx::Transform& transform, 187 const gfx::Transform& transform,
182 gfx::Rect damage_area) { 188 gfx::Rect damage_area) {
183 DCHECK(CalledOnValidThread()); 189 DCHECK(CalledOnValidThread());
184 DCHECK(client_); 190 DCHECK(client_);
185 191
186 did_swap_buffer_ = false; 192 did_swap_buffer_ = false;
187 193
188 InvokeComposite(transform, damage_area); 194 InvokeComposite(transform, damage_area);
189 195
190 return did_swap_buffer_; 196 return did_swap_buffer_;
191 } 197 }
192 198
(...skipping 16 matching lines...) Expand all
209 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 215 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
210 // requirement: SynchronousCompositorOutputSurface() must only be used by 216 // requirement: SynchronousCompositorOutputSurface() must only be used by
211 // embedders that supply their own compositor loop via 217 // embedders that supply their own compositor loop via
212 // OverrideCompositorMessageLoop(). 218 // OverrideCompositorMessageLoop().
213 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 219 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
214 return base::MessageLoop::current() && (base::MessageLoop::current() == 220 return base::MessageLoop::current() && (base::MessageLoop::current() ==
215 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); 221 GetContentClient()->renderer()->OverrideCompositorMessageLoop());
216 } 222 }
217 223
218 } // namespace content 224 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698