From ee44bd0c40e393afe5deccf34c6abda1dd459193 Mon Sep 17 00:00:00 2001 From: "joth@chromium.org" Date: Fri, 9 Aug 2013 12:35:11 +0000 Subject: Android WebView: Make a custom Picture subclass This allows the capturePicture path to work fully even when using mismatched skia version to the system. AwCreatePictureFunction is now obsolete and can be removed in a followup. BUG=b/9814370 Review URL: https://chromiumcodereview.appspot.com/22035002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216667 0039d316-1c4b-4281-b951-d872f2087c98 --- android_webview/browser/browser_view_renderer.h | 7 +- .../browser/in_process_view_renderer.cc | 115 +++++++-------------- android_webview/browser/in_process_view_renderer.h | 15 ++- .../org/chromium/android_webview/AwContents.java | 8 +- .../org/chromium/android_webview/AwPicture.java | 95 +++++++++++++++++ .../native/android_webview_jni_registrar.cc | 6 +- android_webview/native/aw_contents.cc | 17 +-- android_webview/native/aw_contents.h | 5 +- android_webview/native/aw_picture.cc | 56 ++++++++++ android_webview/native/aw_picture.h | 42 ++++++++ .../native/java_browser_view_renderer_helper.cc | 7 ++ .../native/java_browser_view_renderer_helper.h | 2 + android_webview/native/webview_native.gyp | 3 + 13 files changed, 278 insertions(+), 100 deletions(-) create mode 100644 android_webview/java/src/org/chromium/android_webview/AwPicture.java create mode 100644 android_webview/native/aw_picture.cc create mode 100644 android_webview/native/aw_picture.h diff --git a/android_webview/browser/browser_view_renderer.h b/android_webview/browser/browser_view_renderer.h index 9e02959..78beb17 100644 --- a/android_webview/browser/browser_view_renderer.h +++ b/android_webview/browser/browser_view_renderer.h @@ -6,10 +6,12 @@ #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ #include "base/android/scoped_java_ref.h" +#include "skia/ext/refptr.h" #include "ui/gfx/point.h" #include "ui/gfx/rect.h" #include "ui/gfx/vector2d_f.h" +class SkPicture; struct AwDrawGLInfo; struct AwDrawSWFunctionTable; @@ -84,7 +86,6 @@ class BrowserViewRenderer { // Global hookup methods. static void SetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table); static AwDrawSWFunctionTable* GetAwDrawSWFunctionTable(); - static bool IsSkiaVersionCompatible(); // Rendering methods. @@ -108,9 +109,7 @@ class BrowserViewRenderer { virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) = 0; // CapturePicture API methods. - virtual base::android::ScopedJavaLocalRef CapturePicture( - int width, - int height) = 0; + virtual skia::RefPtr CapturePicture(int width, int height) = 0; virtual void EnableOnNewPicture(bool enabled) = 0; // View update notifications. diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc index 9ea1c5a..f5f134e 100644 --- a/android_webview/browser/in_process_view_renderer.cc +++ b/android_webview/browser/in_process_view_renderer.cc @@ -22,7 +22,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" #include "gpu/command_buffer/service/in_process_command_buffer.h" -#include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkDevice.h" @@ -64,13 +63,11 @@ class UserData : public content::WebContents::Data { InProcessViewRenderer* instance_; }; -typedef base::Callback RenderMethod; - bool RasterizeIntoBitmap(JNIEnv* env, const JavaRef& jbitmap, int scroll_x, int scroll_y, - const RenderMethod& renderer) { + const InProcessViewRenderer::RenderMethod& renderer) { DCHECK(jbitmap.obj()); AndroidBitmapInfo bitmap_info; @@ -123,13 +120,6 @@ bool HardwareEnabled() { // Allows preventing extra copies of data when rendering. AwDrawSWFunctionTable* g_sw_draw_functions = NULL; -// Tells if the Skia library versions in Android and Chromium are compatible. -// If they are then it's possible to pass Skia objects like SkPictures to the -// Android glue layer via the SW rendering functions. -// If they are not, then additional copies and rasterizations are required -// as a fallback mechanism, which will have an important performance impact. -bool g_is_skia_version_compatible = false; - const int64 kFallbackTickTimeoutInMilliseconds = 20; class ScopedAllowGL { @@ -180,11 +170,6 @@ static void ScheduleGpuWork() { void BrowserViewRenderer::SetAwDrawSWFunctionTable( AwDrawSWFunctionTable* table) { g_sw_draw_functions = table; - g_is_skia_version_compatible = - g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); - LOG_IF(WARNING, !g_is_skia_version_compatible) - << "Skia versions are not compatible, rendering performance will suffer."; - gpu::InProcessCommandBuffer::SetScheduleCallback( base::Bind(&ScheduleGpuWork)); } @@ -194,12 +179,6 @@ AwDrawSWFunctionTable* BrowserViewRenderer::GetAwDrawSWFunctionTable() { return g_sw_draw_functions; } -// static -bool BrowserViewRenderer::IsSkiaVersionCompatible() { - DCHECK(g_sw_draw_functions); - return g_is_skia_version_compatible; -} - InProcessViewRenderer::InProcessViewRenderer( BrowserViewRenderer::Client* client, JavaHelper* java_helper, @@ -400,7 +379,6 @@ void InProcessViewRenderer::SetGlobalVisibleRect( bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, const gfx::Rect& clip) { - TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawSW"); fallback_tick_.Cancel(); if (clip.IsEmpty()) { @@ -415,17 +393,37 @@ bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, return false; } + return RenderViaAuxilaryBitmapIfNeeded( + java_canvas, + java_helper_, + scroll_at_start_of_frame_, + clip, + base::Bind(&InProcessViewRenderer::CompositeSW, + base::Unretained(this)), + web_contents_); +} + +// static +bool InProcessViewRenderer::RenderViaAuxilaryBitmapIfNeeded( + jobject java_canvas, + BrowserViewRenderer::JavaHelper* java_helper, + const gfx::Vector2d& scroll_correction, + const gfx::Rect& clip, + InProcessViewRenderer::RenderMethod render_source, + void* owner_key) { + TRACE_EVENT0("android_webview", + "InProcessViewRenderer::RenderViaAuxilaryBitmapIfNeeded"); JNIEnv* env = AttachCurrentThread(); AwDrawSWFunctionTable* sw_functions = GetAwDrawSWFunctionTable(); AwPixelInfo* pixels = sw_functions ? sw_functions->access_pixels(env, java_canvas) : NULL; - // Render into an auxiliary bitmap if pixel info is not available. - ScopedJavaLocalRef jcanvas(env, java_canvas); if (pixels == NULL) { + // Render into an auxiliary bitmap if pixel info is not available. + ScopedJavaLocalRef jcanvas(env, java_canvas); TRACE_EVENT0("android_webview", "RenderToAuxBitmap"); - ScopedJavaLocalRef jbitmap(java_helper_->CreateBitmap( - env, clip.width(), clip.height(), jcanvas, web_contents_)); + ScopedJavaLocalRef jbitmap(java_helper->CreateBitmap( + env, clip.width(), clip.height(), jcanvas, owner_key)); if (!jbitmap.obj()) { TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_BitmapAllocFail", @@ -434,18 +432,17 @@ bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, } if (!RasterizeIntoBitmap(env, jbitmap, - clip.x() - scroll_at_start_of_frame_.x(), - clip.y() - scroll_at_start_of_frame_.y(), - base::Bind(&InProcessViewRenderer::CompositeSW, - base::Unretained(this)))) { + clip.x() - scroll_correction.x(), + clip.y() - scroll_correction.y(), + render_source)) { TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_RasterizeFail", TRACE_EVENT_SCOPE_THREAD); return false; } - java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, - clip.x(), clip.y()); + java_helper->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, + clip.x(), clip.y()); return true; } @@ -473,29 +470,22 @@ bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, } else { canvas.clipRect(gfx::RectToSkRect(clip)); } - canvas.translate(scroll_at_start_of_frame_.x(), - scroll_at_start_of_frame_.y()); + canvas.translate(scroll_correction.x(), + scroll_correction.y()); - succeeded = CompositeSW(&canvas); + succeeded = render_source.Run(&canvas); } sw_functions->release_pixels(pixels); return succeeded; } -base::android::ScopedJavaLocalRef -InProcessViewRenderer::CapturePicture(int width, int height) { - if (!compositor_ || !GetAwDrawSWFunctionTable()) { - TRACE_EVENT_INSTANT0( - "android_webview", "EarlyOut_CapturePicture", TRACE_EVENT_SCOPE_THREAD); - return ScopedJavaLocalRef(); - } - +skia::RefPtr InProcessViewRenderer::CapturePicture(int width, + int height) { // Return empty Picture objects for empty SkPictures. - JNIEnv* env = AttachCurrentThread(); + skia::RefPtr picture = skia::AdoptRef(new SkPicture); if (width <= 0 || height <= 0) { - return java_helper_->RecordBitmapIntoPicture(env, - ScopedJavaLocalRef()); + return picture; } // Reset scroll back to the origin, will go back to the old @@ -503,36 +493,11 @@ InProcessViewRenderer::CapturePicture(int width, int height) { base::AutoReset scroll_reset(&scroll_offset_css_, gfx::Vector2d()); - skia::RefPtr picture = skia::AdoptRef(new SkPicture); SkCanvas* rec_canvas = picture->beginRecording(width, height, 0); - if (!CompositeSW(rec_canvas)) - return ScopedJavaLocalRef(); + if (compositor_) + CompositeSW(rec_canvas); picture->endRecording(); - - if (IsSkiaVersionCompatible()) { - // Add a reference that the create_picture() will take ownership of. - picture->ref(); - return ScopedJavaLocalRef(env, - GetAwDrawSWFunctionTable()->create_picture(env, picture.get())); - } - - // If Skia versions are not compatible, workaround it by rasterizing the - // picture into a bitmap and drawing it into a new Java picture. Pass null - // for |canvas| as we don't have java canvas at this point (and it would be - // software anyway). - ScopedJavaLocalRef jbitmap(java_helper_->CreateBitmap( - env, picture->width(), picture->height(), ScopedJavaLocalRef(), - NULL)); - if (!jbitmap.obj()) - return ScopedJavaLocalRef(); - - if (!RasterizeIntoBitmap(env, jbitmap, 0, 0, - base::Bind(&RenderPictureToCanvas, - base::Unretained(picture.get())))) { - return ScopedJavaLocalRef(); - } - - return java_helper_->RecordBitmapIntoPicture(env, jbitmap); + return picture; } void InProcessViewRenderer::EnableOnNewPicture(bool enabled) { diff --git a/android_webview/browser/in_process_view_renderer.h b/android_webview/browser/in_process_view_renderer.h index cc6c96f..e86796f 100644 --- a/android_webview/browser/in_process_view_renderer.h +++ b/android_webview/browser/in_process_view_renderer.h @@ -38,6 +38,16 @@ class InProcessViewRenderer : public BrowserViewRenderer, static InProcessViewRenderer* FromWebContents( content::WebContents* contents); + // TODO(joth): consider extracting this to its own utility class. + typedef base::Callback RenderMethod; + static bool RenderViaAuxilaryBitmapIfNeeded( + jobject java_canvas, + JavaHelper* java_helper, + const gfx::Vector2d& scroll_correction, + const gfx::Rect& clip, + RenderMethod render_source, + void* owner_key); + // BrowserViewRenderer overrides virtual bool OnDraw(jobject java_canvas, bool is_hardware_canvas, @@ -45,9 +55,8 @@ class InProcessViewRenderer : public BrowserViewRenderer, const gfx::Rect& clip) OVERRIDE; virtual void DrawGL(AwDrawGLInfo* draw_info) OVERRIDE; virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) OVERRIDE; - virtual base::android::ScopedJavaLocalRef CapturePicture( - int width, - int height) OVERRIDE; + virtual skia::RefPtr CapturePicture(int width, + int height) OVERRIDE; virtual void EnableOnNewPicture(bool enabled) OVERRIDE; virtual void OnVisibilityChanged(bool visible) OVERRIDE; virtual void OnSizeChanged(int width, int height) OVERRIDE; diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index eb0128e..46989c0 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -717,9 +717,9 @@ public class AwContents { } public Picture capturePicture() { - return nativeCapturePicture(mNativeAwContents, - mScrollOffsetManager.computeHorizontalScrollRange(), - mScrollOffsetManager.computeVerticalScrollRange()); + return new AwPicture(nativeCapturePicture(mNativeAwContents, + mScrollOffsetManager.computeHorizontalScrollRange(), + mScrollOffsetManager.computeVerticalScrollRange())); } /** @@ -1814,7 +1814,7 @@ public class AwContents { private native void nativeSetBackgroundColor(int nativeAwContents, int color); private native int nativeGetAwDrawGLViewContext(int nativeAwContents); - private native Picture nativeCapturePicture(int nativeAwContents, int width, int height); + private native int nativeCapturePicture(int nativeAwContents, int width, int height); private native void nativeEnableOnNewPicture(int nativeAwContents, boolean enabled); private native void nativeInvokeGeolocationCallback( diff --git a/android_webview/java/src/org/chromium/android_webview/AwPicture.java b/android_webview/java/src/org/chromium/android_webview/AwPicture.java new file mode 100644 index 0000000..30ec57b --- /dev/null +++ b/android_webview/java/src/org/chromium/android_webview/AwPicture.java @@ -0,0 +1,95 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.android_webview; + +import android.graphics.Canvas; +import android.graphics.Picture; +import android.graphics.Rect; + +import org.chromium.base.CalledByNative; +import org.chromium.base.JNINamespace; +import org.chromium.content.common.CleanupReference; + +import java.io.OutputStream; + +// A simple wrapper around a SkPicture, that allows final rendering to be performed using the +// chromium skia library. +@JNINamespace("android_webview") +class AwPicture extends Picture { + + private int mNativeAwPicture; + + // There is no explicit destroy method on Picture base-class, so cleanup is always + // handled via the CleanupReference. + private static final class DestroyRunnable implements Runnable { + private int mNativeAwPicture; + private DestroyRunnable(int nativeAwPicture) { + mNativeAwPicture = nativeAwPicture; + } + @Override + public void run() { + nativeDestroy(mNativeAwPicture); + } + } + + private CleanupReference mCleanupReference; + + /** + * @param nativeAwPicture is an instance of the AwPicture native class. Ownership is + * taken by this java instance. + */ + AwPicture(int nativeAwPicture) { + mNativeAwPicture = nativeAwPicture; + mCleanupReference = new CleanupReference(this, new DestroyRunnable(nativeAwPicture)); + } + + @Override + public Canvas beginRecording(int width, int height) { + unsupportedOperation(); + return null; + } + + @Override + public void endRecording() { + // Intentional no-op. The native picture ended recording prior to java c'tor call. + } + + @Override + public int getWidth() { + return nativeGetWidth(mNativeAwPicture); + } + + @Override + public int getHeight() { + return nativeGetHeight(mNativeAwPicture); + } + + // Effectively a local variable of draw(), but held as a member to avoid GC churn. + private Rect mClipBoundsTemporary = new Rect(); + + @Override + public void draw(Canvas canvas) { + canvas.getClipBounds(mClipBoundsTemporary); + nativeDraw(mNativeAwPicture, canvas, + mClipBoundsTemporary.left, mClipBoundsTemporary.top, + mClipBoundsTemporary.right, mClipBoundsTemporary.bottom); + } + + @Override + public void writeToStream(OutputStream stream) { + unsupportedOperation(); + } + + private void unsupportedOperation() { + throw new IllegalStateException("Unsupported in AwPicture"); + } + + private static native void nativeDestroy(int nativeAwPicture); + private native int nativeGetWidth(int nativeAwPicture); + private native int nativeGetHeight(int nativeAwPicture); + private native void nativeDraw(int nativeAwPicture, Canvas canvas, + int left, int top, int right, int bottom); +} + diff --git a/android_webview/native/android_webview_jni_registrar.cc b/android_webview/native/android_webview_jni_registrar.cc index 9202999..4ee5a3b 100644 --- a/android_webview/native/android_webview_jni_registrar.cc +++ b/android_webview/native/android_webview_jni_registrar.cc @@ -11,6 +11,7 @@ #include "android_webview/native/aw_contents_io_thread_client_impl.h" #include "android_webview/native/aw_form_database.h" #include "android_webview/native/aw_http_auth_handler.h" +#include "android_webview/native/aw_picture.h" #include "android_webview/native/aw_quota_manager_bridge_impl.h" #include "android_webview/native/aw_resource.h" #include "android_webview/native/aw_settings.h" @@ -31,8 +32,9 @@ static base::android::RegistrationMethod kWebViewRegisteredMethods[] = { { "AwAutofillManagerDelegate", RegisterAwAutofillManagerDelegate }, { "AwContents", RegisterAwContents }, { "AwContentsClientBridge", RegisterAwContentsClientBridge }, - { "AwContentsIoThreadClientImpl", RegisterAwContentsIoThreadClientImpl}, - { "AwFormDatabase", RegisterAwFormDatabase}, + { "AwContentsIoThreadClientImpl", RegisterAwContentsIoThreadClientImpl }, + { "AwFormDatabase", RegisterAwFormDatabase }, + { "AwPicture", RegisterAwPicture }, { "AwSettings", RegisterAwSettings }, { "AwHttpAuthHandler", RegisterAwHttpAuthHandler }, { "AwQuotaManagerBridge", RegisterAwQuotaManagerBridge }, diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index 4ef093e..4cabfe4 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -15,6 +15,7 @@ #include "android_webview/native/aw_browser_dependency_factory.h" #include "android_webview/native/aw_contents_client_bridge.h" #include "android_webview/native/aw_contents_io_thread_client_impl.h" +#include "android_webview/native/aw_picture.h" #include "android_webview/native/aw_web_contents_delegate.h" #include "android_webview/native/java_browser_view_renderer_helper.h" #include "android_webview/native/state_serializer.h" @@ -45,6 +46,7 @@ #include "content/public/common/ssl_status.h" #include "jni/AwContents_jni.h" #include "net/cert/x509_certificate.h" +#include "third_party/skia/include/core/SkPicture.h" #include "ui/base/l10n/l10n_util_android.h" #include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/image/image.h" @@ -84,9 +86,7 @@ namespace android_webview { namespace { JavaBrowserViewRendererHelper* java_renderer_helper() { - static JavaBrowserViewRendererHelper* g_instance - = new JavaBrowserViewRendererHelper; - return g_instance; + return JavaBrowserViewRendererHelper::GetInstance(); } const void* kAwContentsUserDataKey = &kAwContentsUserDataKey; @@ -758,11 +758,12 @@ void AwContents::OnWebLayoutPageScaleFactorChanged(float page_scale_factor) { page_scale_factor); } -ScopedJavaLocalRef AwContents::CapturePicture(JNIEnv* env, - jobject obj, - int width, - int height) { - return browser_view_renderer_->CapturePicture(width, height); +jint AwContents::CapturePicture(JNIEnv* env, + jobject obj, + int width, + int height) { + return reinterpret_cast(new AwPicture( + browser_view_renderer_->CapturePicture(width, height))); } void AwContents::EnableOnNewPicture(JNIEnv* env, diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h index 270201a..38b433d 100644 --- a/android_webview/native/aw_contents.h +++ b/android_webview/native/aw_contents.h @@ -117,10 +117,7 @@ class AwContents : public FindHelper::Listener, jint visible_right, jint visible_bottom); jint GetAwDrawGLViewContext(JNIEnv* env, jobject obj); - base::android::ScopedJavaLocalRef CapturePicture(JNIEnv* env, - jobject obj, - int width, - int height); + jint CapturePicture(JNIEnv* env, jobject obj, int width, int height); void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled); // Geolocation API support diff --git a/android_webview/native/aw_picture.cc b/android_webview/native/aw_picture.cc new file mode 100644 index 0000000..bc02b5b --- /dev/null +++ b/android_webview/native/aw_picture.cc @@ -0,0 +1,56 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/native/aw_picture.h" + +#include "android_webview/browser/in_process_view_renderer.h" +#include "android_webview/native/java_browser_view_renderer_helper.h" +#include "jni/AwPicture_jni.h" +#include "third_party/skia/include/core/SkPicture.h" + +namespace android_webview { + +AwPicture::AwPicture(skia::RefPtr picture) + : picture_(picture) { + DCHECK(picture_); +} + +AwPicture::~AwPicture() {} + +void AwPicture::Destroy(JNIEnv* env, jobject obj) { + delete this; +} + +jint AwPicture::GetWidth(JNIEnv* env, jobject obj) { + return picture_->width(); +} + +jint AwPicture::GetHeight(JNIEnv* env, jobject obj) { + return picture_->height(); +} + +namespace { +bool RenderPictureToCanvas(SkPicture* picture, SkCanvas* canvas) { + picture->draw(canvas); + return true; +} +} + +void AwPicture::Draw(JNIEnv* env, jobject obj, jobject canvas, + jint left, jint top, jint right, jint bottom) { + bool ok = InProcessViewRenderer::RenderViaAuxilaryBitmapIfNeeded( + canvas, + JavaBrowserViewRendererHelper::GetInstance(), + gfx::Vector2d(), + gfx::Rect(left, top, right - left, bottom - top), + base::Bind(&RenderPictureToCanvas, base::Unretained(picture_.get())), + this); + LOG_IF(ERROR, !ok) << "Couldn't draw picture"; +} + +bool RegisterAwPicture(JNIEnv* env) { + return RegisterNativesImpl(env) >= 0; +} + +} // namespace android_webview diff --git a/android_webview/native/aw_picture.h b/android_webview/native/aw_picture.h new file mode 100644 index 0000000..2cbb5b7 --- /dev/null +++ b/android_webview/native/aw_picture.h @@ -0,0 +1,42 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ANDROID_WEBVIEW_NATIVE_AW_PICTURE_H_ +#define ANDROID_WEBVIEW_NATIVE_AW_PICTURE_H_ + +#include + +#include "base/android/jni_helper.h" +#include "base/android/scoped_java_ref.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/web_contents_observer.h" +#include "skia/ext/refptr.h" + +class SkPicture; + +namespace android_webview { + +class AwPicture { + public: + AwPicture(skia::RefPtr picture); + ~AwPicture(); + + // Methods called from Java. + void Destroy(JNIEnv* env, jobject obj); + jint GetWidth(JNIEnv* env, jobject obj); + jint GetHeight(JNIEnv* env, jobject obj); + void Draw(JNIEnv* env, jobject obj, jobject canvas, + jint left, jint top, jint right, jint bottom); + + private: + skia::RefPtr picture_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(AwPicture); +}; + +bool RegisterAwPicture(JNIEnv* env); + +} // android_webview + +#endif // ANDROID_WEBVIEW_NATIVE_AW_PICTURE_ diff --git a/android_webview/native/java_browser_view_renderer_helper.cc b/android_webview/native/java_browser_view_renderer_helper.cc index 0426bd1..b72e037 100644 --- a/android_webview/native/java_browser_view_renderer_helper.cc +++ b/android_webview/native/java_browser_view_renderer_helper.cc @@ -18,6 +18,13 @@ JavaBrowserViewRendererHelper::JavaBrowserViewRendererHelper() { JavaBrowserViewRendererHelper::~JavaBrowserViewRendererHelper() { } +// static +JavaBrowserViewRendererHelper* JavaBrowserViewRendererHelper::GetInstance() { + static JavaBrowserViewRendererHelper* g_instance = + new JavaBrowserViewRendererHelper; + return g_instance; +} + ScopedJavaLocalRef JavaBrowserViewRendererHelper::CreateBitmap( JNIEnv* env, int width, diff --git a/android_webview/native/java_browser_view_renderer_helper.h b/android_webview/native/java_browser_view_renderer_helper.h index 2d1aadc..986d737 100644 --- a/android_webview/native/java_browser_view_renderer_helper.h +++ b/android_webview/native/java_browser_view_renderer_helper.h @@ -18,6 +18,8 @@ class JavaBrowserViewRendererHelper : public BrowserViewRenderer::JavaHelper { JavaBrowserViewRendererHelper(); virtual ~JavaBrowserViewRendererHelper(); + static JavaBrowserViewRendererHelper* GetInstance(); + // BrowserViewRenderer::JavaHelper implementation. virtual base::android::ScopedJavaLocalRef CreateBitmap( JNIEnv* env, diff --git a/android_webview/native/webview_native.gyp b/android_webview/native/webview_native.gyp index bc6d0e5..b1d7082 100644 --- a/android_webview/native/webview_native.gyp +++ b/android_webview/native/webview_native.gyp @@ -50,6 +50,8 @@ 'aw_geolocation_permission_context.h', 'aw_http_auth_handler.cc', 'aw_http_auth_handler.h', + 'aw_picture.cc', + 'aw_picture.h', 'aw_quota_manager_bridge_impl.cc', 'aw_quota_manager_bridge_impl.h', 'aw_resource.cc', @@ -94,6 +96,7 @@ '../java/src/org/chromium/android_webview/AwCookieManager.java', '../java/src/org/chromium/android_webview/AwFormDatabase.java', '../java/src/org/chromium/android_webview/AwHttpAuthHandler.java', + '../java/src/org/chromium/android_webview/AwPicture.java', '../java/src/org/chromium/android_webview/AwQuotaManagerBridge.java', '../java/src/org/chromium/android_webview/AwResource.java', '../java/src/org/chromium/android_webview/AwSettings.java', -- cgit v1.1