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

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

Issue 2174203002: OnDrawHardware() implementation with async messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implemented CR suggestions Created 4 years, 4 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 <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/browser_view_renderer_client.h" 9 #include "android_webview/browser/browser_view_renderer_client.h"
10 #include "android_webview/browser/child_frame.h" 10 #include "android_webview/browser/child_frame.h"
11 #include "android_webview/browser/compositor_frame_consumer.h" 11 #include "android_webview/browser/compositor_frame_consumer.h"
12 #include "android_webview/common/aw_switches.h"
12 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/supports_user_data.h" 19 #include "base/supports_user_data.h"
19 #include "base/trace_event/trace_event_argument.h" 20 #include "base/trace_event/trace_event_argument.h"
20 #include "cc/output/compositor_frame.h" 21 #include "cc/output/compositor_frame.h"
21 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 BrowserViewRenderer* BrowserViewRenderer::FromWebContents( 87 BrowserViewRenderer* BrowserViewRenderer::FromWebContents(
87 content::WebContents* web_contents) { 88 content::WebContents* web_contents) {
88 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); 89 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents);
89 } 90 }
90 91
91 BrowserViewRenderer::BrowserViewRenderer( 92 BrowserViewRenderer::BrowserViewRenderer(
92 BrowserViewRendererClient* client, 93 BrowserViewRendererClient* client,
93 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) 94 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
94 : client_(client), 95 : client_(client),
95 ui_task_runner_(ui_task_runner), 96 ui_task_runner_(ui_task_runner),
97 async_on_draw_hardware_(base::CommandLine::ForCurrentProcess()->HasSwitch(
98 switches::kAsyncOnDrawHardware)),
96 current_compositor_frame_consumer_(nullptr), 99 current_compositor_frame_consumer_(nullptr),
97 compositor_(nullptr), 100 compositor_(nullptr),
98 is_paused_(false), 101 is_paused_(false),
99 view_visible_(false), 102 view_visible_(false),
100 window_visible_(false), 103 window_visible_(false),
101 attached_to_window_(false), 104 attached_to_window_(false),
102 hardware_enabled_(false), 105 hardware_enabled_(false),
103 dip_scale_(0.f), 106 dip_scale_(0.f),
104 page_scale_factor_(1.f), 107 page_scale_factor_(1.f),
105 min_page_scale_factor_(0.f), 108 min_page_scale_factor_(0.f),
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // If the WebView is on a layer, WebView does not know what transform is 232 // If the WebView is on a layer, WebView does not know what transform is
230 // applied onto the layer so global visible rect does not make sense here. 233 // applied onto the layer so global visible rect does not make sense here.
231 // In this case, just use the surface rect for tiling. 234 // In this case, just use the surface rect for tiling.
232 gfx::Rect viewport_rect_for_tile_priority; 235 gfx::Rect viewport_rect_for_tile_priority;
233 236
234 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. 237 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on.
235 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { 238 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) {
236 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; 239 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
237 } 240 }
238 241
242 if (async_on_draw_hardware_) {
243 compositor_->DemandDrawHwAsync(size_, viewport_rect_for_tile_priority,
244 transform_for_tile_priority);
245 return current_compositor_frame_consumer_->HasFrameOnUI();
246 }
247
239 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( 248 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw(
240 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); 249 size_, viewport_rect_for_tile_priority, transform_for_tile_priority);
241 if (!frame.frame.get()) { 250
242 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", 251 if (!frame.frame.get())
243 TRACE_EVENT_SCOPE_THREAD);
244 return current_compositor_frame_consumer_->HasFrameOnUI(); 252 return current_compositor_frame_consumer_->HasFrameOnUI();
boliu 2016/08/23 22:08:01 there used to be an TRACE_EVENT_INSTANT0 here, don
ojars 2016/08/29 21:54:45 Done.
253
254 OnDrawHardwareProcessFrame(std::move(frame));
255 return true;
256 }
257
258 void BrowserViewRenderer::OnDrawHardwareProcessFrame(
259 content::SynchronousCompositor::Frame frame) {
260 TRACE_EVENT0("android_webview",
261 "BrowserViewRenderer::OnDrawHardwareProcessFrame");
262 if (!frame.frame.get())
263 return;
264
265 gfx::Transform transform_for_tile_priority =
266 external_draw_constraints_.transform;
267 gfx::Rect viewport_rect_for_tile_priority;
268
269 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) {
270 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
boliu 2016/08/23 22:08:01 factor this duplicate code into a helper method, l
ojars 2016/08/29 21:54:45 Done.
245 } 271 }
246 272
247 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( 273 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame(
248 frame.output_surface_id, std::move(frame.frame), compositor_id_, 274 frame.output_surface_id, std::move(frame.frame), compositor_id_,
249 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority, 275 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority,
250 offscreen_pre_raster_, external_draw_constraints_.is_layer)); 276 offscreen_pre_raster_, external_draw_constraints_.is_layer));
251 277
252 ReturnUnusedResource( 278 ReturnUnusedResource(
253 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); 279 current_compositor_frame_consumer_->PassUncommittedFrameOnUI());
254 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); 280 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame));
255 return true;
256 } 281 }
257 282
258 void BrowserViewRenderer::OnParentDrawConstraintsUpdated( 283 void BrowserViewRenderer::OnParentDrawConstraintsUpdated(
259 CompositorFrameConsumer* compositor_frame_consumer) { 284 CompositorFrameConsumer* compositor_frame_consumer) {
260 DCHECK(compositor_frame_consumer); 285 DCHECK(compositor_frame_consumer);
261 if (compositor_frame_consumer != current_compositor_frame_consumer_) 286 if (compositor_frame_consumer != current_compositor_frame_consumer_)
262 return; 287 return;
263 PostInvalidate(compositor_); 288 PostInvalidate(compositor_);
264 external_draw_constraints_ = 289 external_draw_constraints_ =
265 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 290 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 base::StringAppendF(&str, 757 base::StringAppendF(&str,
733 "overscroll_rounding_error_: %s ", 758 "overscroll_rounding_error_: %s ",
734 overscroll_rounding_error_.ToString().c_str()); 759 overscroll_rounding_error_.ToString().c_str());
735 base::StringAppendF( 760 base::StringAppendF(
736 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 761 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
737 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 762 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
738 return str; 763 return str;
739 } 764 }
740 765
741 } // namespace android_webview 766 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698