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

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

Issue 15579002: Implement transform/clip support for Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address joth's code review 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 "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"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 SynchronousCompositorClient* compositor_client) { 146 SynchronousCompositorClient* compositor_client) {
147 DCHECK(CalledOnValidThread()); 147 DCHECK(CalledOnValidThread());
148 compositor_client_ = compositor_client; 148 compositor_client_ = compositor_client;
149 UpdateCompositorClientSettings(); 149 UpdateCompositorClientSettings();
150 } 150 }
151 151
152 bool SynchronousCompositorOutputSurface::IsHwReady() { 152 bool SynchronousCompositorOutputSurface::IsHwReady() {
153 return context3d() != NULL; 153 return context3d() != NULL;
154 } 154 }
155 155
156 namespace {
157 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) {
158 // The system-provided transform translates us from the screen origin to the
159 // origin of the clip rect, but CC's draw origin starts at the clip.
160 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0);
161 }
162
163 gfx::Rect ClipFlipY(gfx::Rect clip, gfx::Size view_size) {
164 // CC's cliprect is relative to the bottom-left in hardware mode and
enne (OOO) 2013/05/29 20:34:12 This seems like an unfortunate inconsistency. Doe
165 // top-left in software mode, but the system always provides it to us
166 // from the top-left.
167 clip.set_y(view_size.height() - clip.bottom());
168 return clip;
169 }
170 } // namespace
171
156 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 172 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
157 DCHECK(CalledOnValidThread()); 173 DCHECK(CalledOnValidThread());
158 DCHECK(canvas); 174 DCHECK(canvas);
159 DCHECK(!current_sw_canvas_); 175 DCHECK(!current_sw_canvas_);
160 current_sw_canvas_ = canvas; 176 current_sw_canvas_ = canvas;
161 177
162 SkRect canvas_clip; 178 SkIRect canvas_clip;
163 gfx::Rect damage_area; 179 canvas->getClipDeviceBounds(&canvas_clip);
164 if (canvas->getClipBounds(&canvas_clip)) { 180 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip);
165 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip));
166 } else {
167 damage_area = gfx::Rect(kint16max, kint16max);
168 }
169 181
170 gfx::Transform transform; 182 gfx::Transform transform(gfx::Transform::kSkipInitialization);
171 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 183 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
184 AdjustTransformForClip(&transform, clip);
172 185
173 InvokeComposite(transform, damage_area); 186 client_->SetDeviceTransformAndClip(transform, clip);
187 InvokeComposite(clip.size());
174 188
175 bool finished_draw = current_sw_canvas_ == NULL; 189 bool finished_draw = current_sw_canvas_ == NULL;
176 current_sw_canvas_ = NULL; 190 current_sw_canvas_ = NULL;
177 return finished_draw; 191 return finished_draw;
178 } 192 }
179 193
180 bool SynchronousCompositorOutputSurface::DemandDrawHw( 194 bool SynchronousCompositorOutputSurface::DemandDrawHw(
181 gfx::Size view_size, 195 gfx::Size view_size,
joth 2013/06/01 01:28:20 view_size -> surface_size or device_size ?
182 const gfx::Transform& transform, 196 const gfx::Transform& transform,
183 gfx::Rect damage_area) { 197 gfx::Rect clip) {
184 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
185 DCHECK(client_); 199 DCHECK(client_);
186 200
187 did_swap_buffer_ = false; 201 did_swap_buffer_ = false;
188 202
189 InvokeComposite(transform, damage_area); 203 gfx::Transform adjusted_transform = transform;
204 AdjustTransformForClip(&adjusted_transform, clip);
205 client_->SetDeviceTransformAndClip(adjusted_transform,
206 ClipFlipY(clip, view_size));
207 InvokeComposite(clip.size());
190 208
191 return did_swap_buffer_; 209 return did_swap_buffer_;
192 } 210 }
193 211
194 void SynchronousCompositorOutputSurface::InvokeComposite( 212 void SynchronousCompositorOutputSurface::InvokeComposite(
195 const gfx::Transform& transform, 213 gfx::Size damage_size) {
196 gfx::Rect damage_area) { 214 client_->SetNeedsRedrawRect(gfx::Rect(damage_size));
197 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the
198 // whole view. Tracking bug to implement this: crbug.com/230463.
199 client_->SetNeedsRedrawRect(damage_area);
200 if (needs_begin_frame_) 215 if (needs_begin_frame_)
201 client_->BeginFrame(base::TimeTicks::Now()); 216 client_->BeginFrame(base::TimeTicks::Now());
202 } 217 }
203 218
204 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() { 219 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() {
205 if (compositor_client_) { 220 if (compositor_client_) {
206 compositor_client_->SetContinuousInvalidate(needs_begin_frame_); 221 compositor_client_->SetContinuousInvalidate(needs_begin_frame_);
207 } 222 }
208 } 223 }
209 224
210 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 225 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
211 // requirement: SynchronousCompositorOutputSurface() must only be used by 226 // requirement: SynchronousCompositorOutputSurface() must only be used by
212 // embedders that supply their own compositor loop via 227 // embedders that supply their own compositor loop via
213 // OverrideCompositorMessageLoop(). 228 // OverrideCompositorMessageLoop().
214 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 229 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
215 return base::MessageLoop::current() && (base::MessageLoop::current() == 230 return base::MessageLoop::current() && (base::MessageLoop::current() ==
216 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); 231 GetContentClient()->renderer()->OverrideCompositorMessageLoop());
217 } 232 }
218 233
219 } // namespace content 234 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698