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

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 code review Created 4 years, 3 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 222
220 external_draw_constraints_ = 223 external_draw_constraints_ =
221 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 224 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
222 225
223 ReturnResourceFromParent(current_compositor_frame_consumer_); 226 ReturnResourceFromParent(current_compositor_frame_consumer_);
224 UpdateMemoryPolicy(); 227 UpdateMemoryPolicy();
225 228
226 gfx::Transform transform_for_tile_priority = 229 gfx::Transform transform_for_tile_priority =
227 external_draw_constraints_.transform; 230 external_draw_constraints_.transform;
228 231
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
boliu 2016/08/29 22:02:10 move this comment to the helper method
ojars 2016/09/02 01:29:55 Done.
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 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on.
236 gfx::Rect viewport_rect_for_tile_priority =
237 ComputeViewportRectForTilePriority();
233 238
234 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. 239 if (async_on_draw_hardware_) {
235 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { 240 compositor_->DemandDrawHwAsync(size_, viewport_rect_for_tile_priority,
236 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; 241 transform_for_tile_priority);
242 return current_compositor_frame_consumer_->HasFrameOnUI();
237 } 243 }
238 244
239 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( 245 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw(
240 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); 246 size_, viewport_rect_for_tile_priority, transform_for_tile_priority);
247
boliu 2016/08/29 22:02:10 remove empty line
ojars 2016/09/02 01:29:55 Done.
241 if (!frame.frame.get()) { 248 if (!frame.frame.get()) {
242 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", 249 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame",
243 TRACE_EVENT_SCOPE_THREAD); 250 TRACE_EVENT_SCOPE_THREAD);
244 return current_compositor_frame_consumer_->HasFrameOnUI(); 251 return current_compositor_frame_consumer_->HasFrameOnUI();
245 } 252 }
246 253
247 std::unique_ptr<ChildFrame> child_frame = base::MakeUnique<ChildFrame>( 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())
dcheng 2016/08/31 18:06:44 Nit: I think .get() can probably be omitted here.
ojars 2016/09/02 01:29:55 Done.
263 return;
264
265 gfx::Transform transform_for_tile_priority =
266 external_draw_constraints_.transform;
267 gfx::Rect viewport_rect_for_tile_priority =
268 ComputeViewportRectForTilePriority();
269 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame(
dcheng 2016/08/31 18:06:44 Nit: prefer base::MakeUnique<ChildFrame>();
ojars 2016/09/02 01:29:55 Done.
ojars 2016/09/02 01:29:55 Done.
248 frame.output_surface_id, std::move(frame.frame), compositor_id_, 270 frame.output_surface_id, std::move(frame.frame), compositor_id_,
249 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority, 271 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority,
250 offscreen_pre_raster_, external_draw_constraints_.is_layer); 272 offscreen_pre_raster_, external_draw_constraints_.is_layer));
251 273
252 ReturnUnusedResource( 274 ReturnUnusedResource(
253 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); 275 current_compositor_frame_consumer_->PassUncommittedFrameOnUI());
254 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); 276 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame));
255 return true; 277 }
278
279 gfx::Rect BrowserViewRenderer::ComputeViewportRectForTilePriority() {
280 gfx::Rect viewport_rect_for_tile_priority;
281
282 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) {
283 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
284 }
285 return viewport_rect_for_tile_priority;
256 } 286 }
257 287
258 void BrowserViewRenderer::OnParentDrawConstraintsUpdated( 288 void BrowserViewRenderer::OnParentDrawConstraintsUpdated(
259 CompositorFrameConsumer* compositor_frame_consumer) { 289 CompositorFrameConsumer* compositor_frame_consumer) {
260 DCHECK(compositor_frame_consumer); 290 DCHECK(compositor_frame_consumer);
261 if (compositor_frame_consumer != current_compositor_frame_consumer_) 291 if (compositor_frame_consumer != current_compositor_frame_consumer_)
262 return; 292 return;
263 PostInvalidate(compositor_); 293 PostInvalidate(compositor_);
264 external_draw_constraints_ = 294 external_draw_constraints_ =
265 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 295 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 base::StringAppendF(&str, 762 base::StringAppendF(&str,
733 "overscroll_rounding_error_: %s ", 763 "overscroll_rounding_error_: %s ",
734 overscroll_rounding_error_.ToString().c_str()); 764 overscroll_rounding_error_.ToString().c_str());
735 base::StringAppendF( 765 base::StringAppendF(
736 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 766 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
737 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 767 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
738 return str; 768 return str;
739 } 769 }
740 770
741 } // namespace android_webview 771 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698