| Index: platform_tools/android/apps/canvasproof/src/main/java/org/skia/canvasproof/HwuiPictureView.java
|
| diff --git a/platform_tools/android/apps/canvasproof/src/main/java/org/skia/canvasproof/HwuiPictureView.java b/platform_tools/android/apps/canvasproof/src/main/java/org/skia/canvasproof/HwuiPictureView.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5dfbfa0b70feb06f9696ce0070c8571503ac33ac
|
| --- /dev/null
|
| +++ b/platform_tools/android/apps/canvasproof/src/main/java/org/skia/canvasproof/HwuiPictureView.java
|
| @@ -0,0 +1,75 @@
|
| +/*
|
| + * Copyright 2015 Google Inc.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +package org.skia.canvasproof;
|
| +
|
| +import android.content.Context;
|
| +import android.graphics.Bitmap;
|
| +import android.graphics.Canvas;
|
| +import android.graphics.Color;
|
| +import android.graphics.Paint;
|
| +import android.graphics.Picture;
|
| +import android.util.Log;
|
| +import android.view.View;
|
| +import java.io.IOException;
|
| +import java.io.InputStream;
|
| +
|
| +public class HwuiPictureView extends View {
|
| + private static final String TAG = "HwuiPictureView";
|
| +
|
| + HwuiPictureView(Context context) {
|
| + super(context);
|
| + this.scale = 1.0f;
|
| + }
|
| + public void setScale(float s) {
|
| + this.scale = s;
|
| + }
|
| + @SuppressWarnings("deprecation") // purposely using this
|
| + public void setPicture(Picture p) {
|
| + this.picture = p;
|
| + this.invalidate();
|
| + }
|
| +
|
| + @Override
|
| + protected void onDraw(Canvas canvas) {
|
| + if (this.picture != null) {
|
| + long now = System.currentTimeMillis();
|
| + canvas.save();
|
| + canvas.scale(scale, scale);
|
| + HwuiPictureView.draw(canvas, this.picture);
|
| + canvas.restore();
|
| + Log.v(TAG, String.format("RENDER TIME: %d",
|
| + System.currentTimeMillis() - now));
|
| + }
|
| +
|
| + }
|
| +
|
| + static private void draw(Canvas canvas, Picture p) {
|
| + if (android.os.Build.VERSION.SDK_INT > 22) {
|
| + try {
|
| + p.draw(canvas);
|
| + return;
|
| + } catch (java.lang.Exception e) {
|
| + Log.e(TAG, "Exception while drawing picture in Hwui");
|
| + }
|
| + }
|
| + if (p.getWidth() > 0 && p.getHeight() > 0) {
|
| + Bitmap bm = Bitmap.createBitmap(p.getWidth(), p.getHeight(),
|
| + Bitmap.Config.ARGB_8888);
|
| + p.draw(new Canvas(bm));
|
| + canvas.drawBitmap(bm, 0.0f, 0.0f, null);
|
| + bm.recycle();
|
| + } else {
|
| + Log.v(TAG, String.format("picture = (%d x %d)",
|
| + p.getWidth(),p.getHeight()));
|
| + }
|
| + }
|
| + Picture picture;
|
| + float scale;
|
| + Picture defaultPicture;
|
| +
|
| +}
|
|
|