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 "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" |
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 Loading... |
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 needs_begin_frame_(false), | 93 needs_begin_frame_(false), |
97 did_swap_buffer_(false), | 94 did_swap_buffer_(false), |
98 current_sw_canvas_(NULL) { | 95 current_sw_canvas_(NULL) { |
99 capabilities_.deferred_gl_initialization = true; | 96 capabilities_.deferred_gl_initialization = true; |
100 } | 97 } |
101 | 98 |
102 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { | 99 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { |
103 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 did_swap_buffer_ = true; | 139 did_swap_buffer_ = true; |
143 } | 140 } |
144 | 141 |
145 void SynchronousCompositorOutputSurface::SetClient( | 142 void SynchronousCompositorOutputSurface::SetClient( |
146 SynchronousCompositorClient* compositor_client) { | 143 SynchronousCompositorClient* compositor_client) { |
147 DCHECK(CalledOnValidThread()); | 144 DCHECK(CalledOnValidThread()); |
148 compositor_client_ = compositor_client; | 145 compositor_client_ = compositor_client; |
149 UpdateCompositorClientSettings(); | 146 UpdateCompositorClientSettings(); |
150 } | 147 } |
151 | 148 |
152 bool SynchronousCompositorOutputSurface::IsHwReady() { | |
153 return context3d() != NULL; | |
154 } | |
155 | |
156 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 149 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
157 DCHECK(CalledOnValidThread()); | 150 DCHECK(CalledOnValidThread()); |
158 DCHECK(canvas); | 151 DCHECK(canvas); |
159 DCHECK(!current_sw_canvas_); | 152 DCHECK(!current_sw_canvas_); |
160 current_sw_canvas_ = canvas; | 153 current_sw_canvas_ = canvas; |
161 | 154 |
162 SkRect canvas_clip; | 155 SkRect canvas_clip; |
163 gfx::Rect damage_area; | 156 gfx::Rect damage_area; |
164 if (canvas->getClipBounds(&canvas_clip)) { | 157 if (canvas->getClipBounds(&canvas_clip)) { |
165 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip)); | 158 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip)); |
166 } else { | 159 } else { |
167 damage_area = gfx::Rect(kint16max, kint16max); | 160 damage_area = gfx::Rect(kint16max, kint16max); |
168 } | 161 } |
169 | 162 |
170 gfx::Transform transform; | 163 gfx::Transform transform; |
171 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 164 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
172 | 165 |
173 InvokeComposite(transform, damage_area); | 166 InvokeComposite(transform, damage_area); |
174 | 167 |
175 bool finished_draw = current_sw_canvas_ == NULL; | 168 bool finished_draw = current_sw_canvas_ == NULL; |
176 current_sw_canvas_ = NULL; | 169 current_sw_canvas_ = NULL; |
177 return finished_draw; | 170 return finished_draw; |
178 } | 171 } |
179 | 172 |
| 173 bool SynchronousCompositorOutputSurface::InitializeHwDraw() { |
| 174 DCHECK(CalledOnValidThread()); |
| 175 DCHECK(client_); |
| 176 DCHECK(!context3d_); |
| 177 |
| 178 context3d_ = CreateWebGraphicsContext3D().Pass(); |
| 179 |
| 180 // TODO(boliu): Get a context provider in constructor and pass here. |
| 181 bool result = client_->InitializeForGL(scoped_refptr<cc::ContextProvider>()); |
| 182 if (!result) |
| 183 client_->DidLoseOutputSurface(); |
| 184 return result; |
| 185 } |
| 186 |
180 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 187 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
181 gfx::Size view_size, | 188 gfx::Size view_size, |
182 const gfx::Transform& transform, | 189 const gfx::Transform& transform, |
183 gfx::Rect damage_area) { | 190 gfx::Rect damage_area) { |
184 DCHECK(CalledOnValidThread()); | 191 DCHECK(CalledOnValidThread()); |
185 DCHECK(client_); | 192 DCHECK(client_); |
186 | 193 |
187 did_swap_buffer_ = false; | 194 did_swap_buffer_ = false; |
188 | 195 |
189 InvokeComposite(transform, damage_area); | 196 InvokeComposite(transform, damage_area); |
190 | 197 |
191 return did_swap_buffer_; | 198 return did_swap_buffer_; |
192 } | 199 } |
193 | 200 |
(...skipping 16 matching lines...) Expand all Loading... |
210 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 217 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
211 // requirement: SynchronousCompositorOutputSurface() must only be used by | 218 // requirement: SynchronousCompositorOutputSurface() must only be used by |
212 // embedders that supply their own compositor loop via | 219 // embedders that supply their own compositor loop via |
213 // OverrideCompositorMessageLoop(). | 220 // OverrideCompositorMessageLoop(). |
214 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 221 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
215 return base::MessageLoop::current() && (base::MessageLoop::current() == | 222 return base::MessageLoop::current() && (base::MessageLoop::current() == |
216 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); | 223 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); |
217 } | 224 } |
218 | 225 |
219 } // namespace content | 226 } // namespace content |
OLD | NEW |