OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "android_webview/native/aw_picture.h" |
| 6 |
| 7 #include "android_webview/browser/in_process_view_renderer.h" |
| 8 #include "android_webview/native/java_browser_view_renderer_helper.h" |
| 9 #include "jni/AwPicture_jni.h" |
| 10 #include "third_party/skia/include/core/SkPicture.h" |
| 11 |
| 12 namespace android_webview { |
| 13 |
| 14 AwPicture::AwPicture(skia::RefPtr<SkPicture> picture) |
| 15 : picture_(picture) { |
| 16 DCHECK(picture_); |
| 17 } |
| 18 |
| 19 void AwPicture::Destroy(JNIEnv* env, jobject obj) { |
| 20 delete this; |
| 21 } |
| 22 |
| 23 jint AwPicture::GetWidth(JNIEnv* env, jobject obj) { |
| 24 return picture_->width(); |
| 25 } |
| 26 |
| 27 jint AwPicture::GetHeight(JNIEnv* env, jobject obj) { |
| 28 return picture_->height(); |
| 29 } |
| 30 |
| 31 namespace { |
| 32 bool RenderPictureToCanvas(SkPicture* picture, SkCanvas* canvas) { |
| 33 picture->draw(canvas); |
| 34 return true; |
| 35 } |
| 36 } |
| 37 |
| 38 void AwPicture::Draw(JNIEnv* env, jobject obj, jobject canvas, |
| 39 jint left, jint top, jint right, jint bottom) { |
| 40 bool ok = InProcessViewRenderer::RenderViaAuxilaryBitmapIfNeeded( |
| 41 canvas, |
| 42 JavaBrowserViewRendererHelper::GetInstance(), |
| 43 gfx::Vector2d(), |
| 44 gfx::Rect(left, top, right - left, bottom - top), |
| 45 base::Bind(&RenderPictureToCanvas, base::Unretained(picture_.get())), |
| 46 this); |
| 47 LOG_IF(ERROR, !ok) << "Couldn't draw picture"; |
| 48 } |
| 49 |
| 50 bool RegisterAwPicture(JNIEnv* env) { |
| 51 return RegisterNativesImpl(env) >= 0; |
| 52 } |
| 53 |
| 54 } // namespace android_webview |
OLD | NEW |