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

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: Add GL support and clean up 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
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 static gfx::Transform adjustTransformForClip(gfx::Transform transform,
joth 2013/05/25 02:56:40 nits: prefer namespace {} to static functions. c
157 gfx::Rect clip) {
158 transform.matrix().postTranslate(-clip.x(), -clip.y(), 0);
159 return transform;
160 }
161
156 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 162 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
157 DCHECK(CalledOnValidThread()); 163 DCHECK(CalledOnValidThread());
158 DCHECK(canvas); 164 DCHECK(canvas);
159 DCHECK(!current_sw_canvas_); 165 DCHECK(!current_sw_canvas_);
160 current_sw_canvas_ = canvas; 166 current_sw_canvas_ = canvas;
161 167
162 SkRect canvas_clip; 168 SkIRect canvas_clip;
163 gfx::Rect damage_area; 169 canvas->getClipDeviceBounds(&canvas_clip);
164 if (canvas->getClipBounds(&canvas_clip)) { 170 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 171
170 gfx::Transform transform; 172 gfx::Transform transform(gfx::Transform::kSkipInitialization);
171 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 173 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
172 174
173 InvokeComposite(transform, damage_area); 175 client_->SetDeviceTransformAndClip(adjustTransformForClip(transform, clip),
176 clip);
177 InvokeComposite(clip);
174 178
175 bool finished_draw = current_sw_canvas_ == NULL; 179 bool finished_draw = current_sw_canvas_ == NULL;
176 current_sw_canvas_ = NULL; 180 current_sw_canvas_ = NULL;
177 return finished_draw; 181 return finished_draw;
178 } 182 }
179 183
184 static gfx::Rect clipFlipY(gfx::Rect clip, gfx::Size view_size) {
joth 2013/05/25 02:56:40 ditto - namespace {} / capitalize
185 clip.set_y(view_size.height() - clip.bottom());
186 return clip;
187 }
188
180 bool SynchronousCompositorOutputSurface::DemandDrawHw( 189 bool SynchronousCompositorOutputSurface::DemandDrawHw(
181 gfx::Size view_size, 190 gfx::Size view_size,
182 const gfx::Transform& transform, 191 const gfx::Transform& transform,
183 gfx::Rect damage_area) { 192 gfx::Rect clip) {
184 DCHECK(CalledOnValidThread()); 193 DCHECK(CalledOnValidThread());
185 DCHECK(client_); 194 DCHECK(client_);
186 195
187 did_swap_buffer_ = false; 196 did_swap_buffer_ = false;
188 197
189 InvokeComposite(transform, damage_area); 198 client_->SetDeviceTransformAndClip(adjustTransformForClip(transform, clip),
199 clipFlipY(clip, view_size));
joth 2013/05/25 02:56:40 any idea why we do need to flip Y for clip (in HW
200 InvokeComposite(clip);
190 201
191 return did_swap_buffer_; 202 return did_swap_buffer_;
192 } 203 }
193 204
194 void SynchronousCompositorOutputSurface::InvokeComposite( 205 void SynchronousCompositorOutputSurface::InvokeComposite(
195 const gfx::Transform& transform,
196 gfx::Rect damage_area) { 206 gfx::Rect damage_area) {
197 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the 207 client_->SetNeedsRedrawRect(gfx::Rect(damage_area.size()));
198 // whole view. Tracking bug to implement this: crbug.com/230463.
199 client_->SetNeedsRedrawRect(damage_area);
200 if (needs_begin_frame_) 208 if (needs_begin_frame_)
201 client_->BeginFrame(base::TimeTicks::Now()); 209 client_->BeginFrame(base::TimeTicks::Now());
202 } 210 }
203 211
204 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() { 212 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() {
205 if (compositor_client_) { 213 if (compositor_client_) {
206 compositor_client_->SetContinuousInvalidate(needs_begin_frame_); 214 compositor_client_->SetContinuousInvalidate(needs_begin_frame_);
207 } 215 }
208 } 216 }
209 217
210 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 218 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
211 // requirement: SynchronousCompositorOutputSurface() must only be used by 219 // requirement: SynchronousCompositorOutputSurface() must only be used by
212 // embedders that supply their own compositor loop via 220 // embedders that supply their own compositor loop via
213 // OverrideCompositorMessageLoop(). 221 // OverrideCompositorMessageLoop().
214 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 222 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
215 return base::MessageLoop::current() && (base::MessageLoop::current() == 223 return base::MessageLoop::current() && (base::MessageLoop::current() ==
216 GetContentClient()->renderer()->OverrideCompositorMessageLoop()); 224 GetContentClient()->renderer()->OverrideCompositorMessageLoop());
217 } 225 }
218 226
219 } // namespace content 227 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698