1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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<SkPicture> 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
|