OLD | NEW |
(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 } |
OLD | NEW |