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/native/java_browser_view_renderer_helper.h" | |
8 #include "base/bind.h" | |
9 #include "jni/AwPicture_jni.h" | |
10 #include "third_party/skia/include/core/SkPicture.h" | |
11 | |
12 using base::android::JavaParamRef; | |
13 | |
14 namespace android_webview { | |
15 | |
16 AwPicture::AwPicture(sk_sp<SkPicture> picture) | |
17 : picture_(std::move(picture)) { | |
18 DCHECK(picture_); | |
19 } | |
20 | |
21 AwPicture::~AwPicture() {} | |
22 | |
23 void AwPicture::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | |
24 delete this; | |
25 } | |
26 | |
27 jint AwPicture::GetWidth(JNIEnv* env, const JavaParamRef<jobject>& obj) { | |
28 return picture_->cullRect().roundOut().width(); | |
29 } | |
30 | |
31 jint AwPicture::GetHeight(JNIEnv* env, const JavaParamRef<jobject>& obj) { | |
32 return picture_->cullRect().roundOut().height(); | |
33 } | |
34 | |
35 void AwPicture::Draw(JNIEnv* env, | |
36 const JavaParamRef<jobject>& obj, | |
37 const JavaParamRef<jobject>& canvas) { | |
38 const SkIRect bounds = picture_->cullRect().roundOut(); | |
39 std::unique_ptr<SoftwareCanvasHolder> canvas_holder = | |
40 SoftwareCanvasHolder::Create(canvas, gfx::Vector2d(), | |
41 gfx::Size(bounds.width(), bounds.height()), | |
42 false); | |
43 if (!canvas_holder || !canvas_holder->GetCanvas()) { | |
44 LOG(ERROR) << "Couldn't draw picture"; | |
45 return; | |
46 } | |
47 picture_->playback(canvas_holder->GetCanvas()); | |
48 } | |
49 | |
50 bool RegisterAwPicture(JNIEnv* env) { | |
51 return RegisterNativesImpl(env); | |
52 } | |
53 | |
54 } // namespace android_webview | |
OLD | NEW |