Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/native/aw_contents.h" | 5 #include "android_webview/native/aw_contents.h" |
| 6 | 6 |
| 7 #include <sys/system_properties.h> | 7 #include <sys/system_properties.h> |
| 8 | 8 |
| 9 #include "android_webview/browser/aw_browser_main_parts.h" | 9 #include "android_webview/browser/aw_browser_main_parts.h" |
| 10 #include "android_webview/browser/net_disk_cache_remover.h" | 10 #include "android_webview/browser/net_disk_cache_remover.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 AwContents::AwContents(JNIEnv* env, | 153 AwContents::AwContents(JNIEnv* env, |
| 154 jobject obj, | 154 jobject obj, |
| 155 jobject web_contents_delegate, | 155 jobject web_contents_delegate, |
| 156 bool private_browsing) | 156 bool private_browsing) |
| 157 : java_ref_(env, obj), | 157 : java_ref_(env, obj), |
| 158 web_contents_delegate_( | 158 web_contents_delegate_( |
| 159 new AwWebContentsDelegate(env, web_contents_delegate)), | 159 new AwWebContentsDelegate(env, web_contents_delegate)), |
| 160 view_visible_(false), | 160 view_visible_(false), |
| 161 compositor_visible_(false), | 161 compositor_visible_(false), |
| 162 is_composite_pending_(false), | 162 is_composite_pending_(false), |
| 163 last_scroll_x_(0), last_scroll_y_(0), | |
| 164 last_frame_context_(NULL) { | 163 last_frame_context_(NULL) { |
| 165 RendererPictureMap::CreateInstance(); | 164 RendererPictureMap::CreateInstance(); |
| 166 android_webview::AwBrowserDependencyFactory* dependency_factory = | 165 android_webview::AwBrowserDependencyFactory* dependency_factory = |
| 167 android_webview::AwBrowserDependencyFactory::GetInstance(); | 166 android_webview::AwBrowserDependencyFactory::GetInstance(); |
| 168 | 167 |
| 169 // TODO(joth): rather than create and set the WebContents here, expose the | 168 // TODO(joth): rather than create and set the WebContents here, expose the |
| 170 // factory method to java side and have that orchestrate the construction | 169 // factory method to java side and have that orchestrate the construction |
| 171 // order. | 170 // order. |
| 172 SetWebContents(dependency_factory->CreateWebContents(private_browsing)); | 171 SetWebContents(dependency_factory->CreateWebContents(private_browsing)); |
| 173 } | 172 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 LOG(WARNING) << "No current context attached. Skipping composite."; | 305 LOG(WARNING) << "No current context attached. Skipping composite."; |
| 307 return; | 306 return; |
| 308 } | 307 } |
| 309 | 308 |
| 310 if (last_frame_context_ != current_context) { | 309 if (last_frame_context_ != current_context) { |
| 311 if (last_frame_context_) | 310 if (last_frame_context_) |
| 312 ResetCompositor(); | 311 ResetCompositor(); |
| 313 last_frame_context_ = current_context; | 312 last_frame_context_ = current_context; |
| 314 } | 313 } |
| 315 | 314 |
| 316 gfx::Transform transform; | |
| 317 compositor_->SetWindowBounds(gfx::Size(draw_info->width, draw_info->height)); | 315 compositor_->SetWindowBounds(gfx::Size(draw_info->width, draw_info->height)); |
| 318 | 316 |
| 319 if (draw_info->is_layer) { | 317 if (draw_info->is_layer) { |
| 320 // When rendering into a separate layer no view clipping, transform, | 318 // When rendering into a separate layer no view clipping, transform, |
| 321 // scissoring or background transparency need to be handled. | 319 // scissoring or background transparency need to be handled. |
| 322 // The Android framework will composite us afterwards. | 320 // The Android framework will composite us afterwards. |
| 323 compositor_->SetHasTransparentBackground(false); | 321 compositor_->SetHasTransparentBackground(false); |
| 324 view_clip_layer_->setMasksToBounds(false); | 322 view_clip_layer_->setMasksToBounds(false); |
| 323 transform_layer_->setTransform(gfx::Transform()); | |
| 325 scissor_clip_layer_->setMasksToBounds(false); | 324 scissor_clip_layer_->setMasksToBounds(false); |
| 326 scissor_clip_layer_->setPosition(gfx::PointF()); | 325 scissor_clip_layer_->setPosition(gfx::PointF()); |
| 327 scissor_clip_layer_->setBounds(gfx::Size()); | 326 scissor_clip_layer_->setBounds(gfx::Size()); |
| 328 scissor_clip_layer_->setSublayerTransform(gfx::Transform()); | 327 scissor_clip_layer_->setSublayerTransform(gfx::Transform()); |
| 329 | 328 |
| 330 } else { | 329 } else { |
| 331 compositor_->SetHasTransparentBackground(true); | 330 compositor_->SetHasTransparentBackground(true); |
| 332 | 331 |
| 333 gfx::Rect clip_rect(draw_info->clip_left, draw_info->clip_top, | 332 gfx::Rect clip_rect(draw_info->clip_left, draw_info->clip_top, |
| 334 draw_info->clip_right - draw_info->clip_left, | 333 draw_info->clip_right - draw_info->clip_left, |
| 335 draw_info->clip_bottom - draw_info->clip_top); | 334 draw_info->clip_bottom - draw_info->clip_top); |
| 336 | 335 |
| 337 scissor_clip_layer_->setPosition(clip_rect.origin()); | 336 scissor_clip_layer_->setPosition(clip_rect.origin()); |
| 338 scissor_clip_layer_->setBounds(clip_rect.size()); | 337 scissor_clip_layer_->setBounds(clip_rect.size()); |
| 339 scissor_clip_layer_->setMasksToBounds(true); | 338 scissor_clip_layer_->setMasksToBounds(true); |
| 340 | 339 |
| 341 // The compositor clipping architecture enforces us to have the clip layer | 340 // The compositor clipping architecture enforces us to have the clip layer |
| 342 // as an ancestor of the area we want to clip, but this makes the transform | 341 // as an ancestor of the area we want to clip, but this makes the transform |
| 343 // become relative to the clip area rather than the full surface. The clip | 342 // become relative to the clip area rather than the full surface. The clip |
| 344 // position offset needs to be undone before applying the transform. | 343 // position offset needs to be undone before applying the transform. |
| 345 gfx::Transform undo_clip_position; | 344 gfx::Transform undo_clip_position; |
| 346 undo_clip_position.Translate(-clip_rect.x(), -clip_rect.y()); | 345 undo_clip_position.Translate(-clip_rect.x(), -clip_rect.y()); |
| 347 scissor_clip_layer_->setSublayerTransform(undo_clip_position); | 346 scissor_clip_layer_->setSublayerTransform(undo_clip_position); |
| 348 | 347 |
| 348 gfx::Transform transform; | |
| 349 transform.matrix().setColMajorf(draw_info->transform); | 349 transform.matrix().setColMajorf(draw_info->transform); |
| 350 | |
| 351 // The scrolling values of the Android Framework affect the transformation | |
| 352 // matrix. This needs to be undone to let the compositor handle scrolling. | |
| 353 transform.Translate(hw_rendering_scroll_.x(), hw_rendering_scroll_.y()); | |
| 354 transform_layer_->setTransform(transform); | |
| 355 | |
| 350 view_clip_layer_->setMasksToBounds(true); | 356 view_clip_layer_->setMasksToBounds(true); |
| 351 } | 357 } |
| 352 | 358 |
| 353 // The scrolling values of the Android Framework affect the transformation | |
| 354 // matrix. This needs to be undone to let the compositor handle scrolling. | |
| 355 transform.Translate(last_scroll_x_, last_scroll_y_); | |
| 356 transform_layer_->setTransform(transform); | |
| 357 | |
| 358 compositor_->Composite(); | 359 compositor_->Composite(); |
| 359 is_composite_pending_ = false; | 360 is_composite_pending_ = false; |
| 360 | 361 |
| 361 // TODO(leandrogracia): remove when crbug.com/164140 is closed. | 362 // TODO(leandrogracia): remove when crbug.com/164140 is closed. |
| 362 // --------------------------------------------------------------------------- | 363 // --------------------------------------------------------------------------- |
| 363 char no_gl_restore_prop[PROP_VALUE_MAX]; | 364 char no_gl_restore_prop[PROP_VALUE_MAX]; |
| 364 __system_property_get("webview.chromium_no_gl_restore", no_gl_restore_prop); | 365 __system_property_get("webview.chromium_no_gl_restore", no_gl_restore_prop); |
| 365 if (!strcmp(no_gl_restore_prop, "true")) { | 366 if (!strcmp(no_gl_restore_prop, "true")) { |
| 366 LOG(WARNING) << "Android GL functor not restoring the previous GL state."; | 367 LOG(WARNING) << "Android GL functor not restoring the previous GL state."; |
| 367 } else { | 368 } else { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 glDisable(GL_SCISSOR_TEST); | 415 glDisable(GL_SCISSOR_TEST); |
| 415 | 416 |
| 416 glScissor(scissor_box[0], scissor_box[1], scissor_box[2], | 417 glScissor(scissor_box[0], scissor_box[1], scissor_box[2], |
| 417 scissor_box[3]); | 418 scissor_box[3]); |
| 418 | 419 |
| 419 glUseProgram(current_program); | 420 glUseProgram(current_program); |
| 420 } | 421 } |
| 421 // --------------------------------------------------------------------------- | 422 // --------------------------------------------------------------------------- |
| 422 } | 423 } |
| 423 | 424 |
| 424 bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) { | 425 bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas, |
| 426 jint scroll_x, jint scroll_y) { | |
| 425 scoped_refptr<cc::PicturePileImpl> picture = | 427 scoped_refptr<cc::PicturePileImpl> picture = |
| 426 RendererPictureMap::GetInstance()->GetRendererPicture( | 428 RendererPictureMap::GetInstance()->GetRendererPicture( |
| 427 web_contents_->GetRoutingID()); | 429 web_contents_->GetRoutingID()); |
| 428 if (!picture) | 430 if (!picture) |
| 429 return false; | 431 return false; |
| 430 | 432 |
| 431 AwPixelInfo* pixels; | 433 AwPixelInfo* pixels; |
| 432 if (!g_draw_sw_functions || | 434 if (!g_draw_sw_functions || |
| 433 (pixels = g_draw_sw_functions->access_pixels(env, java_canvas)) == NULL) { | 435 (pixels = g_draw_sw_functions->access_pixels(env, java_canvas)) == NULL) { |
| 434 // TODO(joth): Fall back to slow path rendering via temporary bitmap. | 436 // TODO(joth): Fall back to slow path rendering via temporary bitmap. |
| 435 return false; | 437 return false; |
| 436 } | 438 } |
| 437 | 439 |
| 438 { | 440 { |
| 439 SkBitmap bitmap; | 441 SkBitmap bitmap; |
| 440 bitmap.setConfig(static_cast<SkBitmap::Config>(pixels->config), | 442 bitmap.setConfig(static_cast<SkBitmap::Config>(pixels->config), |
| 441 pixels->width, | 443 pixels->width, |
| 442 pixels->height, | 444 pixels->height, |
| 443 pixels->row_bytes); | 445 pixels->row_bytes); |
| 444 bitmap.setPixels(pixels->pixels); | 446 bitmap.setPixels(pixels->pixels); |
| 445 SkDevice device(bitmap); | 447 SkDevice device(bitmap); |
| 446 SkCanvas canvas(&device); | 448 SkCanvas canvas(&device); |
| 447 SkMatrix matrix; | 449 SkMatrix matrix; |
| 448 for (int i = 0; i < 9; i++) { | 450 for (int i = 0; i < 9; i++) { |
| 449 matrix.set(i, pixels->matrix[i]); | 451 matrix.set(i, pixels->matrix[i]); |
| 450 } | 452 } |
| 451 canvas.setMatrix(matrix); | 453 canvas.setMatrix(matrix); |
| 452 | 454 |
| 455 // Scroll needs to be undone to let the Chrome compositor handle scrolling. | |
| 456 canvas.translate(scroll_x, scroll_y); | |
|
Leandro GraciĆ” Gil
2013/01/04 21:21:24
As part of the review of https://codereview.chromi
| |
| 457 | |
| 453 SkRegion clip; | 458 SkRegion clip; |
| 454 if (pixels->clip_region_size) { | 459 if (pixels->clip_region_size) { |
| 455 size_t bytes_read = clip.readFromMemory(pixels->clip_region); | 460 size_t bytes_read = clip.readFromMemory(pixels->clip_region); |
| 456 DCHECK_EQ(pixels->clip_region_size, bytes_read); | 461 DCHECK_EQ(pixels->clip_region_size, bytes_read); |
| 457 canvas.setClipRegion(clip); | 462 canvas.setClipRegion(clip); |
| 458 } else { | 463 } else { |
| 459 clip.setRect(SkIRect::MakeWH(pixels->width, pixels->height)); | 464 clip.setRect(SkIRect::MakeWH(pixels->width, pixels->height)); |
| 460 } | 465 } |
| 461 | 466 |
| 462 SkIRect sk_clip_rect = clip.getBounds(); | |
| 463 gfx::Rect clip_rect(sk_clip_rect.x(), sk_clip_rect.y(), | |
| 464 sk_clip_rect.width(), sk_clip_rect.height()); | |
| 465 | |
| 466 cc::RenderingStats stats; | 467 cc::RenderingStats stats; |
| 467 picture->Raster(&canvas, clip_rect, 1.0, &stats); | 468 gfx::Rect content_rect(scroll_x, scroll_y, view_size_.width(), |
| 469 view_size_.height()); | |
| 470 picture->Raster(&canvas, content_rect, 1.0, &stats); | |
| 468 } | 471 } |
| 469 | 472 |
| 470 g_draw_sw_functions->release_pixels(pixels); | 473 g_draw_sw_functions->release_pixels(pixels); |
| 471 return true; | 474 return true; |
| 472 } | 475 } |
| 473 | 476 |
| 474 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { | 477 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { |
| 475 return reinterpret_cast<jint>(web_contents_.get()); | 478 return reinterpret_cast<jint>(web_contents_.get()); |
| 476 } | 479 } |
| 477 | 480 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 853 | 856 |
| 854 Pickle pickle(reinterpret_cast<const char*>(state_vector.begin()), | 857 Pickle pickle(reinterpret_cast<const char*>(state_vector.begin()), |
| 855 state_vector.size()); | 858 state_vector.size()); |
| 856 PickleIterator iterator(pickle); | 859 PickleIterator iterator(pickle); |
| 857 | 860 |
| 858 return RestoreFromPickle(&iterator, web_contents_.get()); | 861 return RestoreFromPickle(&iterator, web_contents_.get()); |
| 859 } | 862 } |
| 860 | 863 |
| 861 void AwContents::SetScrollForHWFrame(JNIEnv* env, jobject obj, | 864 void AwContents::SetScrollForHWFrame(JNIEnv* env, jobject obj, |
| 862 int scroll_x, int scroll_y) { | 865 int scroll_x, int scroll_y) { |
| 863 last_scroll_x_ = scroll_x; | 866 hw_rendering_scroll_ = gfx::Point(scroll_x, scroll_y); |
| 864 last_scroll_y_ = scroll_y; | |
| 865 } | 867 } |
| 866 | 868 |
| 867 void AwContents::SetPendingWebContentsForPopup( | 869 void AwContents::SetPendingWebContentsForPopup( |
| 868 scoped_ptr<content::WebContents> pending) { | 870 scoped_ptr<content::WebContents> pending) { |
| 869 if (pending_contents_.get()) { | 871 if (pending_contents_.get()) { |
| 870 // TODO(benm): Support holding multiple pop up window requests. | 872 // TODO(benm): Support holding multiple pop up window requests. |
| 871 LOG(WARNING) << "Blocking popup window creation as an outstanding " | 873 LOG(WARNING) << "Blocking popup window creation as an outstanding " |
| 872 << "popup window is still pending."; | 874 << "popup window is still pending."; |
| 873 MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release()); | 875 MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release()); |
| 874 return; | 876 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 886 | 888 |
| 887 void AwContents::OnPictureUpdated(int process_id, int render_view_id) { | 889 void AwContents::OnPictureUpdated(int process_id, int render_view_id) { |
| 888 CHECK_EQ(web_contents_->GetRenderProcessHost()->GetID(), process_id); | 890 CHECK_EQ(web_contents_->GetRenderProcessHost()->GetID(), process_id); |
| 889 if (render_view_id != web_contents_->GetRoutingID()) | 891 if (render_view_id != web_contents_->GetRoutingID()) |
| 890 return; | 892 return; |
| 891 | 893 |
| 892 Invalidate(); | 894 Invalidate(); |
| 893 } | 895 } |
| 894 | 896 |
| 895 } // namespace android_webview | 897 } // namespace android_webview |
| OLD | NEW |