| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/in_process_view_renderer.h" | 5 #include "android_webview/browser/in_process_view_renderer.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 | 8 |
| 9 #include "android_webview/public/browser/draw_gl.h" | 9 #include "android_webview/public/browser/draw_gl.h" |
| 10 #include "android_webview/public/browser/draw_sw.h" | 10 #include "android_webview/public/browser/draw_sw.h" |
| 11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "content/public/browser/android/content_view_core.h" | 15 #include "content/public/browser/android/content_view_core.h" |
| 16 #include "content/public/browser/android/synchronous_compositor.h" | 16 #include "content/public/browser/android/synchronous_compositor.h" |
| 17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "skia/ext/refptr.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "third_party/skia/include/core/SkCanvas.h" | 21 #include "third_party/skia/include/core/SkCanvas.h" |
| 21 #include "third_party/skia/include/core/SkDevice.h" | 22 #include "third_party/skia/include/core/SkDevice.h" |
| 22 #include "third_party/skia/include/core/SkGraphics.h" | 23 #include "third_party/skia/include/core/SkGraphics.h" |
| 23 #include "third_party/skia/include/core/SkPicture.h" | 24 #include "third_party/skia/include/core/SkPicture.h" |
| 24 #include "ui/gfx/size_conversions.h" | 25 #include "ui/gfx/size_conversions.h" |
| 25 #include "ui/gfx/skia_util.h" | 26 #include "ui/gfx/skia_util.h" |
| 26 #include "ui/gfx/transform.h" | 27 #include "ui/gfx/transform.h" |
| 27 #include "ui/gfx/vector2d_f.h" | 28 #include "ui/gfx/vector2d_f.h" |
| 28 #include "ui/gl/gl_bindings.h" | 29 #include "ui/gl/gl_bindings.h" |
| 29 | 30 |
| 30 // TODO(leandrogracia): Borrowed from gl2ext.h. Cannot be included due to | 31 // TODO(leandrogracia): Borrowed from gl2ext.h. Cannot be included due to |
| 31 // conflicts with gl_bindings.h and the EGL library methods | 32 // conflicts with gl_bindings.h and the EGL library methods |
| 32 // (eglGetCurrentContext). | 33 // (eglGetCurrentContext). |
| 33 #ifndef GL_TEXTURE_EXTERNAL_OES | 34 #ifndef GL_TEXTURE_EXTERNAL_OES |
| 34 #define GL_TEXTURE_EXTERNAL_OES 0x8D65 | 35 #define GL_TEXTURE_EXTERNAL_OES 0x8D65 |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 #ifndef GL_TEXTURE_BINDING_EXTERNAL_OES | 38 #ifndef GL_TEXTURE_BINDING_EXTERNAL_OES |
| 38 #define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 | 39 #define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 using base::android::AttachCurrentThread; | 42 using base::android::AttachCurrentThread; |
| 42 using base::android::JavaRef; | 43 using base::android::JavaRef; |
| 43 using base::android::ScopedJavaLocalRef; | 44 using base::android::ScopedJavaLocalRef; |
| 44 using content::Compositor; | |
| 45 using content::ContentViewCore; | 45 using content::ContentViewCore; |
| 46 | 46 |
| 47 namespace android_webview { | 47 namespace android_webview { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 class GLStateRestore { | 51 class GLStateRestore { |
| 52 public: | 52 public: |
| 53 GLStateRestore() { | 53 GLStateRestore() { |
| 54 #if !defined(NDEBUG) | 54 #if !defined(NDEBUG) |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 bool RenderPictureToCanvas(SkPicture* picture, SkCanvas* canvas) { | 256 bool RenderPictureToCanvas(SkPicture* picture, SkCanvas* canvas) { |
| 257 canvas->drawPicture(*picture); | 257 canvas->drawPicture(*picture); |
| 258 return true; | 258 return true; |
| 259 } | 259 } |
| 260 | 260 |
| 261 // TODO(boliu): Remove this when hardware mode is ready. | 261 // TODO(boliu): Remove this when hardware mode is ready. |
| 262 bool HardwareEnabled() { | 262 bool HardwareEnabled() { |
| 263 return CommandLine::ForCurrentProcess()->HasSwitch("testing-webview-gl-mode"); | 263 return CommandLine::ForCurrentProcess()->HasSwitch("testing-webview-gl-mode"); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Provides software rendering functions from the Android glue layer. |
| 267 // Allows preventing extra copies of data when rendering. |
| 268 AwDrawSWFunctionTable* g_sw_draw_functions = NULL; |
| 269 |
| 270 // Tells if the Skia library versions in Android and Chromium are compatible. |
| 271 // If they are then it's possible to pass Skia objects like SkPictures to the |
| 272 // Android glue layer via the SW rendering functions. |
| 273 // If they are not, then additional copies and rasterizations are required |
| 274 // as a fallback mechanism, which will have an important performance impact. |
| 275 bool g_is_skia_version_compatible = false; |
| 276 |
| 266 } // namespace | 277 } // namespace |
| 267 | 278 |
| 279 // static |
| 280 void BrowserViewRenderer::SetAwDrawSWFunctionTable( |
| 281 AwDrawSWFunctionTable* table) { |
| 282 g_sw_draw_functions = table; |
| 283 g_is_skia_version_compatible = |
| 284 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); |
| 285 LOG_IF(WARNING, !g_is_skia_version_compatible) |
| 286 << "Skia versions are not compatible, rendering performance will suffer."; |
| 287 } |
| 288 |
| 289 // static |
| 290 AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { |
| 291 return g_sw_draw_functions; |
| 292 } |
| 293 |
| 294 // static |
| 295 bool BrowserViewRenderer::IsSkiaVersionCompatible() { |
| 296 DCHECK(g_sw_draw_functions); |
| 297 return g_is_skia_version_compatible; |
| 298 } |
| 299 |
| 268 InProcessViewRenderer::InProcessViewRenderer( | 300 InProcessViewRenderer::InProcessViewRenderer( |
| 269 BrowserViewRenderer::Client* client, | 301 BrowserViewRenderer::Client* client, |
| 270 JavaHelper* java_helper) | 302 JavaHelper* java_helper) |
| 271 : client_(client), | 303 : client_(client), |
| 272 java_helper_(java_helper), | 304 java_helper_(java_helper), |
| 273 web_contents_(NULL), | 305 web_contents_(NULL), |
| 274 compositor_(NULL), | 306 compositor_(NULL), |
| 275 view_visible_(false), | 307 view_visible_(false), |
| 276 continuous_invalidate_(false), | 308 continuous_invalidate_(false), |
| 277 continuous_invalidate_task_pending_(false), | 309 continuous_invalidate_task_pending_(false), |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page | 636 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page |
| 605 // scale here. Determine what if any needs bringing over to this class. | 637 // scale here. Determine what if any needs bringing over to this class. |
| 606 return CompositeSW(canvas); | 638 return CompositeSW(canvas); |
| 607 } | 639 } |
| 608 | 640 |
| 609 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 641 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
| 610 return compositor_ && compositor_->DemandDrawSw(canvas); | 642 return compositor_ && compositor_->DemandDrawSw(canvas); |
| 611 } | 643 } |
| 612 | 644 |
| 613 } // namespace android_webview | 645 } // namespace android_webview |
| OLD | NEW |