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> | |
| 8 | |
| 9 #include "android_webview/browser/aw_browser_main_parts.h" | 7 #include "android_webview/browser/aw_browser_main_parts.h" |
| 10 #include "android_webview/browser/net_disk_cache_remover.h" | 8 #include "android_webview/browser/net_disk_cache_remover.h" |
| 11 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" | 9 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
| 12 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h" | 10 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h" |
| 11 #include "android_webview/browser/view_renderer_impl.h" | |
| 13 #include "android_webview/common/aw_hit_test_data.h" | 12 #include "android_webview/common/aw_hit_test_data.h" |
| 14 #include "android_webview/common/renderer_picture_map.h" | |
| 15 #include "android_webview/native/aw_browser_dependency_factory.h" | 13 #include "android_webview/native/aw_browser_dependency_factory.h" |
| 16 #include "android_webview/native/aw_contents_io_thread_client_impl.h" | 14 #include "android_webview/native/aw_contents_io_thread_client_impl.h" |
| 17 #include "android_webview/native/aw_web_contents_delegate.h" | 15 #include "android_webview/native/aw_web_contents_delegate.h" |
| 16 #include "android_webview/native/render_helper.h" | |
| 18 #include "android_webview/native/state_serializer.h" | 17 #include "android_webview/native/state_serializer.h" |
| 19 #include "android_webview/public/browser/draw_sw.h" | 18 #include "android_webview/public/browser/draw_gl.h" |
| 20 #include "base/android/jni_android.h" | 19 #include "base/android/jni_android.h" |
| 21 #include "base/android/jni_array.h" | 20 #include "base/android/jni_array.h" |
| 22 #include "base/android/jni_string.h" | 21 #include "base/android/jni_string.h" |
| 23 #include "base/bind.h" | 22 #include "base/bind.h" |
| 24 #include "base/callback.h" | 23 #include "base/callback.h" |
| 25 #include "base/debug/trace_event.h" | |
| 26 #include "base/message_loop.h" | 24 #include "base/message_loop.h" |
| 27 #include "base/pickle.h" | 25 #include "base/pickle.h" |
| 28 #include "base/supports_user_data.h" | 26 #include "base/supports_user_data.h" |
| 29 #include "cc/layer.h" | |
| 30 #include "content/components/navigation_interception/intercept_navigation_delega te.h" | 27 #include "content/components/navigation_interception/intercept_navigation_delega te.h" |
| 31 #include "content/public/browser/android/content_view_core.h" | 28 #include "content/public/browser/android/content_view_core.h" |
| 32 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/cert_store.h" | 30 #include "content/public/browser/cert_store.h" |
| 34 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
| 35 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/common/ssl_status.h" | 34 #include "content/public/common/ssl_status.h" |
| 38 #include "jni/AwContents_jni.h" | 35 #include "jni/AwContents_jni.h" |
| 39 #include "net/base/x509_certificate.h" | 36 #include "net/base/x509_certificate.h" |
| 40 #include "skia/ext/refptr.h" | |
| 41 #include "third_party/skia/include/core/SkBitmap.h" | |
| 42 #include "third_party/skia/include/core/SkCanvas.h" | |
| 43 #include "third_party/skia/include/core/SkDevice.h" | |
| 44 #include "third_party/skia/include/core/SkPicture.h" | |
| 45 #include "ui/gfx/transform.h" | |
| 46 #include "ui/gl/gl_bindings.h" | |
| 47 | |
| 48 // TODO(leandrogracia): remove when crbug.com/164140 is closed. | |
| 49 // Borrowed from gl2ext.h. Cannot be included due to conflicts with | |
| 50 // gl_bindings.h and the EGL library methods (eglGetCurrentContext). | |
| 51 #ifndef GL_TEXTURE_EXTERNAL_OES | |
| 52 #define GL_TEXTURE_EXTERNAL_OES 0x8D65 | |
| 53 #endif | |
| 54 | |
| 55 #ifndef GL_TEXTURE_BINDING_EXTERNAL_OES | |
| 56 #define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 | |
| 57 #endif | |
| 58 | 37 |
| 59 using base::android::AttachCurrentThread; | 38 using base::android::AttachCurrentThread; |
| 60 using base::android::ConvertJavaStringToUTF16; | 39 using base::android::ConvertJavaStringToUTF16; |
| 61 using base::android::ConvertJavaStringToUTF8; | 40 using base::android::ConvertJavaStringToUTF8; |
| 62 using base::android::ConvertUTF16ToJavaString; | 41 using base::android::ConvertUTF16ToJavaString; |
| 63 using base::android::ConvertUTF8ToJavaString; | 42 using base::android::ConvertUTF8ToJavaString; |
| 64 using base::android::JavaRef; | 43 using base::android::JavaRef; |
| 65 using base::android::ScopedJavaGlobalRef; | 44 using base::android::ScopedJavaGlobalRef; |
| 66 using base::android::ScopedJavaLocalRef; | 45 using base::android::ScopedJavaLocalRef; |
| 67 using content::BrowserThread; | 46 using content::BrowserThread; |
| 68 using content::ContentViewCore; | 47 using content::ContentViewCore; |
| 69 using content::InterceptNavigationDelegate; | 48 using content::InterceptNavigationDelegate; |
| 70 using content::WebContents; | 49 using content::WebContents; |
| 71 | 50 |
| 72 extern "C" { | 51 extern "C" { |
| 73 static AwDrawGLFunction DrawGLFunction; | 52 static AwDrawGLFunction DrawGLFunction; |
| 74 static void DrawGLFunction(int view_context, | 53 static void DrawGLFunction(int view_context, |
| 75 AwDrawGLInfo* draw_info, | 54 AwDrawGLInfo* draw_info, |
| 76 void* spare) { | 55 void* spare) { |
| 77 // |view_context| is the value that was returned from the java | 56 // |view_context| is the value that was returned from the java |
| 78 // AwContents.onPrepareDrawGL; this cast must match the code there. | 57 // AwContents.onPrepareDrawGL; this cast must match the code there. |
| 79 reinterpret_cast<android_webview::AwContents*>(view_context)->DrawGL( | 58 reinterpret_cast<android_webview::ViewRenderer*>(view_context)->DrawGL( |
| 80 draw_info); | 59 draw_info); |
| 81 } | 60 } |
| 82 } | 61 } |
| 83 | 62 |
| 84 namespace android_webview { | 63 namespace android_webview { |
| 85 | 64 |
| 86 namespace { | 65 namespace { |
| 87 | 66 |
| 88 AwDrawSWFunctionTable* g_draw_sw_functions = NULL; | 67 static RenderHelper render_helper; |
| 89 | 68 |
| 90 const void* kAwContentsUserDataKey = &kAwContentsUserDataKey; | 69 const void* kAwContentsUserDataKey = &kAwContentsUserDataKey; |
| 91 | 70 |
| 92 class AwContentsUserData : public base::SupportsUserData::Data { | 71 class AwContentsUserData : public base::SupportsUserData::Data { |
| 93 public: | 72 public: |
| 94 AwContentsUserData(AwContents* ptr) : contents_(ptr) {} | 73 AwContentsUserData(AwContents* ptr) : contents_(ptr) {} |
| 95 | 74 |
| 96 static AwContents* GetContents(WebContents* web_contents) { | 75 static AwContents* GetContents(WebContents* web_contents) { |
| 97 if (!web_contents) | 76 if (!web_contents) |
| 98 return NULL; | 77 return NULL; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 111 AwContents* AwContents::FromWebContents(WebContents* web_contents) { | 90 AwContents* AwContents::FromWebContents(WebContents* web_contents) { |
| 112 return AwContentsUserData::GetContents(web_contents); | 91 return AwContentsUserData::GetContents(web_contents); |
| 113 } | 92 } |
| 114 | 93 |
| 115 AwContents::AwContents(JNIEnv* env, | 94 AwContents::AwContents(JNIEnv* env, |
| 116 jobject obj, | 95 jobject obj, |
| 117 jobject web_contents_delegate) | 96 jobject web_contents_delegate) |
| 118 : java_ref_(env, obj), | 97 : java_ref_(env, obj), |
| 119 web_contents_delegate_( | 98 web_contents_delegate_( |
| 120 new AwWebContentsDelegate(env, web_contents_delegate)), | 99 new AwWebContentsDelegate(env, web_contents_delegate)), |
| 121 view_visible_(false), | 100 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 122 compositor_visible_(false), | 101 view_renderer_(ViewRendererImpl::Create(this, &render_helper))) { |
| 123 is_composite_pending_(false), | |
| 124 last_frame_context_(NULL) { | |
| 125 RendererPictureMap::CreateInstance(); | |
| 126 android_webview::AwBrowserDependencyFactory* dependency_factory = | 102 android_webview::AwBrowserDependencyFactory* dependency_factory = |
| 127 android_webview::AwBrowserDependencyFactory::GetInstance(); | 103 android_webview::AwBrowserDependencyFactory::GetInstance(); |
| 128 | 104 |
| 129 // TODO(joth): rather than create and set the WebContents here, expose the | 105 // TODO(joth): rather than create and set the WebContents here, expose the |
| 130 // factory method to java side and have that orchestrate the construction | 106 // factory method to java side and have that orchestrate the construction |
| 131 // order. | 107 // order. |
| 132 SetWebContents(dependency_factory->CreateWebContents()); | 108 SetWebContents(dependency_factory->CreateWebContents()); |
| 133 } | 109 } |
| 134 | 110 |
| 135 void AwContents::ResetCompositor() { | |
| 136 compositor_.reset(content::Compositor::Create(this)); | |
| 137 if (scissor_clip_layer_.get()) | |
| 138 AttachLayerTree(); | |
| 139 } | |
| 140 | |
| 141 void AwContents::SetWebContents(content::WebContents* web_contents) { | 111 void AwContents::SetWebContents(content::WebContents* web_contents) { |
| 142 web_contents_.reset(web_contents); | 112 web_contents_.reset(web_contents); |
| 143 web_contents_->SetUserData(kAwContentsUserDataKey, | 113 web_contents_->SetUserData(kAwContentsUserDataKey, |
| 144 new AwContentsUserData(this)); | 114 new AwContentsUserData(this)); |
| 145 | |
| 146 web_contents_->SetDelegate(web_contents_delegate_.get()); | 115 web_contents_->SetDelegate(web_contents_delegate_.get()); |
| 147 render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents_.get(), | 116 render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents_.get())); |
| 148 this)); | |
| 149 ResetCompositor(); | |
| 150 } | 117 } |
| 151 | 118 |
| 152 void AwContents::SetWebContents(JNIEnv* env, jobject obj, jint new_wc) { | 119 void AwContents::SetWebContents(JNIEnv* env, jobject obj, jint new_wc) { |
| 153 SetWebContents(reinterpret_cast<content::WebContents*>(new_wc)); | 120 SetWebContents(reinterpret_cast<content::WebContents*>(new_wc)); |
| 154 } | 121 } |
| 155 | 122 |
| 156 AwContents::~AwContents() { | 123 AwContents::~AwContents() { |
| 157 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); | 124 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); |
| 158 web_contents_->RemoveUserData(kAwContentsUserDataKey); | 125 web_contents_->RemoveUserData(kAwContentsUserDataKey); |
| 159 if (find_helper_.get()) | 126 if (find_helper_.get()) |
| 160 find_helper_->SetListener(NULL); | 127 find_helper_->SetListener(NULL); |
| 161 } | 128 } |
| 162 | 129 |
| 163 void AwContents::DrawGL(AwDrawGLInfo* draw_info) { | |
| 164 | |
| 165 TRACE_EVENT0("AwContents", "AwContents::DrawGL"); | |
| 166 | |
| 167 if (!scissor_clip_layer_ || draw_info->mode == AwDrawGLInfo::kModeProcess) | |
| 168 return; | |
| 169 | |
| 170 DCHECK_EQ(draw_info->mode, AwDrawGLInfo::kModeDraw); | |
| 171 | |
| 172 SetCompositorVisibility(view_visible_); | |
| 173 if (!compositor_visible_) | |
| 174 return; | |
| 175 | |
| 176 // TODO(leandrogracia): remove when crbug.com/164140 is closed. | |
| 177 // --------------------------------------------------------------------------- | |
| 178 GLint texture_external_oes_binding; | |
| 179 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_external_oes_binding); | |
| 180 | |
| 181 GLint vertex_array_buffer_binding; | |
| 182 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vertex_array_buffer_binding); | |
| 183 | |
| 184 GLint index_array_buffer_binding; | |
| 185 glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &index_array_buffer_binding); | |
| 186 | |
| 187 GLint pack_alignment; | |
| 188 glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); | |
| 189 | |
| 190 GLint unpack_alignment; | |
| 191 glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); | |
| 192 | |
| 193 struct { | |
| 194 GLint enabled; | |
| 195 GLint size; | |
| 196 GLint type; | |
| 197 GLint normalized; | |
| 198 GLint stride; | |
| 199 GLvoid* pointer; | |
| 200 } vertex_attrib[3]; | |
| 201 | |
| 202 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib); ++i) { | |
| 203 glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, | |
| 204 &vertex_attrib[i].enabled); | |
| 205 glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_SIZE, | |
| 206 &vertex_attrib[i].size); | |
| 207 glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_TYPE, | |
| 208 &vertex_attrib[i].type); | |
| 209 glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, | |
| 210 &vertex_attrib[i].normalized); | |
| 211 glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_STRIDE, | |
| 212 &vertex_attrib[i].stride); | |
| 213 glGetVertexAttribPointerv(i, GL_VERTEX_ATTRIB_ARRAY_POINTER, | |
| 214 &vertex_attrib[i].pointer); | |
| 215 } | |
| 216 | |
| 217 GLboolean depth_test; | |
| 218 glGetBooleanv(GL_DEPTH_TEST, &depth_test); | |
| 219 | |
| 220 GLboolean cull_face; | |
| 221 glGetBooleanv(GL_CULL_FACE, &cull_face); | |
| 222 | |
| 223 GLboolean color_mask[4]; | |
| 224 glGetBooleanv(GL_COLOR_WRITEMASK, color_mask); | |
| 225 | |
| 226 GLboolean blend_enabled; | |
| 227 glGetBooleanv(GL_BLEND, &blend_enabled); | |
| 228 | |
| 229 GLint blend_src_rgb; | |
| 230 glGetIntegerv(GL_BLEND_SRC_RGB, &blend_src_rgb); | |
| 231 | |
| 232 GLint blend_src_alpha; | |
| 233 glGetIntegerv(GL_BLEND_SRC_ALPHA, &blend_src_alpha); | |
| 234 | |
| 235 GLint blend_dest_rgb; | |
| 236 glGetIntegerv(GL_BLEND_DST_RGB, &blend_dest_rgb); | |
| 237 | |
| 238 GLint blend_dest_alpha; | |
| 239 glGetIntegerv(GL_BLEND_DST_ALPHA, &blend_dest_alpha); | |
| 240 | |
| 241 GLint active_texture; | |
| 242 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture); | |
| 243 | |
| 244 GLint viewport[4]; | |
| 245 glGetIntegerv(GL_VIEWPORT, viewport); | |
| 246 | |
| 247 GLboolean scissor_test; | |
| 248 glGetBooleanv(GL_SCISSOR_TEST, &scissor_test); | |
| 249 | |
| 250 GLint scissor_box[4]; | |
| 251 glGetIntegerv(GL_SCISSOR_BOX, scissor_box); | |
| 252 | |
| 253 GLint current_program; | |
| 254 glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program); | |
| 255 // --------------------------------------------------------------------------- | |
| 256 | |
| 257 // We need to watch if the current Android context has changed and enforce | |
| 258 // a clean-up in the compositor. | |
| 259 EGLContext current_context = eglGetCurrentContext(); | |
| 260 if (!current_context) { | |
| 261 LOG(WARNING) << "No current context attached. Skipping composite."; | |
| 262 return; | |
| 263 } | |
| 264 | |
| 265 if (last_frame_context_ != current_context) { | |
| 266 if (last_frame_context_) | |
| 267 ResetCompositor(); | |
| 268 last_frame_context_ = current_context; | |
| 269 } | |
| 270 | |
| 271 compositor_->SetWindowBounds(gfx::Size(draw_info->width, draw_info->height)); | |
| 272 | |
| 273 if (draw_info->is_layer) { | |
| 274 // When rendering into a separate layer no view clipping, transform, | |
| 275 // scissoring or background transparency need to be handled. | |
| 276 // The Android framework will composite us afterwards. | |
| 277 compositor_->SetHasTransparentBackground(false); | |
| 278 view_clip_layer_->setMasksToBounds(false); | |
| 279 transform_layer_->setTransform(gfx::Transform()); | |
| 280 scissor_clip_layer_->setMasksToBounds(false); | |
| 281 scissor_clip_layer_->setPosition(gfx::PointF()); | |
| 282 scissor_clip_layer_->setBounds(gfx::Size()); | |
| 283 scissor_clip_layer_->setSublayerTransform(gfx::Transform()); | |
| 284 | |
| 285 } else { | |
| 286 compositor_->SetHasTransparentBackground(true); | |
| 287 | |
| 288 gfx::Rect clip_rect(draw_info->clip_left, draw_info->clip_top, | |
| 289 draw_info->clip_right - draw_info->clip_left, | |
| 290 draw_info->clip_bottom - draw_info->clip_top); | |
| 291 | |
| 292 scissor_clip_layer_->setPosition(clip_rect.origin()); | |
| 293 scissor_clip_layer_->setBounds(clip_rect.size()); | |
| 294 scissor_clip_layer_->setMasksToBounds(true); | |
| 295 | |
| 296 // The compositor clipping architecture enforces us to have the clip layer | |
| 297 // as an ancestor of the area we want to clip, but this makes the transform | |
| 298 // become relative to the clip area rather than the full surface. The clip | |
| 299 // position offset needs to be undone before applying the transform. | |
| 300 gfx::Transform undo_clip_position; | |
| 301 undo_clip_position.Translate(-clip_rect.x(), -clip_rect.y()); | |
| 302 scissor_clip_layer_->setSublayerTransform(undo_clip_position); | |
| 303 | |
| 304 gfx::Transform transform; | |
| 305 transform.matrix().setColMajorf(draw_info->transform); | |
| 306 | |
| 307 // The scrolling values of the Android Framework affect the transformation | |
| 308 // matrix. This needs to be undone to let the compositor handle scrolling. | |
| 309 transform.Translate(hw_rendering_scroll_.x(), hw_rendering_scroll_.y()); | |
| 310 transform_layer_->setTransform(transform); | |
| 311 | |
| 312 view_clip_layer_->setMasksToBounds(true); | |
| 313 } | |
| 314 | |
| 315 compositor_->Composite(); | |
| 316 is_composite_pending_ = false; | |
| 317 | |
| 318 // TODO(leandrogracia): remove when crbug.com/164140 is closed. | |
| 319 // --------------------------------------------------------------------------- | |
| 320 char no_gl_restore_prop[PROP_VALUE_MAX]; | |
| 321 __system_property_get("webview.chromium_no_gl_restore", no_gl_restore_prop); | |
| 322 if (!strcmp(no_gl_restore_prop, "true")) { | |
| 323 LOG(WARNING) << "Android GL functor not restoring the previous GL state."; | |
| 324 } else { | |
| 325 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_external_oes_binding); | |
| 326 glBindBuffer(GL_ARRAY_BUFFER, vertex_array_buffer_binding); | |
| 327 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_buffer_binding); | |
| 328 | |
| 329 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); | |
| 330 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); | |
| 331 | |
| 332 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib); ++i) { | |
| 333 glVertexAttribPointer(i, vertex_attrib[i].size, | |
| 334 vertex_attrib[i].type, vertex_attrib[i].normalized, | |
| 335 vertex_attrib[i].stride, vertex_attrib[i].pointer); | |
| 336 | |
| 337 if (vertex_attrib[i].enabled) | |
| 338 glEnableVertexAttribArray(i); | |
| 339 else | |
| 340 glDisableVertexAttribArray(i); | |
| 341 } | |
| 342 | |
| 343 if (depth_test) | |
| 344 glEnable(GL_DEPTH_TEST); | |
| 345 else | |
| 346 glDisable(GL_DEPTH_TEST); | |
| 347 | |
| 348 if (cull_face) | |
| 349 glEnable(GL_CULL_FACE); | |
| 350 else | |
| 351 glDisable(GL_CULL_FACE); | |
| 352 | |
| 353 glColorMask(color_mask[0], color_mask[1], color_mask[2], | |
| 354 color_mask[3]); | |
| 355 | |
| 356 if (blend_enabled) | |
| 357 glEnable(GL_BLEND); | |
| 358 else | |
| 359 glDisable(GL_BLEND); | |
| 360 | |
| 361 glBlendFuncSeparate(blend_src_rgb, blend_dest_rgb, | |
| 362 blend_src_alpha, blend_dest_alpha); | |
| 363 | |
| 364 glActiveTexture(active_texture); | |
| 365 | |
| 366 glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); | |
| 367 | |
| 368 if (scissor_test) | |
| 369 glEnable(GL_SCISSOR_TEST); | |
| 370 else | |
| 371 glDisable(GL_SCISSOR_TEST); | |
| 372 | |
| 373 glScissor(scissor_box[0], scissor_box[1], scissor_box[2], | |
| 374 scissor_box[3]); | |
| 375 | |
| 376 glUseProgram(current_program); | |
| 377 } | |
| 378 // --------------------------------------------------------------------------- | |
| 379 } | |
| 380 | |
| 381 bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) { | |
| 382 skia::RefPtr<SkPicture> picture = | |
| 383 RendererPictureMap::GetInstance()->GetRendererPicture( | |
| 384 web_contents_->GetRoutingID()); | |
| 385 if (!picture) | |
| 386 return false; | |
| 387 | |
| 388 AwPixelInfo* pixels; | |
| 389 if (!g_draw_sw_functions || | |
| 390 (pixels = g_draw_sw_functions->access_pixels(env, java_canvas)) == NULL) { | |
| 391 // TODO(joth): Fall back to slow path rendering via temporary bitmap. | |
| 392 return false; | |
| 393 } | |
| 394 | |
| 395 { | |
| 396 SkBitmap bitmap; | |
| 397 bitmap.setConfig(static_cast<SkBitmap::Config>(pixels->config), | |
| 398 pixels->width, | |
| 399 pixels->height, | |
| 400 pixels->row_bytes); | |
| 401 bitmap.setPixels(pixels->pixels); | |
| 402 SkDevice device(bitmap); | |
| 403 SkCanvas canvas(&device); | |
| 404 SkMatrix matrix; | |
| 405 for (int i = 0; i < 9; i++) | |
| 406 matrix.set(i, pixels->matrix[i]); | |
| 407 canvas.setMatrix(matrix); | |
| 408 | |
| 409 SkRegion clip; | |
| 410 if (pixels->clip_region_size) { | |
| 411 size_t bytes_read = clip.readFromMemory(pixels->clip_region); | |
| 412 DCHECK_EQ(pixels->clip_region_size, bytes_read); | |
| 413 canvas.setClipRegion(clip); | |
| 414 } else { | |
| 415 clip.setRect(SkIRect::MakeWH(pixels->width, pixels->height)); | |
| 416 } | |
| 417 | |
| 418 picture->draw(&canvas); | |
| 419 } | |
| 420 | |
| 421 g_draw_sw_functions->release_pixels(pixels); | |
| 422 return true; | |
| 423 } | |
| 424 | |
| 425 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { | 130 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { |
| 426 return reinterpret_cast<jint>(web_contents_.get()); | 131 return reinterpret_cast<jint>(web_contents_.get()); |
| 427 } | 132 } |
| 428 | 133 |
| 429 void AwContents::DidInitializeContentViewCore(JNIEnv* env, jobject obj, | 134 void AwContents::DidInitializeContentViewCore(JNIEnv* env, jobject obj, |
| 430 jint content_view_core) { | 135 jint content_view_core) { |
| 431 ContentViewCore* core = reinterpret_cast<ContentViewCore*>(content_view_core); | 136 ContentViewCore* core = reinterpret_cast<ContentViewCore*>(content_view_core); |
| 432 DCHECK(core == ContentViewCore::FromWebContents(web_contents_.get())); | 137 DCHECK(core == ContentViewCore::FromWebContents(web_contents_.get())); |
| 433 | 138 view_renderer_->SetContents(core); |
| 434 // Ensures content keeps clipped within the view during transformations. | |
| 435 view_clip_layer_ = cc::Layer::create(); | |
| 436 view_clip_layer_->setBounds(view_size_); | |
| 437 view_clip_layer_->addChild(core->GetLayer()); | |
| 438 | |
| 439 // Applies the transformation matrix. | |
| 440 transform_layer_ = cc::Layer::create(); | |
| 441 transform_layer_->addChild(view_clip_layer_); | |
| 442 | |
| 443 // Ensures content is drawn within the scissor clip rect provided by the | |
| 444 // Android framework. | |
| 445 scissor_clip_layer_ = cc::Layer::create(); | |
| 446 scissor_clip_layer_->addChild(transform_layer_); | |
| 447 | |
| 448 AttachLayerTree(); | |
| 449 } | |
| 450 | |
| 451 void AwContents::AttachLayerTree() { | |
| 452 DCHECK(scissor_clip_layer_.get()); | |
| 453 compositor_->SetRootLayer(scissor_clip_layer_); | |
| 454 Invalidate(); | |
| 455 } | 139 } |
| 456 | 140 |
| 457 void AwContents::Destroy(JNIEnv* env, jobject obj) { | 141 void AwContents::Destroy(JNIEnv* env, jobject obj) { |
| 458 delete this; | 142 delete this; |
| 459 } | 143 } |
| 460 | 144 |
| 461 // static | 145 // static |
| 462 void SetAwDrawSWFunctionTable(JNIEnv* env, jclass, jint function_table) { | 146 void SetAwDrawSWFunctionTable(JNIEnv* env, jclass, jint function_table) { |
| 463 g_draw_sw_functions = | 147 ViewRenderer::SetAwDrawSWFunctionTable( |
| 464 reinterpret_cast<AwDrawSWFunctionTable*>(function_table); | 148 reinterpret_cast<AwDrawSWFunctionTable*>(function_table)); |
| 465 } | 149 } |
| 466 | 150 |
| 467 // static | 151 // static |
| 468 jint GetAwDrawGLFunction(JNIEnv* env, jclass) { | 152 jint GetAwDrawGLFunction(JNIEnv* env, jclass) { |
| 469 return reinterpret_cast<jint>(&DrawGLFunction); | 153 return reinterpret_cast<jint>(&DrawGLFunction); |
| 470 } | 154 } |
| 471 | 155 |
| 156 jint AwContents::GetAwDrawGLViewContext(JNIEnv* env, jobject obj) { | |
| 157 return reinterpret_cast<jint>(view_renderer_.get()); | |
| 158 } | |
| 159 | |
| 472 namespace { | 160 namespace { |
| 473 // |message| is passed as base::Owned, so it will automatically be deleted | 161 // |message| is passed as base::Owned, so it will automatically be deleted |
| 474 // when the callback goes out of scope. | 162 // when the callback goes out of scope. |
| 475 void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message, | 163 void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message, |
| 476 bool has_images) { | 164 bool has_images) { |
| 477 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), | 165 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), |
| 478 has_images, | 166 has_images, |
| 479 message->obj()); | 167 message->obj()); |
| 480 } | 168 } |
| 481 } // namespace | 169 } // namespace |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 bool finished) { | 361 bool finished) { |
| 674 JNIEnv* env = AttachCurrentThread(); | 362 JNIEnv* env = AttachCurrentThread(); |
| 675 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 363 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 676 if (obj.is_null()) | 364 if (obj.is_null()) |
| 677 return; | 365 return; |
| 678 | 366 |
| 679 Java_AwContents_onFindResultReceived( | 367 Java_AwContents_onFindResultReceived( |
| 680 env, obj.obj(), active_ordinal, match_count, finished); | 368 env, obj.obj(), active_ordinal, match_count, finished); |
| 681 } | 369 } |
| 682 | 370 |
| 683 void AwContents::ScheduleComposite() { | |
| 684 TRACE_EVENT0("AwContents", "AwContents::ScheduleComposite"); | |
| 685 | |
| 686 if (is_composite_pending_) | |
| 687 return; | |
| 688 | |
| 689 is_composite_pending_ = true; | |
| 690 Invalidate(); | |
| 691 } | |
| 692 | |
| 693 void AwContents::Invalidate() { | 371 void AwContents::Invalidate() { |
| 694 JNIEnv* env = AttachCurrentThread(); | 372 JNIEnv* env = AttachCurrentThread(); |
| 695 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 373 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 696 if (obj.is_null()) | 374 if (!obj.is_null()) |
| 697 return; | 375 Java_AwContents_invalidate(env, obj.obj()); |
| 698 | |
| 699 Java_AwContents_invalidate(env, obj.obj()); | |
| 700 } | 376 } |
| 701 | 377 |
| 702 void AwContents::SetCompositorVisibility(bool visible) { | 378 void AwContents::OnNewPicture(ScopedJavaLocalRef<jobject> picture) { |
| 703 if (compositor_visible_ != visible) { | 379 JNIEnv* env = AttachCurrentThread(); |
| 704 compositor_visible_ = visible; | 380 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 705 compositor_->SetVisible(compositor_visible_); | 381 if (!obj.is_null()) |
| 706 } | 382 Java_AwContents_onNewPicture(env, obj.obj(), picture.obj()); |
| 707 } | |
| 708 | |
| 709 void AwContents::OnSwapBuffersCompleted() { | |
| 710 } | 383 } |
| 711 | 384 |
| 712 base::android::ScopedJavaLocalRef<jbyteArray> | 385 base::android::ScopedJavaLocalRef<jbyteArray> |
| 713 AwContents::GetCertificate(JNIEnv* env, | 386 AwContents::GetCertificate(JNIEnv* env, |
| 714 jobject obj) { | 387 jobject obj) { |
| 715 content::NavigationEntry* entry = | 388 content::NavigationEntry* entry = |
| 716 web_contents_->GetController().GetActiveEntry(); | 389 web_contents_->GetController().GetActiveEntry(); |
| 717 if (!entry) | 390 if (!entry) |
| 718 return ScopedJavaLocalRef<jbyteArray>(); | 391 return ScopedJavaLocalRef<jbyteArray>(); |
| 719 // Get the certificate | 392 // Get the certificate |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 obj, | 436 obj, |
| 764 data.type, | 437 data.type, |
| 765 extra_data_for_type.obj(), | 438 extra_data_for_type.obj(), |
| 766 href.obj(), | 439 href.obj(), |
| 767 anchor_text.obj(), | 440 anchor_text.obj(), |
| 768 img_src.obj()); | 441 img_src.obj()); |
| 769 } | 442 } |
| 770 | 443 |
| 771 void AwContents::OnSizeChanged(JNIEnv* env, jobject obj, | 444 void AwContents::OnSizeChanged(JNIEnv* env, jobject obj, |
| 772 int w, int h, int ow, int oh) { | 445 int w, int h, int ow, int oh) { |
| 773 view_size_ = gfx::Size(w, h); | 446 view_renderer_->OnSizeChanged(w, h); |
| 774 if (view_clip_layer_.get()) | |
| 775 view_clip_layer_->setBounds(view_size_); | |
| 776 } | 447 } |
| 777 | 448 |
| 778 void AwContents::SetWindowViewVisibility(JNIEnv* env, jobject obj, | 449 void AwContents::SetWindowViewVisibility(JNIEnv* env, jobject obj, |
| 779 bool window_visible, | 450 bool window_visible, |
| 780 bool view_visible) { | 451 bool view_visible) { |
| 781 view_visible_ = window_visible && view_visible; | 452 view_renderer_->OnVisibilityChanged(window_visible, view_visible); |
| 782 Invalidate(); | |
| 783 } | 453 } |
| 784 | 454 |
| 785 void AwContents::OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h) { | 455 void AwContents::OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h) { |
| 786 view_size_ = gfx::Size(w, h); | 456 view_renderer_->OnAttachedToWindow(w, h); |
| 787 if (view_clip_layer_.get()) | |
| 788 view_clip_layer_->setBounds(view_size_); | |
| 789 } | 457 } |
| 790 | 458 |
| 791 void AwContents::OnDetachedFromWindow(JNIEnv* env, jobject obj) { | 459 void AwContents::OnDetachedFromWindow(JNIEnv* env, jobject obj) { |
| 792 view_visible_ = false; | 460 view_renderer_->OnDetachedFromWindow(); |
| 793 SetCompositorVisibility(false); | |
| 794 } | 461 } |
| 795 | 462 |
| 796 base::android::ScopedJavaLocalRef<jbyteArray> | 463 base::android::ScopedJavaLocalRef<jbyteArray> |
| 797 AwContents::GetOpaqueState(JNIEnv* env, jobject obj) { | 464 AwContents::GetOpaqueState(JNIEnv* env, jobject obj) { |
| 798 // Required optimization in WebViewClassic to not save any state if | 465 // Required optimization in WebViewClassic to not save any state if |
| 799 // there has been no navigations. | 466 // there has been no navigations. |
| 800 if (!web_contents_->GetController().GetEntryCount()) | 467 if (!web_contents_->GetController().GetEntryCount()) |
| 801 return ScopedJavaLocalRef<jbyteArray>(); | 468 return ScopedJavaLocalRef<jbyteArray>(); |
| 802 | 469 |
| 803 Pickle pickle; | 470 Pickle pickle; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 816 std::vector<uint8> state_vector; | 483 std::vector<uint8> state_vector; |
| 817 base::android::JavaByteArrayToByteVector(env, state, &state_vector); | 484 base::android::JavaByteArrayToByteVector(env, state, &state_vector); |
| 818 | 485 |
| 819 Pickle pickle(reinterpret_cast<const char*>(state_vector.begin()), | 486 Pickle pickle(reinterpret_cast<const char*>(state_vector.begin()), |
| 820 state_vector.size()); | 487 state_vector.size()); |
| 821 PickleIterator iterator(pickle); | 488 PickleIterator iterator(pickle); |
| 822 | 489 |
| 823 return RestoreFromPickle(&iterator, web_contents_.get()); | 490 return RestoreFromPickle(&iterator, web_contents_.get()); |
| 824 } | 491 } |
| 825 | 492 |
| 493 bool AwContents::DrawSW(JNIEnv* env, | |
| 494 jobject obj, | |
| 495 jobject canvas, | |
| 496 jint clip_x, | |
| 497 jint clip_y, | |
| 498 jint clip_w, | |
| 499 jint clip_h) { | |
| 500 return view_renderer_->DrawSW(canvas, | |
| 501 gfx::Rect(clip_x, clip_y, clip_w, clip_h)); | |
| 502 } | |
| 503 | |
| 826 void AwContents::SetScrollForHWFrame(JNIEnv* env, jobject obj, | 504 void AwContents::SetScrollForHWFrame(JNIEnv* env, jobject obj, |
| 827 int scroll_x, int scroll_y) { | 505 int scroll_x, int scroll_y) { |
| 828 hw_rendering_scroll_ = gfx::Point(scroll_x, scroll_y); | 506 view_renderer_->SetScrollForHWFrame(scroll_x, scroll_y); |
| 829 } | 507 } |
| 830 | 508 |
| 831 void AwContents::SetPendingWebContentsForPopup( | 509 void AwContents::SetPendingWebContentsForPopup( |
| 832 scoped_ptr<content::WebContents> pending) { | 510 scoped_ptr<content::WebContents> pending) { |
| 833 if (pending_contents_.get()) { | 511 if (pending_contents_.get()) { |
| 834 // TODO(benm): Support holding multiple pop up window requests. | 512 // TODO(benm): Support holding multiple pop up window requests. |
| 835 LOG(WARNING) << "Blocking popup window creation as an outstanding " | 513 LOG(WARNING) << "Blocking popup window creation as an outstanding " |
| 836 << "popup window is still pending."; | 514 << "popup window is still pending."; |
| 837 MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release()); | 515 MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release()); |
| 838 return; | 516 return; |
| 839 } | 517 } |
| 840 pending_contents_ = pending.Pass(); | 518 pending_contents_ = pending.Pass(); |
| 841 } | 519 } |
| 842 | 520 |
| 843 void AwContents::FocusFirstNode(JNIEnv* env, jobject obj) { | 521 void AwContents::FocusFirstNode(JNIEnv* env, jobject obj) { |
| 844 web_contents_->FocusThroughTabTraversal(false); | 522 web_contents_->FocusThroughTabTraversal(false); |
| 845 } | 523 } |
| 846 | 524 |
| 847 jint AwContents::ReleasePopupWebContents(JNIEnv* env, jobject obj) { | 525 jint AwContents::ReleasePopupWebContents(JNIEnv* env, jobject obj) { |
| 848 return reinterpret_cast<jint>(pending_contents_.release()); | 526 return reinterpret_cast<jint>(pending_contents_.release()); |
| 849 } | 527 } |
| 850 | 528 |
| 851 void AwContents::OnPictureUpdated(int process_id, int render_view_id) { | 529 ScopedJavaLocalRef<jobject> AwContents::CapturePicture(JNIEnv* env, |
| 852 CHECK_EQ(web_contents_->GetRenderProcessHost()->GetID(), process_id); | 530 jobject obj) { |
| 853 if (render_view_id != web_contents_->GetRoutingID()) | 531 return view_renderer_->CapturePicture(); |
| 854 return; | 532 } |
| 855 | 533 |
| 856 // TODO(leandrogracia): delete when sw rendering uses Ubercompositor. | 534 void AwContents::EnableOnNewPicture(JNIEnv* env, |
| 857 // Invalidation should be provided by the compositor only. | 535 jobject obj, |
| 858 Invalidate(); | 536 jboolean enabled, |
| 537 jboolean invalidation_only) { | |
| 538 view_renderer_->EnableOnNewPicture( | |
|
joth
2013/01/21 22:54:24
Mode m = ViewRenderer::kOnNewPictureDisabled;
if (
Leandro GraciĆ” Gil
2013/01/22 08:18:46
Done.
| |
| 539 !enabled ? ViewRenderer::kOnNewPictureDisabled : | |
| 540 (invalidation_only ? ViewRenderer::kOnNewPictureInvalidationOnly : | |
| 541 ViewRenderer::kOnNewPictureEnabled)); | |
| 859 } | 542 } |
| 860 | 543 |
| 861 } // namespace android_webview | 544 } // namespace android_webview |
| OLD | NEW |