Port Android relocation packer to chromium build
[chromium-blink-merge.git] / android_webview / native / aw_picture.cc
blob348e1a0aefe1e2fce37cd01cd8162f5e2268926e
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.
5 #include "android_webview/native/aw_picture.h"
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"
12 namespace android_webview {
14 AwPicture::AwPicture(skia::RefPtr<SkPicture> picture)
15 : picture_(picture) {
16 DCHECK(picture_);
19 AwPicture::~AwPicture() {}
21 void AwPicture::Destroy(JNIEnv* env, jobject obj) {
22 delete this;
25 jint AwPicture::GetWidth(JNIEnv* env, jobject obj) {
26 return picture_->cullRect().roundOut().width();
29 jint AwPicture::GetHeight(JNIEnv* env, jobject obj) {
30 return picture_->cullRect().roundOut().height();
33 void AwPicture::Draw(JNIEnv* env, jobject obj, jobject canvas) {
34 const SkIRect bounds = picture_->cullRect().roundOut();
35 scoped_ptr<SoftwareCanvasHolder> canvas_holder = SoftwareCanvasHolder::Create(
36 canvas, gfx::Vector2d(),
37 gfx::Size(bounds.width(), bounds.height()));
38 if (!canvas_holder || !canvas_holder->GetCanvas()) {
39 LOG(ERROR) << "Couldn't draw picture";
40 return;
42 picture_->playback(canvas_holder->GetCanvas());
45 bool RegisterAwPicture(JNIEnv* env) {
46 return RegisterNativesImpl(env);
49 } // namespace android_webview