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

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

Issue 659743002: aw: Fallback delegated composite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 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" 9 #include "android_webview/common/aw_switches.h"
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/debug/trace_event_argument.h" 12 #include "base/debug/trace_event_argument.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "cc/output/compositor_frame.h"
hush (inactive) 2014/10/15 18:17:30 why is this removed? we still use cc::compositorFr
boliu 2014/10/15 19:37:51 Added back.
17 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
18 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
19 #include "gpu/command_buffer/service/gpu_switches.h" 18 #include "gpu/command_buffer/service/gpu_switches.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
22 #include "third_party/skia/include/core/SkPicture.h" 21 #include "third_party/skia/include/core/SkPicture.h"
23 #include "third_party/skia/include/core/SkPictureRecorder.h" 22 #include "third_party/skia/include/core/SkPictureRecorder.h"
24 #include "ui/gfx/vector2d_conversions.h" 23 #include "ui/gfx/vector2d_conversions.h"
25 24
26 using content::SynchronousCompositorMemoryPolicy; 25 using content::SynchronousCompositorMemoryPolicy;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if (!hardware_enabled_) { 218 if (!hardware_enabled_) {
220 hardware_enabled_ = compositor_->InitializeHwDraw(); 219 hardware_enabled_ = compositor_->InitializeHwDraw();
221 if (hardware_enabled_) { 220 if (hardware_enabled_) {
222 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); 221 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this);
223 } 222 }
224 } 223 }
225 if (!hardware_enabled_) 224 if (!hardware_enabled_)
226 return false; 225 return false;
227 226
228 ReturnResourceFromParent(); 227 ReturnResourceFromParent();
229 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy();
230 RequestMemoryPolicy(new_policy);
231 compositor_->SetMemoryPolicy(memory_policy_);
232
233 if (shared_renderer_state_->HasCompositorFrame()) { 228 if (shared_renderer_state_->HasCompositorFrame()) {
234 TRACE_EVENT_INSTANT0("android_webview", 229 TRACE_EVENT_INSTANT0("android_webview",
235 "EarlyOut_PreviousFrameUnconsumed", 230 "EarlyOut_PreviousFrameUnconsumed",
236 TRACE_EVENT_SCOPE_THREAD); 231 TRACE_EVENT_SCOPE_THREAD);
237 SkippedCompositeInDraw(); 232 SkippedCompositeInDraw();
238 return client_->RequestDrawGL(java_canvas, false); 233 return client_->RequestDrawGL(java_canvas, false);
239 } 234 }
240 235
236 scoped_ptr<cc::CompositorFrame> frame = CompositeHw();
237 if (!frame.get())
238 return false;
239
240 shared_renderer_state_->SetCompositorFrame(frame.Pass(), false);
241 return client_->RequestDrawGL(java_canvas, false);
242 }
243
244 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() {
245 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy();
246 RequestMemoryPolicy(new_policy);
247 compositor_->SetMemoryPolicy(memory_policy_);
248
241 parent_draw_constraints_ = shared_renderer_state_->ParentDrawConstraints(); 249 parent_draw_constraints_ = shared_renderer_state_->ParentDrawConstraints();
242 gfx::Size surface_size(width_, height_); 250 gfx::Size surface_size(width_, height_);
243 gfx::Rect viewport(surface_size); 251 gfx::Rect viewport(surface_size);
244 gfx::Rect clip = viewport; 252 gfx::Rect clip = viewport;
245 gfx::Transform transform_for_tile_priority = 253 gfx::Transform transform_for_tile_priority =
246 parent_draw_constraints_.transform; 254 parent_draw_constraints_.transform;
247 255
248 // If the WebView is on a layer, WebView does not know what transform is 256 // If the WebView is on a layer, WebView does not know what transform is
249 // applied onto the layer so global visible rect does not make sense here. 257 // applied onto the layer so global visible rect does not make sense here.
250 // In this case, just use the surface rect for tiling. 258 // In this case, just use the surface rect for tiling.
251 gfx::Rect viewport_rect_for_tile_priority; 259 gfx::Rect viewport_rect_for_tile_priority;
252 if (parent_draw_constraints_.is_layer) 260 if (parent_draw_constraints_.is_layer)
253 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; 261 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect;
254 else 262 else
255 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; 263 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
256 264
257 scoped_ptr<cc::CompositorFrame> frame = 265 scoped_ptr<cc::CompositorFrame> frame =
258 compositor_->DemandDrawHw(surface_size, 266 compositor_->DemandDrawHw(surface_size,
259 gfx::Transform(), 267 gfx::Transform(),
260 viewport, 268 viewport,
261 clip, 269 clip,
262 viewport_rect_for_tile_priority, 270 viewport_rect_for_tile_priority,
263 transform_for_tile_priority); 271 transform_for_tile_priority);
264 if (!frame.get()) 272 if (!frame.get())
265 return false; 273 return frame.Pass();
266 274
267 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); 275 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_);
268 276
269 shared_renderer_state_->SetCompositorFrame(frame.Pass());
270 DidComposite(); 277 DidComposite();
271 return client_->RequestDrawGL(java_canvas, false); 278 return frame.Pass();
272 } 279 }
273 280
274 void BrowserViewRenderer::UpdateParentDrawConstraints() { 281 void BrowserViewRenderer::UpdateParentDrawConstraints() {
275 // Post an invalidate if the parent draw constraints are stale and there is 282 // Post an invalidate if the parent draw constraints are stale and there is
276 // no pending invalidate. 283 // no pending invalidate.
277 if (shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL() || 284 if (shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL() ||
278 !parent_draw_constraints_.Equals( 285 !parent_draw_constraints_.Equals(
279 shared_renderer_state_->ParentDrawConstraints())) { 286 shared_renderer_state_->ParentDrawConstraints())) {
280 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false); 287 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false);
281 EnsureContinuousInvalidation(true, false); 288 EnsureContinuousInvalidation(true, false);
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 TRACE_EVENT1("android_webview", 710 TRACE_EVENT1("android_webview",
704 "BrowserViewRenderer::FallbackTickFired", 711 "BrowserViewRenderer::FallbackTickFired",
705 "compositor_needs_continuous_invalidate_", 712 "compositor_needs_continuous_invalidate_",
706 compositor_needs_continuous_invalidate_); 713 compositor_needs_continuous_invalidate_);
707 714
708 // This should only be called if OnDraw or DrawGL did not come in time, which 715 // This should only be called if OnDraw or DrawGL did not come in time, which
709 // means block_invalidates_ must still be true. 716 // means block_invalidates_ must still be true.
710 DCHECK(block_invalidates_); 717 DCHECK(block_invalidates_);
711 fallback_tick_pending_ = false; 718 fallback_tick_pending_ = false;
712 if (compositor_needs_continuous_invalidate_ && compositor_) { 719 if (compositor_needs_continuous_invalidate_ && compositor_) {
713 ForceFakeCompositeSW(); 720 if (hardware_enabled_) {
721 ReturnResourceFromParent();
722 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame());
hush (inactive) 2014/10/15 18:17:30 there is also a frame in HardwareRenderer.commited
boliu 2014/10/15 19:37:51 I am calling SetFrameData twice in HWR::DrawGL :)
723 scoped_ptr<cc::CompositorFrame> frame = CompositeHw();
724 if (frame.get()) {
725 shared_renderer_state_->SetCompositorFrame(frame.Pass(), true);
726 }
727 } else {
728 ForceFakeCompositeSW();
729 }
714 } else { 730 } else {
715 // Pretend we just composited to unblock further invalidates. 731 // Pretend we just composited to unblock further invalidates.
716 DidComposite(); 732 DidComposite();
717 } 733 }
718 } 734 }
719 735
720 void BrowserViewRenderer::ForceFakeCompositeSW() { 736 void BrowserViewRenderer::ForceFakeCompositeSW() {
721 DCHECK(compositor_); 737 DCHECK(compositor_);
722 SkBitmap bitmap; 738 SkBitmap bitmap;
723 bitmap.allocN32Pixels(1, 1); 739 bitmap.allocN32Pixels(1, 1);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 base::StringAppendF(&str, 784 base::StringAppendF(&str,
769 "overscroll_rounding_error_: %s ", 785 "overscroll_rounding_error_: %s ",
770 overscroll_rounding_error_.ToString().c_str()); 786 overscroll_rounding_error_.ToString().c_str());
771 base::StringAppendF( 787 base::StringAppendF(
772 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 788 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
773 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 789 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
774 return str; 790 return str;
775 } 791 }
776 792
777 } // namespace android_webview 793 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698