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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 package org.skia.canvasproof;
9
10 import android.content.Context;
11 import android.graphics.Bitmap;
12 import android.graphics.Canvas;
13 import android.graphics.Color;
14 import android.graphics.Paint;
15 import android.graphics.Picture;
16 import android.util.Log;
17 import android.view.View;
18 import java.io.IOException;
19 import java.io.InputStream;
20
21 public class HwuiPictureView extends View {
22 private static final String TAG = "HwuiPictureView";
23 private Picture picture;
24 private float scale;
25 private Picture defaultPicture;
26
27 public boolean fullTime;
28
29 HwuiPictureView(Context context) {
30 super(context);
31 this.scale = 1.0f;
32 }
33 public void setScale(float s) {
34 this.scale = s;
35 }
36 public void setPicture(Picture p) {
37 this.picture = p;
38 this.invalidate();
39 }
40
41 @Override
42 protected void onDraw(Canvas canvas) {
43 if (this.picture != null) {
44 canvas.save();
45 canvas.scale(scale, scale);
46 HwuiPictureView.draw(canvas, this.picture);
47 canvas.restore();
48 if (fullTime) {
49 this.invalidate();
50 }
51 }
52 }
53
54 static private void draw(Canvas canvas, Picture p) {
55 if (android.os.Build.VERSION.SDK_INT > 22) {
56 try {
57 canvas.drawPicture(p);
58 return;
59 } catch (java.lang.Exception e) {
60 Log.e(TAG, "Exception while drawing picture in Hwui");
61 }
62 }
63 if (p.getWidth() > 0 && p.getHeight() > 0) {
64 // Fallback to software rendering.
65 Bitmap bm = Bitmap.createBitmap(p.getWidth(), p.getHeight(),
66 Bitmap.Config.ARGB_8888);
67 (new Canvas(bm)).drawPicture(p);
68 canvas.drawBitmap(bm, 0.0f, 0.0f, null);
69 bm.recycle();
70 }
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698