Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Unified Diff: platform_tools/android/apps/canvasproof/src/main/java/org/skia/canvasproof/HwuiPictureView.java

Issue 1258123004: android/apps: Add CanvasProof App; (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-09-04 (Friday) 13:29:02 EDT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..872089c9d304fb68adc00cff1a5ae2f2e5e0e1bf
--- /dev/null
+++ b/platform_tools/android/apps/canvasproof/src/main/java/org/skia/canvasproof/HwuiPictureView.java
@@ -0,0 +1,72 @@
+/*
+ * 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";
+ private Picture picture;
+ private float scale;
+ private Picture defaultPicture;
+
+ public boolean fullTime;
+
+ HwuiPictureView(Context context) {
+ super(context);
+ this.scale = 1.0f;
+ }
+ public void setScale(float s) {
+ this.scale = s;
+ }
+ public void setPicture(Picture p) {
+ this.picture = p;
+ this.invalidate();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (this.picture != null) {
+ canvas.save();
+ canvas.scale(scale, scale);
+ HwuiPictureView.draw(canvas, this.picture);
+ canvas.restore();
+ if (fullTime) {
+ this.invalidate();
+ }
+ }
+ }
+
+ static private void draw(Canvas canvas, Picture p) {
+ if (android.os.Build.VERSION.SDK_INT > 22) {
+ try {
+ canvas.drawPicture(p);
+ return;
+ } catch (java.lang.Exception e) {
+ Log.e(TAG, "Exception while drawing picture in Hwui");
+ }
+ }
+ if (p.getWidth() > 0 && p.getHeight() > 0) {
+ // Fallback to software rendering.
+ Bitmap bm = Bitmap.createBitmap(p.getWidth(), p.getHeight(),
+ Bitmap.Config.ARGB_8888);
+ (new Canvas(bm)).drawPicture(p);
+ canvas.drawBitmap(bm, 0.0f, 0.0f, null);
+ bm.recycle();
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698