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

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: swipe down to switch views Created 5 years, 4 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..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
tomhudson 2015/08/24 20:10:25 Tell us why. (Also, this doesn't seem to be @overr
hal.canary 2015/08/31 21:16:56 removed. Dang. This was taking an input stream r
+ 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;
+
+}

Powered by Google App Engine
This is Rietveld 408576698