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

Side by Side Diff: android_webview/browser/browser_view_renderer.cc

Issue 331103002: aw: Remove legacy rendering path (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "android_webview/browser/browser_view_renderer.h" 5 #include "android_webview/browser/browser_view_renderer.h"
6 6
7 #include "android_webview/browser/browser_view_renderer_client.h" 7 #include "android_webview/browser/browser_view_renderer_client.h"
8 #include "android_webview/browser/shared_renderer_state.h" 8 #include "android_webview/browser/shared_renderer_state.h"
9 #include "android_webview/common/aw_switches.h"
10 #include "android_webview/public/browser/draw_gl.h" 9 #include "android_webview/public/browser/draw_gl.h"
11 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
12 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
13 #include "base/command_line.h" 12 #include "base/command_line.h"
14 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
15 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
16 #include "base/logging.h" 15 #include "base/logging.h"
17 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
19 #include "cc/output/compositor_frame.h" 18 #include "cc/output/compositor_frame.h"
20 #include "content/public/browser/android/synchronous_compositor.h"
21 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "third_party/skia/include/core/SkCanvas.h" 23 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "third_party/skia/include/core/SkPicture.h" 24 #include "third_party/skia/include/core/SkPicture.h"
27 #include "third_party/skia/include/core/SkPictureRecorder.h" 25 #include "third_party/skia/include/core/SkPictureRecorder.h"
28 #include "ui/gfx/vector2d_conversions.h" 26 #include "ui/gfx/vector2d_conversions.h"
29 27
30 using base::android::AttachCurrentThread; 28 using base::android::AttachCurrentThread;
(...skipping 13 matching lines...) Expand all
44 const size_t kBytesPerPixel = 4; 42 const size_t kBytesPerPixel = 4;
45 const size_t kMemoryAllocationStep = 5 * 1024 * 1024; 43 const size_t kMemoryAllocationStep = 5 * 1024 * 1024;
46 44
47 // Used to calculate tile allocation. Determined experimentally. 45 // Used to calculate tile allocation. Determined experimentally.
48 const size_t kTileMultiplier = 12; 46 const size_t kTileMultiplier = 12;
49 const size_t kTileAllocationStep = 20; 47 const size_t kTileAllocationStep = 20;
50 // This will be set by static function CalculateTileMemoryPolicy() during init. 48 // This will be set by static function CalculateTileMemoryPolicy() during init.
51 // See AwMainDelegate::BasicStartupComplete. 49 // See AwMainDelegate::BasicStartupComplete.
52 size_t g_tile_area; 50 size_t g_tile_area;
53 51
54 class AutoResetWithLock {
55 public:
56 AutoResetWithLock(gfx::Vector2dF* scoped_variable,
57 gfx::Vector2dF new_value,
58 base::Lock& lock)
59 : scoped_variable_(scoped_variable),
60 original_value_(*scoped_variable),
61 lock_(lock) {
62 base::AutoLock auto_lock(lock_);
63 *scoped_variable_ = new_value;
64 }
65
66 ~AutoResetWithLock() {
67 base::AutoLock auto_lock(lock_);
68 *scoped_variable_ = original_value_;
69 }
70
71 private:
72 gfx::Vector2dF* scoped_variable_;
73 gfx::Vector2dF original_value_;
74 base::Lock& lock_;
75
76 DISALLOW_COPY_AND_ASSIGN(AutoResetWithLock);
77 };
78
79 class TracedValue : public base::debug::ConvertableToTraceFormat { 52 class TracedValue : public base::debug::ConvertableToTraceFormat {
80 public: 53 public:
81 explicit TracedValue(base::Value* value) : value_(value) {} 54 explicit TracedValue(base::Value* value) : value_(value) {}
82 static scoped_refptr<base::debug::ConvertableToTraceFormat> FromValue( 55 static scoped_refptr<base::debug::ConvertableToTraceFormat> FromValue(
83 base::Value* value) { 56 base::Value* value) {
84 return scoped_refptr<base::debug::ConvertableToTraceFormat>( 57 return scoped_refptr<base::debug::ConvertableToTraceFormat>(
85 new TracedValue(value)); 58 new TracedValue(value));
86 } 59 }
87 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { 60 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE {
88 std::string tmp; 61 std::string tmp;
(...skipping 30 matching lines...) Expand all
119 BrowserViewRendererClient* client, 92 BrowserViewRendererClient* client,
120 SharedRendererState* shared_renderer_state, 93 SharedRendererState* shared_renderer_state,
121 content::WebContents* web_contents, 94 content::WebContents* web_contents,
122 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) 95 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
123 : client_(client), 96 : client_(client),
124 shared_renderer_state_(shared_renderer_state), 97 shared_renderer_state_(shared_renderer_state),
125 web_contents_(web_contents), 98 web_contents_(web_contents),
126 weak_factory_on_ui_thread_(this), 99 weak_factory_on_ui_thread_(this),
127 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), 100 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()),
128 ui_task_runner_(ui_task_runner), 101 ui_task_runner_(ui_task_runner),
129 has_compositor_(false), 102 compositor_(NULL),
130 is_paused_(false), 103 is_paused_(false),
131 view_visible_(false), 104 view_visible_(false),
132 window_visible_(false), 105 window_visible_(false),
133 attached_to_window_(false), 106 attached_to_window_(false),
134 hardware_enabled_(false), 107 hardware_enabled_(false),
135 dip_scale_(0.0), 108 dip_scale_(0.0),
136 page_scale_factor_(1.0), 109 page_scale_factor_(1.0),
137 on_new_picture_enable_(false), 110 on_new_picture_enable_(false),
138 clear_view_(false), 111 clear_view_(false),
139 compositor_needs_continuous_invalidate_(false), 112 compositor_needs_continuous_invalidate_(false),
140 block_invalidates_(false), 113 block_invalidates_(false),
141 width_(0), 114 width_(0),
142 height_(0), 115 height_(0),
143 num_tiles_(0u), 116 num_tiles_(0u),
144 num_bytes_(0u) { 117 num_bytes_(0u) {
145 CHECK(web_contents_); 118 CHECK(web_contents_);
146 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this); 119 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this);
147 120
148 // Currently the logic in this class relies on |has_compositor_| remaining 121 // Currently the logic in this class relies on |compositor_| remaining
149 // false until the DidInitializeCompositor() call, hence it is not set here. 122 // NULL until the DidInitializeCompositor() call, hence it is not set here.
150 } 123 }
151 124
152 BrowserViewRenderer::~BrowserViewRenderer() { 125 BrowserViewRenderer::~BrowserViewRenderer() {
153 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); 126 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL);
154 // OnDetachedFromWindow should be called before the destructor, so the memory 127 // OnDetachedFromWindow should be called before the destructor, so the memory
155 // policy should have already been updated. 128 // policy should have already been updated.
156 } 129 }
157 130
158 // This function updates the cached memory policy in shared renderer state, as 131 // This function updates the cached memory policy in shared renderer state, as
159 // well as the tile resource allocation in GlobalTileManager. 132 // well as the tile resource allocation in GlobalTileManager.
(...skipping 12 matching lines...) Expand all
172 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) 145 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN)
173 return; 146 return;
174 147
175 // Do not release resources on view we expect to get DrawGL soon. 148 // Do not release resources on view we expect to get DrawGL soon.
176 if (level < TRIM_MEMORY_BACKGROUND && visible) 149 if (level < TRIM_MEMORY_BACKGROUND && visible)
177 return; 150 return;
178 151
179 // Just set the memory limit to 0 and drop all tiles. This will be reset to 152 // Just set the memory limit to 0 and drop all tiles. This will be reset to
180 // normal levels in the next DrawGL call. 153 // normal levels in the next DrawGL call.
181 SynchronousCompositorMemoryPolicy zero_policy; 154 SynchronousCompositorMemoryPolicy zero_policy;
182 if (shared_renderer_state_->GetMemoryPolicy() == zero_policy) 155 if (memory_policy_ == zero_policy)
183 return; 156 return;
184 157
185 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); 158 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory");
186 159
187 RequestMemoryPolicy(zero_policy); 160 RequestMemoryPolicy(zero_policy);
188 EnforceMemoryPolicyImmediately(zero_policy); 161 EnforceMemoryPolicyImmediately(zero_policy);
189 } 162 }
190 163
191 SynchronousCompositorMemoryPolicy 164 SynchronousCompositorMemoryPolicy
192 BrowserViewRenderer::CalculateDesiredMemoryPolicy() { 165 BrowserViewRenderer::CalculateDesiredMemoryPolicy() {
(...skipping 25 matching lines...) Expand all
218 // The following line will call BrowserViewRenderer::SetTilesNum(). 191 // The following line will call BrowserViewRenderer::SetTilesNum().
219 manager->RequestTiles(new_policy.num_resources_limit, tile_manager_key_); 192 manager->RequestTiles(new_policy.num_resources_limit, tile_manager_key_);
220 } 193 }
221 194
222 void BrowserViewRenderer::SetNumTiles(size_t num_tiles, 195 void BrowserViewRenderer::SetNumTiles(size_t num_tiles,
223 bool effective_immediately) { 196 bool effective_immediately) {
224 if (num_tiles == num_tiles_) 197 if (num_tiles == num_tiles_)
225 return; 198 return;
226 num_tiles_ = num_tiles; 199 num_tiles_ = num_tiles;
227 200
228 SynchronousCompositorMemoryPolicy new_policy; 201 memory_policy_.num_resources_limit = num_tiles_;
229 new_policy.num_resources_limit = num_tiles_; 202 memory_policy_.bytes_limit = num_bytes_;
230 new_policy.bytes_limit = num_bytes_;
231 shared_renderer_state_->SetMemoryPolicy(new_policy);
232 203
233 if (effective_immediately) 204 if (effective_immediately)
234 EnforceMemoryPolicyImmediately(new_policy); 205 EnforceMemoryPolicyImmediately(memory_policy_);
235 } 206 }
236 207
237 void BrowserViewRenderer::EnforceMemoryPolicyImmediately( 208 void BrowserViewRenderer::EnforceMemoryPolicyImmediately(
238 SynchronousCompositorMemoryPolicy new_policy) { 209 SynchronousCompositorMemoryPolicy new_policy) {
239 shared_renderer_state_->GetCompositor()->SetMemoryPolicy(new_policy); 210 compositor_->SetMemoryPolicy(new_policy);
240 ForceFakeCompositeSW(); 211 ForceFakeCompositeSW();
241 shared_renderer_state_->SetMemoryPolicyDirty(false);
242 } 212 }
243 213
244 size_t BrowserViewRenderer::GetNumTiles() const { 214 size_t BrowserViewRenderer::GetNumTiles() const {
245 return shared_renderer_state_->GetMemoryPolicy().num_resources_limit; 215 return memory_policy_.num_resources_limit;
246 } 216 }
247 217
248 bool BrowserViewRenderer::OnDraw(jobject java_canvas, 218 bool BrowserViewRenderer::OnDraw(jobject java_canvas,
249 bool is_hardware_canvas, 219 bool is_hardware_canvas,
250 const gfx::Vector2d& scroll, 220 const gfx::Vector2d& scroll,
251 const gfx::Rect& global_visible_rect, 221 const gfx::Rect& global_visible_rect,
252 const gfx::Rect& clip) { 222 const gfx::Rect& clip) {
253 last_on_draw_scroll_offset_ = scroll; 223 last_on_draw_scroll_offset_ = scroll;
254 last_on_draw_global_visible_rect_ = global_visible_rect; 224 last_on_draw_global_visible_rect_ = global_visible_rect;
255 225
256 if (clear_view_) 226 if (clear_view_)
257 return false; 227 return false;
258 228
259 if (is_hardware_canvas && attached_to_window_) { 229 if (is_hardware_canvas && attached_to_window_)
260 if (switches::UbercompEnabled()) { 230 return OnDrawHardware(java_canvas);
261 return OnDrawHardware(java_canvas);
262 } else {
263 return OnDrawHardwareLegacy(java_canvas);
264 }
265 }
266 // Perform a software draw 231 // Perform a software draw
267 return DrawSWInternal(java_canvas, clip); 232 return DrawSWInternal(java_canvas, clip);
268 } 233 }
269 234
270 bool BrowserViewRenderer::OnDrawHardwareLegacy(jobject java_canvas) {
271 scoped_ptr<DrawGLInput> draw_gl_input(new DrawGLInput);
272 draw_gl_input->scroll_offset = last_on_draw_scroll_offset_;
273 draw_gl_input->global_visible_rect = last_on_draw_global_visible_rect_;
274 draw_gl_input->width = width_;
275 draw_gl_input->height = height_;
276
277 SynchronousCompositorMemoryPolicy old_policy =
278 shared_renderer_state_->GetMemoryPolicy();
279 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy();
280 RequestMemoryPolicy(new_policy);
281 // We should be performing a hardware draw here. If we don't have the
282 // compositor yet or if RequestDrawGL fails, it means we failed this draw
283 // and thus return false here to clear to background color for this draw.
284 bool did_draw_gl =
285 has_compositor_ && client_->RequestDrawGL(java_canvas, false);
286 if (did_draw_gl) {
287 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_);
288 shared_renderer_state_->SetDrawGLInput(draw_gl_input.Pass());
289 } else {
290 RequestMemoryPolicy(old_policy);
291 }
292
293 return did_draw_gl;
294 }
295
296 void BrowserViewRenderer::DidDrawGL(scoped_ptr<DrawGLResult> result) {
297 DidComposite(!result->clip_contains_visible_rect);
298 }
299
300 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { 235 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) {
301 if (!has_compositor_) 236 if (!compositor_)
302 return false; 237 return false;
303 238
304 if (!hardware_enabled_) { 239 if (!hardware_enabled_) {
305 hardware_enabled_ = 240 hardware_enabled_ = compositor_->InitializeHwDraw();
306 shared_renderer_state_->GetCompositor()->InitializeHwDraw(NULL);
307 if (hardware_enabled_) { 241 if (hardware_enabled_) {
308 gpu::GLInProcessContext* share_context = 242 gpu::GLInProcessContext* share_context = compositor_->GetShareContext();
309 shared_renderer_state_->GetCompositor()->GetShareContext();
310 DCHECK(share_context); 243 DCHECK(share_context);
311 shared_renderer_state_->SetSharedContext(share_context); 244 shared_renderer_state_->SetSharedContext(share_context);
312 } 245 }
313 } 246 }
314 if (!hardware_enabled_) 247 if (!hardware_enabled_)
315 return false; 248 return false;
316 249
317 ReturnResources(); 250 ReturnResources();
318 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); 251 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy();
319 RequestMemoryPolicy(new_policy); 252 RequestMemoryPolicy(new_policy);
320 shared_renderer_state_->GetCompositor()->SetMemoryPolicy( 253 compositor_->SetMemoryPolicy(memory_policy_);
321 shared_renderer_state_->GetMemoryPolicy());
322 254
323 scoped_ptr<DrawGLInput> draw_gl_input(new DrawGLInput); 255 scoped_ptr<DrawGLInput> draw_gl_input(new DrawGLInput);
324 draw_gl_input->scroll_offset = last_on_draw_scroll_offset_; 256 draw_gl_input->scroll_offset = last_on_draw_scroll_offset_;
325 draw_gl_input->global_visible_rect = last_on_draw_global_visible_rect_;
326 draw_gl_input->width = width_; 257 draw_gl_input->width = width_;
327 draw_gl_input->height = height_; 258 draw_gl_input->height = height_;
328 259
329 gfx::Transform transform; 260 gfx::Transform transform;
330 gfx::Size surface_size(width_, height_); 261 gfx::Size surface_size(width_, height_);
331 gfx::Rect viewport(surface_size); 262 gfx::Rect viewport(surface_size);
332 // TODO(boliu): Should really be |last_on_draw_global_visible_rect_|. 263 // TODO(boliu): Should really be |last_on_draw_global_visible_rect_|.
333 // See crbug.com/372073. 264 // See crbug.com/372073.
334 gfx::Rect clip = viewport; 265 gfx::Rect clip = viewport;
335 bool stencil_enabled = false; 266 scoped_ptr<cc::CompositorFrame> frame = compositor_->DemandDrawHw(
336 scoped_ptr<cc::CompositorFrame> frame = 267 surface_size, transform, viewport, clip);
337 shared_renderer_state_->GetCompositor()->DemandDrawHw(
338 surface_size, transform, viewport, clip, stencil_enabled);
339 if (!frame.get()) 268 if (!frame.get())
340 return false; 269 return false;
341 270
342 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); 271 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_);
343 272
344 frame->AssignTo(&draw_gl_input->frame); 273 frame->AssignTo(&draw_gl_input->frame);
345 scoped_ptr<DrawGLInput> old_input = shared_renderer_state_->PassDrawGLInput(); 274 scoped_ptr<DrawGLInput> old_input = shared_renderer_state_->PassDrawGLInput();
346 if (old_input.get()) { 275 if (old_input.get()) {
347 shared_renderer_state_->ReturnResources( 276 shared_renderer_state_->ReturnResources(
348 old_input->frame.delegated_frame_data->resource_list); 277 old_input->frame.delegated_frame_data->resource_list);
349 } 278 }
350 shared_renderer_state_->SetDrawGLInput(draw_gl_input.Pass()); 279 shared_renderer_state_->SetDrawGLInput(draw_gl_input.Pass());
351 280
352 DidComposite(false); 281 DidComposite();
353 bool did_request = client_->RequestDrawGL(java_canvas, false); 282 bool did_request = client_->RequestDrawGL(java_canvas, false);
354 if (did_request) 283 if (did_request)
355 return true; 284 return true;
356 285
357 ReturnResources(); 286 ReturnResources();
358 return false; 287 return false;
359 } 288 }
360 289
361 void BrowserViewRenderer::DidDrawDelegated(scoped_ptr<DrawGLResult> result) { 290 void BrowserViewRenderer::DidDrawDelegated() {
362 if (!ui_task_runner_->BelongsToCurrentThread()) { 291 if (!ui_task_runner_->BelongsToCurrentThread()) {
363 // TODO(boliu): This should be a cancelable callback. 292 // TODO(boliu): This should be a cancelable callback.
364 ui_task_runner_->PostTask(FROM_HERE, 293 ui_task_runner_->PostTask(FROM_HERE,
365 base::Bind(&BrowserViewRenderer::DidDrawDelegated, 294 base::Bind(&BrowserViewRenderer::DidDrawDelegated,
366 ui_thread_weak_ptr_, 295 ui_thread_weak_ptr_));
367 base::Passed(&result)));
368 return; 296 return;
369 } 297 }
370 ReturnResources(); 298 ReturnResources();
371 } 299 }
372 300
373 void BrowserViewRenderer::ReturnResources() { 301 void BrowserViewRenderer::ReturnResources() {
374 cc::CompositorFrameAck frame_ack; 302 cc::CompositorFrameAck frame_ack;
375 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); 303 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources);
376 if (!frame_ack.resources.empty()) { 304 if (!frame_ack.resources.empty()) {
377 shared_renderer_state_->GetCompositor()->ReturnResources(frame_ack); 305 compositor_->ReturnResources(frame_ack);
378 } 306 }
379 } 307 }
380 308
381 bool BrowserViewRenderer::DrawSWInternal(jobject java_canvas, 309 bool BrowserViewRenderer::DrawSWInternal(jobject java_canvas,
382 const gfx::Rect& clip) { 310 const gfx::Rect& clip) {
383 if (clip.IsEmpty()) { 311 if (clip.IsEmpty()) {
384 TRACE_EVENT_INSTANT0( 312 TRACE_EVENT_INSTANT0(
385 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD); 313 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD);
386 return true; 314 return true;
387 } 315 }
388 316
389 if (!has_compositor_) { 317 if (!compositor_) {
390 TRACE_EVENT_INSTANT0( 318 TRACE_EVENT_INSTANT0(
391 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); 319 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD);
392 return false; 320 return false;
393 } 321 }
394 322
395 return BrowserViewRendererJavaHelper::GetInstance() 323 return BrowserViewRendererJavaHelper::GetInstance()
396 ->RenderViaAuxilaryBitmapIfNeeded( 324 ->RenderViaAuxilaryBitmapIfNeeded(
397 java_canvas, 325 java_canvas,
398 last_on_draw_scroll_offset_, 326 last_on_draw_scroll_offset_,
399 clip, 327 clip,
400 base::Bind(&BrowserViewRenderer::CompositeSW, 328 base::Bind(&BrowserViewRenderer::CompositeSW,
401 base::Unretained(this))); 329 base::Unretained(this)));
402 } 330 }
403 331
404 skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width, 332 skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width,
405 int height) { 333 int height) {
406 TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture"); 334 TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture");
407 335
408 // Return empty Picture objects for empty SkPictures. 336 // Return empty Picture objects for empty SkPictures.
409 if (width <= 0 || height <= 0) { 337 if (width <= 0 || height <= 0) {
410 return skia::AdoptRef(new SkPicture); 338 return skia::AdoptRef(new SkPicture);
411 } 339 }
412 340
413 // Reset scroll back to the origin, will go back to the old 341 // Reset scroll back to the origin, will go back to the old
414 // value when scroll_reset is out of scope. 342 // value when scroll_reset is out of scope.
415 AutoResetWithLock scroll_reset( 343 base::AutoReset<gfx::Vector2dF> scroll_reset(&scroll_offset_dip_,
416 &scroll_offset_dip_, gfx::Vector2dF(), render_thread_lock_); 344 gfx::Vector2dF());
417 345
418 SkPictureRecorder recorder; 346 SkPictureRecorder recorder;
419 SkCanvas* rec_canvas = recorder.beginRecording(width, height, NULL, 0); 347 SkCanvas* rec_canvas = recorder.beginRecording(width, height, NULL, 0);
420 if (has_compositor_) 348 if (compositor_)
421 CompositeSW(rec_canvas); 349 CompositeSW(rec_canvas);
422 return skia::AdoptRef(recorder.endRecording()); 350 return skia::AdoptRef(recorder.endRecording());
423 } 351 }
424 352
425 void BrowserViewRenderer::EnableOnNewPicture(bool enabled) { 353 void BrowserViewRenderer::EnableOnNewPicture(bool enabled) {
426 on_new_picture_enable_ = enabled; 354 on_new_picture_enable_ = enabled;
427 } 355 }
428 356
429 void BrowserViewRenderer::ClearView() { 357 void BrowserViewRenderer::ClearView() {
430 TRACE_EVENT_INSTANT0("android_webview", 358 TRACE_EVENT_INSTANT0("android_webview",
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 attached_to_window_ = false; 425 attached_to_window_ = false;
498 if (hardware_enabled_) { 426 if (hardware_enabled_) {
499 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput(); 427 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput();
500 if (input.get()) { 428 if (input.get()) {
501 shared_renderer_state_->ReturnResources( 429 shared_renderer_state_->ReturnResources(
502 input->frame.delegated_frame_data->resource_list); 430 input->frame.delegated_frame_data->resource_list);
503 } 431 }
504 ReturnResources(); 432 ReturnResources();
505 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); 433 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty());
506 434
507 if (switches::UbercompEnabled()) 435 compositor_->ReleaseHwDraw();
508 shared_renderer_state_->GetCompositor()->ReleaseHwDraw();
509 shared_renderer_state_->SetSharedContext(NULL); 436 shared_renderer_state_->SetSharedContext(NULL);
510 hardware_enabled_ = false; 437 hardware_enabled_ = false;
511 } 438 }
512 SynchronousCompositorMemoryPolicy zero_policy; 439 SynchronousCompositorMemoryPolicy zero_policy;
513 RequestMemoryPolicy(zero_policy); 440 RequestMemoryPolicy(zero_policy);
514 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); 441 GlobalTileManager::GetInstance()->Remove(tile_manager_key_);
515 // The hardware resources are released in the destructor of hardware renderer, 442 // The hardware resources are released in the destructor of hardware renderer,
516 // so we don't need to do it here. 443 // so we don't need to do it here.
517 // See AwContents::ReleaseHardwareDrawOnRenderThread(JNIEnv*, jobject). 444 // See AwContents::ReleaseHardwareDrawOnRenderThread(JNIEnv*, jobject).
518 } 445 }
519 446
520 bool BrowserViewRenderer::IsAttachedToWindow() const { 447 bool BrowserViewRenderer::IsAttachedToWindow() const {
521 return attached_to_window_; 448 return attached_to_window_;
522 } 449 }
523 450
524 bool BrowserViewRenderer::IsVisible() const { 451 bool BrowserViewRenderer::IsVisible() const {
525 // Ignore |window_visible_| if |attached_to_window_| is false. 452 // Ignore |window_visible_| if |attached_to_window_| is false.
526 return view_visible_ && (!attached_to_window_ || window_visible_); 453 return view_visible_ && (!attached_to_window_ || window_visible_);
527 } 454 }
528 455
529 gfx::Rect BrowserViewRenderer::GetScreenRect() const { 456 gfx::Rect BrowserViewRenderer::GetScreenRect() const {
530 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); 457 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_));
531 } 458 }
532 459
533 void BrowserViewRenderer::DidInitializeCompositor( 460 void BrowserViewRenderer::DidInitializeCompositor(
534 content::SynchronousCompositor* compositor) { 461 content::SynchronousCompositor* compositor) {
535 TRACE_EVENT0("android_webview", 462 TRACE_EVENT0("android_webview",
536 "BrowserViewRenderer::DidInitializeCompositor"); 463 "BrowserViewRenderer::DidInitializeCompositor");
537 DCHECK(compositor); 464 DCHECK(compositor);
538 DCHECK(!has_compositor_); 465 DCHECK(!compositor_);
539 DCHECK(ui_task_runner_->BelongsToCurrentThread()); 466 DCHECK(ui_task_runner_->BelongsToCurrentThread());
540 has_compositor_ = true; 467 compositor_ = compositor;
541 shared_renderer_state_->SetCompositorOnUiThread(compositor);
542 } 468 }
543 469
544 void BrowserViewRenderer::DidDestroyCompositor( 470 void BrowserViewRenderer::DidDestroyCompositor(
545 content::SynchronousCompositor* compositor) { 471 content::SynchronousCompositor* compositor) {
546 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); 472 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor");
547 DCHECK(has_compositor_); 473 DCHECK(compositor_);
548 DCHECK(ui_task_runner_->BelongsToCurrentThread()); 474 DCHECK(ui_task_runner_->BelongsToCurrentThread());
549 has_compositor_ = false; 475 compositor_ = NULL;
550 shared_renderer_state_->SetCompositorOnUiThread(NULL);
551 SynchronousCompositorMemoryPolicy zero_policy; 476 SynchronousCompositorMemoryPolicy zero_policy;
552 DCHECK(shared_renderer_state_->GetMemoryPolicy() == zero_policy); 477 DCHECK(memory_policy_ == zero_policy);
553 } 478 }
554 479
555 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { 480 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) {
556 { 481 if (compositor_needs_continuous_invalidate_ == invalidate)
557 base::AutoLock lock(render_thread_lock_); 482 return;
558 if (compositor_needs_continuous_invalidate_ == invalidate)
559 return;
560 483
561 TRACE_EVENT_INSTANT1("android_webview", 484 TRACE_EVENT_INSTANT1("android_webview",
562 "BrowserViewRenderer::SetContinuousInvalidate", 485 "BrowserViewRenderer::SetContinuousInvalidate",
563 TRACE_EVENT_SCOPE_THREAD, 486 TRACE_EVENT_SCOPE_THREAD,
564 "invalidate", 487 "invalidate",
565 invalidate); 488 invalidate);
566 compositor_needs_continuous_invalidate_ = invalidate; 489 compositor_needs_continuous_invalidate_ = invalidate;
567 }
568 490
569 if (ui_task_runner_->BelongsToCurrentThread()) { 491 if (ui_task_runner_->BelongsToCurrentThread()) {
570 EnsureContinuousInvalidation(false); 492 EnsureContinuousInvalidation(false);
571 return; 493 return;
572 } 494 }
573 ui_task_runner_->PostTask( 495 ui_task_runner_->PostTask(
574 FROM_HERE, 496 FROM_HERE,
575 base::Bind(&BrowserViewRenderer::EnsureContinuousInvalidation, 497 base::Bind(&BrowserViewRenderer::EnsureContinuousInvalidation,
576 ui_thread_weak_ptr_, 498 ui_thread_weak_ptr_,
577 false)); 499 false));
(...skipping 24 matching lines...) Expand all
602 if (max_offset.y()) { 524 if (max_offset.y()) {
603 scroll_offset_dip.set_y((scroll_offset.y() * max_scroll_offset_dip_.y()) / 525 scroll_offset_dip.set_y((scroll_offset.y() * max_scroll_offset_dip_.y()) /
604 max_offset.y()); 526 max_offset.y());
605 } 527 }
606 528
607 DCHECK_LE(0, scroll_offset_dip.x()); 529 DCHECK_LE(0, scroll_offset_dip.x());
608 DCHECK_LE(0, scroll_offset_dip.y()); 530 DCHECK_LE(0, scroll_offset_dip.y());
609 DCHECK_LE(scroll_offset_dip.x(), max_scroll_offset_dip_.x()); 531 DCHECK_LE(scroll_offset_dip.x(), max_scroll_offset_dip_.x());
610 DCHECK_LE(scroll_offset_dip.y(), max_scroll_offset_dip_.y()); 532 DCHECK_LE(scroll_offset_dip.y(), max_scroll_offset_dip_.y());
611 533
612 { 534 if (scroll_offset_dip_ == scroll_offset_dip)
613 base::AutoLock lock(render_thread_lock_); 535 return;
614 if (scroll_offset_dip_ == scroll_offset_dip)
615 return;
616 536
617 scroll_offset_dip_ = scroll_offset_dip; 537 scroll_offset_dip_ = scroll_offset_dip;
618 }
619 538
620 TRACE_EVENT_INSTANT2("android_webview", 539 TRACE_EVENT_INSTANT2("android_webview",
621 "BrowserViewRenderer::ScrollTo", 540 "BrowserViewRenderer::ScrollTo",
622 TRACE_EVENT_SCOPE_THREAD, 541 TRACE_EVENT_SCOPE_THREAD,
623 "x", 542 "x",
624 scroll_offset_dip.x(), 543 scroll_offset_dip.x(),
625 "y", 544 "y",
626 scroll_offset_dip.y()); 545 scroll_offset_dip.y());
627 546
628 if (has_compositor_) 547 if (compositor_)
629 shared_renderer_state_->GetCompositor()-> 548 compositor_->DidChangeRootLayerScrollOffset();
630 DidChangeRootLayerScrollOffset();
631 } 549 }
632 550
633 void BrowserViewRenderer::DidUpdateContent() { 551 void BrowserViewRenderer::DidUpdateContent() {
634 if (!ui_task_runner_->BelongsToCurrentThread()) { 552 if (!ui_task_runner_->BelongsToCurrentThread()) {
635 ui_task_runner_->PostTask(FROM_HERE, 553 ui_task_runner_->PostTask(FROM_HERE,
636 base::Bind(&BrowserViewRenderer::DidUpdateContent, 554 base::Bind(&BrowserViewRenderer::DidUpdateContent,
637 ui_thread_weak_ptr_)); 555 ui_thread_weak_ptr_));
638 return; 556 return;
639 } 557 }
640 TRACE_EVENT_INSTANT0("android_webview", 558 TRACE_EVENT_INSTANT0("android_webview",
641 "BrowserViewRenderer::DidUpdateContent", 559 "BrowserViewRenderer::DidUpdateContent",
642 TRACE_EVENT_SCOPE_THREAD); 560 TRACE_EVENT_SCOPE_THREAD);
643 clear_view_ = false; 561 clear_view_ = false;
644 if (on_new_picture_enable_) 562 if (on_new_picture_enable_)
645 client_->OnNewPicture(); 563 client_->OnNewPicture();
646 } 564 }
647 565
648 void BrowserViewRenderer::SetTotalRootLayerScrollOffset( 566 void BrowserViewRenderer::SetTotalRootLayerScrollOffset(
649 gfx::Vector2dF scroll_offset_dip) { 567 gfx::Vector2dF scroll_offset_dip) {
568 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during
569 // DrawGl when http://crbug.com/249972 is fixed.
570 if (scroll_offset_dip_ == scroll_offset_dip)
571 return;
650 572
651 { 573 scroll_offset_dip_ = scroll_offset_dip;
652 base::AutoLock lock(render_thread_lock_);
653 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during
654 // DrawGl when http://crbug.com/249972 is fixed.
655 if (scroll_offset_dip_ == scroll_offset_dip)
656 return;
657
658 scroll_offset_dip_ = scroll_offset_dip;
659 }
660 574
661 gfx::Vector2d max_offset = max_scroll_offset(); 575 gfx::Vector2d max_offset = max_scroll_offset();
662 gfx::Vector2d scroll_offset; 576 gfx::Vector2d scroll_offset;
663 // For an explanation as to why this is done this way see the comment in 577 // For an explanation as to why this is done this way see the comment in
664 // BrowserViewRenderer::ScrollTo. 578 // BrowserViewRenderer::ScrollTo.
665 if (max_scroll_offset_dip_.x()) { 579 if (max_scroll_offset_dip_.x()) {
666 scroll_offset.set_x((scroll_offset_dip.x() * max_offset.x()) / 580 scroll_offset.set_x((scroll_offset_dip.x() * max_offset.x()) /
667 max_scroll_offset_dip_.x()); 581 max_scroll_offset_dip_.x());
668 } 582 }
669 583
670 if (max_scroll_offset_dip_.y()) { 584 if (max_scroll_offset_dip_.y()) {
671 scroll_offset.set_y((scroll_offset_dip.y() * max_offset.y()) / 585 scroll_offset.set_y((scroll_offset_dip.y() * max_offset.y()) /
672 max_scroll_offset_dip_.y()); 586 max_scroll_offset_dip_.y());
673 } 587 }
674 588
675 DCHECK(0 <= scroll_offset.x()); 589 DCHECK(0 <= scroll_offset.x());
676 DCHECK(0 <= scroll_offset.y()); 590 DCHECK(0 <= scroll_offset.y());
677 DCHECK(scroll_offset.x() <= max_offset.x()); 591 DCHECK(scroll_offset.x() <= max_offset.x());
678 DCHECK(scroll_offset.y() <= max_offset.y()); 592 DCHECK(scroll_offset.y() <= max_offset.y());
679 593
680 client_->ScrollContainerViewTo(scroll_offset); 594 client_->ScrollContainerViewTo(scroll_offset);
681 } 595 }
682 596
683 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { 597 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() {
684 base::AutoLock lock(render_thread_lock_);
685 return scroll_offset_dip_; 598 return scroll_offset_dip_;
686 } 599 }
687 600
688 bool BrowserViewRenderer::IsExternalFlingActive() const { 601 bool BrowserViewRenderer::IsExternalFlingActive() const {
689 if (!ui_task_runner_->BelongsToCurrentThread()) { 602 if (!ui_task_runner_->BelongsToCurrentThread()) {
690 // TODO(boliu): This is short term hack since we cannot call into 603 // TODO(boliu): This is short term hack since we cannot call into
691 // view system on non-UI thread. 604 // view system on non-UI thread.
692 return false; 605 return false;
693 } 606 }
694 return client_->IsFlingActive(); 607 return client_->IsFlingActive();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 // 1) Webview is paused. Also need to check we are not in clear view since 711 // 1) Webview is paused. Also need to check we are not in clear view since
799 // paused, offscreen still expect clear view to recover. 712 // paused, offscreen still expect clear view to recover.
800 // 2) If we are attached to window and the window is not visible (eg when 713 // 2) If we are attached to window and the window is not visible (eg when
801 // app is in the background). We are sure in this case the webview is used 714 // app is in the background). We are sure in this case the webview is used
802 // "on-screen" but that updates are not needed when in the background. 715 // "on-screen" but that updates are not needed when in the background.
803 bool throttle_fallback_tick = 716 bool throttle_fallback_tick =
804 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_); 717 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_);
805 if (throttle_fallback_tick) 718 if (throttle_fallback_tick)
806 return; 719 return;
807 720
808 { 721 block_invalidates_ = compositor_needs_continuous_invalidate_;
809 base::AutoLock lock(render_thread_lock_);
810 block_invalidates_ = compositor_needs_continuous_invalidate_;
811 }
812 722
813 // Unretained here is safe because the callback is cancelled when 723 // Unretained here is safe because the callback is cancelled when
814 // |fallback_tick_| is destroyed. 724 // |fallback_tick_| is destroyed.
815 fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::FallbackTickFired, 725 fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::FallbackTickFired,
816 base::Unretained(this))); 726 base::Unretained(this)));
817 727
818 // No need to reschedule fallback tick if compositor does not need to be 728 // No need to reschedule fallback tick if compositor does not need to be
819 // ticked. This can happen if this is reached because force_invalidate is 729 // ticked. This can happen if this is reached because force_invalidate is
820 // true. 730 // true.
821 if (compositor_needs_continuous_invalidate_) { 731 if (compositor_needs_continuous_invalidate_) {
822 ui_task_runner_->PostDelayedTask( 732 ui_task_runner_->PostDelayedTask(
823 FROM_HERE, 733 FROM_HERE,
824 fallback_tick_.callback(), 734 fallback_tick_.callback(),
825 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds)); 735 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds));
826 } 736 }
827 } 737 }
828 738
829 void BrowserViewRenderer::FallbackTickFired() { 739 void BrowserViewRenderer::FallbackTickFired() {
830 TRACE_EVENT1("android_webview", 740 TRACE_EVENT1("android_webview",
831 "BrowserViewRenderer::FallbackTickFired", 741 "BrowserViewRenderer::FallbackTickFired",
832 "compositor_needs_continuous_invalidate_", 742 "compositor_needs_continuous_invalidate_",
833 compositor_needs_continuous_invalidate_); 743 compositor_needs_continuous_invalidate_);
834 744
835 // This should only be called if OnDraw or DrawGL did not come in time, which 745 // This should only be called if OnDraw or DrawGL did not come in time, which
836 // means block_invalidates_ must still be true. 746 // means block_invalidates_ must still be true.
837 DCHECK(block_invalidates_); 747 DCHECK(block_invalidates_);
838 if (compositor_needs_continuous_invalidate_ && has_compositor_) 748 if (compositor_needs_continuous_invalidate_ && compositor_)
839 ForceFakeCompositeSW(); 749 ForceFakeCompositeSW();
840 } 750 }
841 751
842 void BrowserViewRenderer::ForceFakeCompositeSW() { 752 void BrowserViewRenderer::ForceFakeCompositeSW() {
843 DCHECK(has_compositor_); 753 DCHECK(compositor_);
844 SkBitmap bitmap; 754 SkBitmap bitmap;
845 bitmap.allocN32Pixels(1, 1); 755 bitmap.allocN32Pixels(1, 1);
846 bitmap.eraseColor(0); 756 bitmap.eraseColor(0);
847 SkCanvas canvas(bitmap); 757 SkCanvas canvas(bitmap);
848 CompositeSW(&canvas); 758 CompositeSW(&canvas);
849 } 759 }
850 760
851 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { 761 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) {
852 DCHECK(has_compositor_); 762 DCHECK(compositor_);
853 bool result = shared_renderer_state_->GetCompositor()-> 763 bool result = compositor_->DemandDrawSw(canvas);
854 DemandDrawSw(canvas); 764 DidComposite();
855 DidComposite(false);
856 return result; 765 return result;
857 } 766 }
858 767
859 void BrowserViewRenderer::DidComposite(bool force_invalidate) { 768 void BrowserViewRenderer::DidComposite() {
860 { 769 block_invalidates_ = false;
861 base::AutoLock lock(render_thread_lock_);
862 block_invalidates_ = false;
863 }
864 770
865 if (!ui_task_runner_->BelongsToCurrentThread()) { 771 if (!ui_task_runner_->BelongsToCurrentThread()) {
866 ui_task_runner_->PostTask( 772 ui_task_runner_->PostTask(
867 FROM_HERE, 773 FROM_HERE,
868 base::Bind(&BrowserViewRenderer::EnsureContinuousInvalidation, 774 base::Bind(&BrowserViewRenderer::EnsureContinuousInvalidation,
869 ui_thread_weak_ptr_, 775 ui_thread_weak_ptr_,
870 force_invalidate)); 776 false));
871 return; 777 return;
872 } 778 }
873 779
874 fallback_tick_.Cancel(); 780 fallback_tick_.Cancel();
875 EnsureContinuousInvalidation(force_invalidate); 781 EnsureContinuousInvalidation(false);
876 } 782 }
877 783
878 std::string BrowserViewRenderer::ToString(AwDrawGLInfo* draw_info) const { 784 std::string BrowserViewRenderer::ToString(AwDrawGLInfo* draw_info) const {
879 std::string str; 785 std::string str;
880 base::StringAppendF(&str, "is_paused: %d ", is_paused_); 786 base::StringAppendF(&str, "is_paused: %d ", is_paused_);
881 base::StringAppendF(&str, "view_visible: %d ", view_visible_); 787 base::StringAppendF(&str, "view_visible: %d ", view_visible_);
882 base::StringAppendF(&str, "window_visible: %d ", window_visible_); 788 base::StringAppendF(&str, "window_visible: %d ", window_visible_);
883 base::StringAppendF(&str, "dip_scale: %f ", dip_scale_); 789 base::StringAppendF(&str, "dip_scale: %f ", dip_scale_);
884 base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_); 790 base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_);
885 base::StringAppendF(&str, 791 base::StringAppendF(&str,
(...skipping 23 matching lines...) Expand all
909 base::StringAppendF(&str, 815 base::StringAppendF(&str,
910 "surface width height: [%d %d] ", 816 "surface width height: [%d %d] ",
911 draw_info->width, 817 draw_info->width,
912 draw_info->height); 818 draw_info->height);
913 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); 819 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer);
914 } 820 }
915 return str; 821 return str;
916 } 822 }
917 823
918 } // namespace android_webview 824 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698