Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.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 "base/supports_user_data.h" | 16 #include "base/supports_user_data.h" |
| 17 #include "base/trace_event/trace_event_argument.h" | 17 #include "base/trace_event/trace_event_argument.h" |
| 18 #include "cc/output/compositor_frame.h" | 18 #include "cc/output/compositor_frame.h" |
| 19 #include "cc/output/compositor_frame_ack.h" | |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 21 #include "gpu/command_buffer/service/gpu_switches.h" | 22 #include "gpu/command_buffer/service/gpu_switches.h" |
| 22 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 23 #include "third_party/skia/include/core/SkCanvas.h" | 24 #include "third_party/skia/include/core/SkCanvas.h" |
| 24 #include "third_party/skia/include/core/SkPicture.h" | 25 #include "third_party/skia/include/core/SkPicture.h" |
| 25 #include "third_party/skia/include/core/SkPictureRecorder.h" | 26 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 26 #include "ui/gfx/geometry/scroll_offset.h" | 27 #include "ui/gfx/geometry/scroll_offset.h" |
| 27 #include "ui/gfx/geometry/vector2d_conversions.h" | 28 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 28 | 29 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 BrowserViewRenderer* BrowserViewRenderer::FromWebContents( | 82 BrowserViewRenderer* BrowserViewRenderer::FromWebContents( |
| 82 content::WebContents* web_contents) { | 83 content::WebContents* web_contents) { |
| 83 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); | 84 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); |
| 84 } | 85 } |
| 85 | 86 |
| 86 BrowserViewRenderer::BrowserViewRenderer( | 87 BrowserViewRenderer::BrowserViewRenderer( |
| 87 BrowserViewRendererClient* client, | 88 BrowserViewRendererClient* client, |
| 88 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 89 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 89 bool disable_page_visibility) | 90 bool disable_page_visibility) |
| 90 : client_(client), | 91 : client_(client), |
| 91 shared_renderer_state_(ui_task_runner, this), | |
| 92 ui_task_runner_(ui_task_runner), | 92 ui_task_runner_(ui_task_runner), |
| 93 disable_page_visibility_(disable_page_visibility), | 93 disable_page_visibility_(disable_page_visibility), |
| 94 compositor_(NULL), | 94 compositor_(NULL), |
| 95 is_paused_(false), | 95 is_paused_(false), |
| 96 view_visible_(false), | 96 view_visible_(false), |
| 97 window_visible_(false), | 97 window_visible_(false), |
| 98 attached_to_window_(false), | 98 attached_to_window_(false), |
| 99 hardware_enabled_(false), | 99 hardware_enabled_(false), |
| 100 dip_scale_(0.f), | 100 dip_scale_(0.f), |
| 101 page_scale_factor_(1.f), | 101 page_scale_factor_(1.f), |
| 102 min_page_scale_factor_(0.f), | 102 min_page_scale_factor_(0.f), |
| 103 max_page_scale_factor_(0.f), | 103 max_page_scale_factor_(0.f), |
| 104 on_new_picture_enable_(false), | 104 on_new_picture_enable_(false), |
| 105 clear_view_(false), | 105 clear_view_(false), |
| 106 offscreen_pre_raster_(false), | 106 offscreen_pre_raster_(false), |
| 107 next_compositor_id_(1) {} | 107 next_compositor_id_(1) {} |
| 108 | 108 |
| 109 BrowserViewRenderer::~BrowserViewRenderer() { | 109 BrowserViewRenderer::~BrowserViewRenderer() { |
| 110 DCHECK(compositor_map_.empty()); | 110 DCHECK(compositor_map_.empty()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void BrowserViewRenderer::RegisterWithWebContents( | 113 void BrowserViewRenderer::RegisterWithWebContents( |
| 114 content::WebContents* web_contents) { | 114 content::WebContents* web_contents) { |
| 115 web_contents->SetUserData(kBrowserViewRendererUserDataKey, | 115 web_contents->SetUserData(kBrowserViewRendererUserDataKey, |
| 116 new BrowserViewRendererUserData(this)); | 116 new BrowserViewRendererUserData(this)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 SharedRendererState* BrowserViewRenderer::GetAwDrawGLViewContext() { | 119 void BrowserViewRenderer::TrimMemory(const int level) { |
|
boliu
2016/03/24 17:34:45
don't need to take level at all now
| |
| 120 return &shared_renderer_state_; | |
| 121 } | |
| 122 | |
| 123 bool BrowserViewRenderer::RequestDrawGL(bool wait_for_completion) { | |
| 124 return client_->RequestDrawGL(wait_for_completion); | |
| 125 } | |
| 126 | |
| 127 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { | |
| 128 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 120 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 129 // Constants from Android ComponentCallbacks2. | |
| 130 enum { | |
| 131 TRIM_MEMORY_RUNNING_LOW = 10, | |
| 132 TRIM_MEMORY_UI_HIDDEN = 20, | |
| 133 TRIM_MEMORY_BACKGROUND = 40, | |
| 134 TRIM_MEMORY_MODERATE = 60, | |
| 135 }; | |
| 136 | |
| 137 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because | |
| 138 // it does not indicate memory pressure, but merely that the app is | |
| 139 // backgrounded. | |
| 140 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) | |
| 141 return; | |
| 142 | |
| 143 // Do not release resources on view we expect to get DrawGL soon. | |
| 144 if (level < TRIM_MEMORY_BACKGROUND && visible) | |
| 145 return; | |
| 146 | |
| 147 // Nothing to drop. | 121 // Nothing to drop. |
| 148 if (!compositor_ || !hardware_enabled_) | 122 if (!compositor_ || !hardware_enabled_) |
| 149 return; | 123 return; |
| 150 | 124 |
| 151 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); | 125 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); |
| 152 | 126 |
| 153 // If offscreen pre-raster is disabled, drop everything in hardware. Otherwise | |
| 154 // keep the tiles and just delete the HardwareRenderer. | |
| 155 if (level >= TRIM_MEMORY_MODERATE) { | |
| 156 if (offscreen_pre_raster_) | |
| 157 shared_renderer_state_.DeleteHardwareRendererOnUI(); | |
| 158 else | |
| 159 shared_renderer_state_.ReleaseHardwareDrawIfNeededOnUI(); | |
| 160 return; | |
| 161 } | |
| 162 | |
| 163 // Just set the memory limit to 0 and drop all tiles. This will be reset to | 127 // Just set the memory limit to 0 and drop all tiles. This will be reset to |
| 164 // normal levels in the next DrawGL call. | 128 // normal levels in the next DrawGL call. |
| 165 // TODO(hush): need to setMemoryPolicy to 0 for non-current compositors too. | 129 // TODO(hush): need to setMemoryPolicy to 0 for non-current compositors too. |
| 166 // But WebView only has non-current compositors temporarily. So don't have to | 130 // But WebView only has non-current compositors temporarily. So don't have to |
| 167 // do it now. | 131 // do it now. |
| 168 if (!offscreen_pre_raster_) | 132 if (!offscreen_pre_raster_) |
| 169 compositor_->SetMemoryPolicy(0u); | 133 compositor_->SetMemoryPolicy(0u); |
| 170 } | 134 } |
| 171 | 135 |
| 172 void BrowserViewRenderer::UpdateMemoryPolicy() { | 136 void BrowserViewRenderer::UpdateMemoryPolicy() { |
| 137 if (!compositor_) { | |
| 138 return; | |
| 139 } | |
| 140 | |
| 173 if (!hardware_enabled_) { | 141 if (!hardware_enabled_) { |
| 174 compositor_->SetMemoryPolicy(0u); | 142 compositor_->SetMemoryPolicy(0u); |
| 175 return; | 143 return; |
| 176 } | 144 } |
| 177 | 145 |
| 178 size_t bytes_limit = 0u; | 146 size_t bytes_limit = 0u; |
| 179 if (g_memory_override_in_bytes) { | 147 if (g_memory_override_in_bytes) { |
| 180 bytes_limit = static_cast<size_t>(g_memory_override_in_bytes); | 148 bytes_limit = static_cast<size_t>(g_memory_override_in_bytes); |
| 181 } else { | 149 } else { |
| 182 ParentCompositorDrawConstraints parent_draw_constraints = | |
| 183 shared_renderer_state_.GetParentDrawConstraintsOnUI(); | |
| 184 gfx::Rect interest_rect = | 150 gfx::Rect interest_rect = |
| 185 offscreen_pre_raster_ || parent_draw_constraints.is_layer | 151 offscreen_pre_raster_ || external_draw_constraints_.is_layer |
| 186 ? gfx::Rect(size_) | 152 ? gfx::Rect(size_) |
| 187 : last_on_draw_global_visible_rect_; | 153 : last_on_draw_global_visible_rect_; |
| 188 size_t width = interest_rect.width(); | 154 size_t width = interest_rect.width(); |
| 189 size_t height = interest_rect.height(); | 155 size_t height = interest_rect.height(); |
| 190 bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; | 156 bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; |
| 191 // Round up to a multiple of kMemoryAllocationStep. | 157 // Round up to a multiple of kMemoryAllocationStep. |
| 192 bytes_limit = | 158 bytes_limit = |
| 193 (bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; | 159 (bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; |
| 194 } | 160 } |
| 195 | 161 |
| 196 compositor_->SetMemoryPolicy(bytes_limit); | 162 compositor_->SetMemoryPolicy(bytes_limit); |
| 197 } | 163 } |
| 198 | 164 |
| 199 void BrowserViewRenderer::PrepareToDraw(const gfx::Vector2d& scroll, | 165 void BrowserViewRenderer::PrepareToDraw(const gfx::Rect& global_visible_rect) { |
| 200 const gfx::Rect& global_visible_rect) { | |
| 201 last_on_draw_scroll_offset_ = scroll; | |
| 202 last_on_draw_global_visible_rect_ = global_visible_rect; | 166 last_on_draw_global_visible_rect_ = global_visible_rect; |
| 203 } | 167 } |
| 204 | 168 |
| 205 bool BrowserViewRenderer::CanOnDraw() { | 169 bool BrowserViewRenderer::CanOnDraw() { |
| 206 if (!compositor_) { | 170 if (!compositor_) { |
| 207 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_NoCompositor", | 171 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_NoCompositor", |
| 208 TRACE_EVENT_SCOPE_THREAD); | 172 TRACE_EVENT_SCOPE_THREAD); |
| 209 return false; | 173 return false; |
| 210 } | 174 } |
| 211 if (clear_view_) { | 175 if (clear_view_) { |
| 212 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", | 176 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", |
| 213 TRACE_EVENT_SCOPE_THREAD); | 177 TRACE_EVENT_SCOPE_THREAD); |
| 214 return false; | 178 return false; |
| 215 } | 179 } |
| 216 | 180 |
| 217 return true; | 181 return true; |
| 218 } | 182 } |
| 219 | 183 |
| 220 bool BrowserViewRenderer::OnDrawHardware() { | 184 scoped_ptr<ChildFrame> BrowserViewRenderer::OnDrawHardware() { |
| 221 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); | 185 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
| 222 | 186 |
| 223 shared_renderer_state_.InitializeHardwareDrawIfNeededOnUI(); | 187 LOG(WARNING) << "XXX me=" << ToString(); |
| 224 | |
| 225 if (!CanOnDraw()) { | 188 if (!CanOnDraw()) { |
| 226 return false; | 189 LOG(WARNING) << "XXX CanOnDraw returned false"; |
| 190 return nullptr; | |
| 227 } | 191 } |
| 228 | 192 |
| 229 shared_renderer_state_.SetScrollOffsetOnUI(last_on_draw_scroll_offset_); | |
| 230 hardware_enabled_ = true; | 193 hardware_enabled_ = true; |
| 231 | 194 |
| 232 ReturnResourceFromParent(); | |
| 233 UpdateMemoryPolicy(); | |
| 234 | |
| 235 ParentCompositorDrawConstraints parent_draw_constraints = | |
| 236 shared_renderer_state_.GetParentDrawConstraintsOnUI(); | |
| 237 gfx::Size surface_size(size_); | 195 gfx::Size surface_size(size_); |
| 238 gfx::Rect viewport(surface_size); | 196 gfx::Rect viewport(surface_size); |
| 239 gfx::Rect clip = viewport; | 197 gfx::Rect clip = viewport; |
| 240 gfx::Transform transform_for_tile_priority = | 198 gfx::Transform transform_for_tile_priority = |
| 241 parent_draw_constraints.transform; | 199 external_draw_constraints_.transform; |
| 242 | 200 |
| 243 // If the WebView is on a layer, WebView does not know what transform is | 201 // If the WebView is on a layer, WebView does not know what transform is |
| 244 // applied onto the layer so global visible rect does not make sense here. | 202 // applied onto the layer so global visible rect does not make sense here. |
| 245 // In this case, just use the surface rect for tiling. | 203 // In this case, just use the surface rect for tiling. |
| 246 gfx::Rect viewport_rect_for_tile_priority; | 204 gfx::Rect viewport_rect_for_tile_priority; |
| 247 | 205 |
| 248 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. | 206 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
| 249 if (!offscreen_pre_raster_ && !parent_draw_constraints.is_layer) { | 207 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
| 250 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 208 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
| 251 } | 209 } |
| 252 | 210 |
| 253 content::SynchronousCompositor::Frame frame = | 211 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( |
| 254 compositor_->DemandDrawHw(surface_size, | 212 surface_size, gfx::Transform(), viewport, clip, |
| 255 gfx::Transform(), | 213 viewport_rect_for_tile_priority, transform_for_tile_priority); |
| 256 viewport, | 214 |
| 257 clip, | |
| 258 viewport_rect_for_tile_priority, | |
| 259 transform_for_tile_priority); | |
| 260 if (!frame.frame.get()) { | 215 if (!frame.frame.get()) { |
| 261 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", | 216 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", |
| 262 TRACE_EVENT_SCOPE_THREAD); | 217 TRACE_EVENT_SCOPE_THREAD); |
| 263 return shared_renderer_state_.HasFrameOnUI(); | 218 return nullptr; |
| 264 } | 219 } |
| 265 | 220 |
| 266 scoped_ptr<ChildFrame> child_frame = make_scoped_ptr(new ChildFrame( | 221 return make_scoped_ptr(new ChildFrame( |
| 267 frame.output_surface_id, std::move(frame.frame), | 222 frame.output_surface_id, std::move(frame.frame), |
| 268 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), | 223 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), |
| 269 transform_for_tile_priority, offscreen_pre_raster_, | 224 transform_for_tile_priority, offscreen_pre_raster_, |
| 270 parent_draw_constraints.is_layer)); | 225 external_draw_constraints_.is_layer)); |
| 271 | |
| 272 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); | |
| 273 shared_renderer_state_.SetCompositorFrameOnUI(std::move(child_frame)); | |
| 274 return true; | |
| 275 } | 226 } |
| 276 | 227 |
| 277 void BrowserViewRenderer::UpdateParentDrawConstraints() { | 228 void BrowserViewRenderer::UpdateParentDrawConstraints( |
| 229 const ParentCompositorDrawConstraints& external_draw_constraints) { | |
| 278 PostInvalidate(); | 230 PostInvalidate(); |
| 279 ParentCompositorDrawConstraints parent_draw_constraints = | 231 external_draw_constraints_ = external_draw_constraints; |
| 280 shared_renderer_state_.GetParentDrawConstraintsOnUI(); | 232 UpdateMemoryPolicy(); |
| 281 client_->ParentDrawConstraintsUpdated(parent_draw_constraints); | |
| 282 } | 233 } |
| 283 | 234 |
| 284 void BrowserViewRenderer::ReturnUnusedResource( | 235 void BrowserViewRenderer::ReturnUnusedResource( |
| 285 scoped_ptr<ChildFrame> child_frame) { | 236 scoped_ptr<ChildFrame> child_frame) { |
| 286 if (!child_frame.get() || !child_frame->frame.get()) | 237 if (!child_frame.get() || !child_frame->frame.get()) |
| 287 return; | 238 return; |
| 288 | 239 |
| 289 cc::CompositorFrameAck frame_ack; | 240 cc::ReturnedResourceArray returned_resources; |
| 290 cc::TransferableResource::ReturnResources( | 241 cc::TransferableResource::ReturnResources( |
| 291 child_frame->frame->delegated_frame_data->resource_list, | 242 child_frame->frame->delegated_frame_data->resource_list, |
| 292 &frame_ack.resources); | 243 &returned_resources); |
| 293 content::SynchronousCompositor* compositor = | 244 ReturnResourceFromParent(child_frame->compositor_id, |
| 294 compositor_map_[child_frame->compositor_id]; | 245 child_frame->output_surface_id, &returned_resources); |
| 295 if (compositor && !frame_ack.resources.empty()) | |
| 296 compositor->ReturnResources(child_frame->output_surface_id, frame_ack); | |
| 297 } | 246 } |
| 298 | 247 |
| 299 void BrowserViewRenderer::ReturnResourceFromParent() { | 248 void BrowserViewRenderer::ReturnResourceFromParent( |
| 300 SharedRendererState::ReturnedResourcesMap returned_resource_map; | 249 uint32_t compositor_id, |
| 301 shared_renderer_state_.SwapReturnedResourcesOnUI(&returned_resource_map); | 250 uint32_t output_surface_id, |
| 302 for (auto iterator = returned_resource_map.begin(); | 251 cc::ReturnedResourceArray* resources) { |
| 303 iterator != returned_resource_map.end(); iterator++) { | 252 content::SynchronousCompositor* compositor = compositor_map_[compositor_id]; |
| 304 uint32_t compositor_id = iterator->first; | 253 cc::CompositorFrameAck frame_ack; |
| 305 content::SynchronousCompositor* compositor = compositor_map_[compositor_id]; | 254 frame_ack.resources.swap(*resources); |
| 306 cc::CompositorFrameAck frame_ack; | 255 if (compositor && !frame_ack.resources.empty()) { |
| 307 frame_ack.resources.swap(iterator->second.resources); | 256 compositor->ReturnResources(output_surface_id, frame_ack); |
| 308 | |
| 309 if (compositor && !frame_ack.resources.empty()) { | |
| 310 compositor->ReturnResources(iterator->second.output_surface_id, | |
| 311 frame_ack); | |
| 312 } | |
| 313 } | 257 } |
| 314 } | 258 } |
| 315 | 259 |
| 316 void BrowserViewRenderer::DetachFunctorFromView() { | |
| 317 client_->DetachFunctorFromView(); | |
| 318 } | |
| 319 | |
| 320 bool BrowserViewRenderer::OnDrawSoftware(SkCanvas* canvas) { | 260 bool BrowserViewRenderer::OnDrawSoftware(SkCanvas* canvas) { |
| 321 return CanOnDraw() && CompositeSW(canvas); | 261 return CanOnDraw() && CompositeSW(canvas); |
| 322 } | 262 } |
| 323 | 263 |
| 324 skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width, | 264 skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width, |
| 325 int height) { | 265 int height) { |
| 326 TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture"); | 266 TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture"); |
| 327 | 267 |
| 328 // Return empty Picture objects for empty SkPictures. | 268 // Return empty Picture objects for empty SkPictures. |
| 329 if (width <= 0 || height <= 0) { | 269 if (width <= 0 || height <= 0) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 357 TRACE_EVENT_SCOPE_THREAD); | 297 TRACE_EVENT_SCOPE_THREAD); |
| 358 if (clear_view_) | 298 if (clear_view_) |
| 359 return; | 299 return; |
| 360 | 300 |
| 361 clear_view_ = true; | 301 clear_view_ = true; |
| 362 // Always invalidate ignoring the compositor to actually clear the webview. | 302 // Always invalidate ignoring the compositor to actually clear the webview. |
| 363 PostInvalidate(); | 303 PostInvalidate(); |
| 364 } | 304 } |
| 365 | 305 |
| 366 void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { | 306 void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { |
| 367 if (offscreen_pre_raster_ != enable && compositor_) | |
| 368 UpdateMemoryPolicy(); | |
| 369 | |
| 370 offscreen_pre_raster_ = enable; | 307 offscreen_pre_raster_ = enable; |
| 308 UpdateMemoryPolicy(); | |
| 371 } | 309 } |
| 372 | 310 |
| 373 void BrowserViewRenderer::SetIsPaused(bool paused) { | 311 void BrowserViewRenderer::SetIsPaused(bool paused) { |
| 374 TRACE_EVENT_INSTANT1("android_webview", | 312 TRACE_EVENT_INSTANT1("android_webview", |
| 375 "BrowserViewRenderer::SetIsPaused", | 313 "BrowserViewRenderer::SetIsPaused", |
| 376 TRACE_EVENT_SCOPE_THREAD, | 314 TRACE_EVENT_SCOPE_THREAD, |
| 377 "paused", | 315 "paused", |
| 378 paused); | 316 paused); |
| 379 is_paused_ = paused; | 317 is_paused_ = paused; |
| 380 UpdateCompositorIsActive(); | 318 UpdateCompositorIsActive(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 401 | 339 |
| 402 void BrowserViewRenderer::OnSizeChanged(int width, int height) { | 340 void BrowserViewRenderer::OnSizeChanged(int width, int height) { |
| 403 TRACE_EVENT_INSTANT2("android_webview", | 341 TRACE_EVENT_INSTANT2("android_webview", |
| 404 "BrowserViewRenderer::OnSizeChanged", | 342 "BrowserViewRenderer::OnSizeChanged", |
| 405 TRACE_EVENT_SCOPE_THREAD, | 343 TRACE_EVENT_SCOPE_THREAD, |
| 406 "width", | 344 "width", |
| 407 width, | 345 width, |
| 408 "height", | 346 "height", |
| 409 height); | 347 height); |
| 410 size_.SetSize(width, height); | 348 size_.SetSize(width, height); |
| 349 if (offscreen_pre_raster_) | |
| 350 UpdateMemoryPolicy(); | |
| 411 } | 351 } |
| 412 | 352 |
| 413 void BrowserViewRenderer::OnAttachedToWindow(int width, int height) { | 353 void BrowserViewRenderer::OnAttachedToWindow(int width, int height) { |
| 414 TRACE_EVENT2("android_webview", | 354 TRACE_EVENT2("android_webview", |
| 415 "BrowserViewRenderer::OnAttachedToWindow", | 355 "BrowserViewRenderer::OnAttachedToWindow", |
| 416 "width", | 356 "width", |
| 417 width, | 357 width, |
| 418 "height", | 358 "height", |
| 419 height); | 359 height); |
| 420 attached_to_window_ = true; | 360 attached_to_window_ = true; |
| 421 size_.SetSize(width, height); | 361 size_.SetSize(width, height); |
| 362 if (offscreen_pre_raster_) | |
| 363 UpdateMemoryPolicy(); | |
| 422 UpdateCompositorIsActive(); | 364 UpdateCompositorIsActive(); |
| 423 } | 365 } |
| 424 | 366 |
| 425 void BrowserViewRenderer::OnDetachedFromWindow() { | 367 void BrowserViewRenderer::OnDetachedFromWindow() { |
| 426 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); | 368 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); |
| 427 shared_renderer_state_.ReleaseHardwareDrawIfNeededOnUI(); | 369 if (compositor_) { |
| 370 compositor_->SetMemoryPolicy(0u); | |
| 371 } | |
| 372 | |
| 373 hardware_enabled_ = false; | |
|
boliu
2016/03/24 17:34:45
Feels like this should be
hardware_enabled_ = fal
| |
| 428 attached_to_window_ = false; | 374 attached_to_window_ = false; |
| 429 DCHECK(!hardware_enabled_); | |
| 430 UpdateCompositorIsActive(); | 375 UpdateCompositorIsActive(); |
| 431 } | 376 } |
| 432 | 377 |
| 433 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { | 378 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { |
| 434 if (!compositor_) | 379 if (!compositor_) |
| 435 return; | 380 return; |
| 436 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); | 381 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); |
| 437 compositor_->OnComputeScroll(animation_time); | 382 compositor_->OnComputeScroll(animation_time); |
| 438 } | 383 } |
| 439 | 384 |
| 440 void BrowserViewRenderer::ReleaseHardware() { | |
| 441 DCHECK(hardware_enabled_); | |
| 442 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); | |
| 443 ReturnResourceFromParent(); | |
| 444 DCHECK(shared_renderer_state_.ReturnedResourcesEmptyOnUI()); | |
| 445 | |
| 446 if (compositor_) { | |
| 447 compositor_->SetMemoryPolicy(0u); | |
| 448 } | |
| 449 | |
| 450 hardware_enabled_ = false; | |
| 451 } | |
| 452 | |
| 453 bool BrowserViewRenderer::IsVisible() const { | 385 bool BrowserViewRenderer::IsVisible() const { |
| 454 // Ignore |window_visible_| if |attached_to_window_| is false. | 386 // Ignore |window_visible_| if |attached_to_window_| is false. |
| 455 return view_visible_ && (!attached_to_window_ || window_visible_); | 387 return view_visible_ && (!attached_to_window_ || window_visible_); |
| 456 } | 388 } |
| 457 | 389 |
| 458 bool BrowserViewRenderer::IsClientVisible() const { | 390 bool BrowserViewRenderer::IsClientVisible() const { |
| 459 if (disable_page_visibility_) | 391 if (disable_page_visibility_) |
| 460 return !is_paused_; | 392 return !is_paused_; |
| 461 | 393 |
| 462 return !is_paused_ && (!attached_to_window_ || window_visible_); | 394 return !is_paused_ && (!attached_to_window_ || window_visible_); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 } | 623 } |
| 692 | 624 |
| 693 void BrowserViewRenderer::PostInvalidate() { | 625 void BrowserViewRenderer::PostInvalidate() { |
| 694 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", | 626 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", |
| 695 TRACE_EVENT_SCOPE_THREAD); | 627 TRACE_EVENT_SCOPE_THREAD); |
| 696 client_->PostInvalidate(); | 628 client_->PostInvalidate(); |
| 697 } | 629 } |
| 698 | 630 |
| 699 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { | 631 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { |
| 700 DCHECK(compositor_); | 632 DCHECK(compositor_); |
| 701 ReturnResourceFromParent(); | |
| 702 return compositor_->DemandDrawSw(canvas); | 633 return compositor_->DemandDrawSw(canvas); |
| 703 } | 634 } |
| 704 | 635 |
| 705 void BrowserViewRenderer::UpdateCompositorIsActive() { | 636 void BrowserViewRenderer::UpdateCompositorIsActive() { |
| 706 if (compositor_) { | 637 if (compositor_) { |
| 707 compositor_->SetIsActive(!is_paused_ && | 638 compositor_->SetIsActive(!is_paused_ && |
| 708 (!attached_to_window_ || window_visible_)); | 639 (!attached_to_window_ || window_visible_)); |
| 709 } | 640 } |
| 710 } | 641 } |
| 711 | 642 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 726 base::StringAppendF(&str, | 657 base::StringAppendF(&str, |
| 727 "overscroll_rounding_error_: %s ", | 658 "overscroll_rounding_error_: %s ", |
| 728 overscroll_rounding_error_.ToString().c_str()); | 659 overscroll_rounding_error_.ToString().c_str()); |
| 729 base::StringAppendF( | 660 base::StringAppendF( |
| 730 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 661 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 731 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 662 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
| 732 return str; | 663 return str; |
| 733 } | 664 } |
| 734 | 665 |
| 735 } // namespace android_webview | 666 } // namespace android_webview |
| OLD | NEW |