1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.view; 18 19import android.graphics.Bitmap; 20import android.graphics.Canvas; 21import android.graphics.CanvasProperty; 22import android.graphics.Paint; 23import android.graphics.Rect; 24 25/** 26 * Hardware accelerated canvas. 27 * 28 * @hide 29 */ 30public abstract class HardwareCanvas extends Canvas { 31 32 @Override 33 public boolean isHardwareAccelerated() { 34 return true; 35 } 36 37 @Override 38 public void setBitmap(Bitmap bitmap) { 39 throw new UnsupportedOperationException(); 40 } 41 42 /** 43 * Invoked before any drawing operation is performed in this canvas. 44 * 45 * @param dirty The dirty rectangle to update, can be null. 46 * @return {@link RenderNode#STATUS_DREW} if anything was drawn (such as a call to clear 47 * the canvas). 48 * 49 * @hide 50 */ 51 public abstract int onPreDraw(Rect dirty); 52 53 /** 54 * Invoked after all drawing operation have been performed. 55 * 56 * @hide 57 */ 58 public abstract void onPostDraw(); 59 60 /** 61 * Draws the specified display list onto this canvas. The display list can only 62 * be drawn if {@link android.view.RenderNode#isValid()} returns true. 63 * 64 * @param renderNode The RenderNode to replay. 65 */ 66 public void drawRenderNode(RenderNode renderNode) { 67 drawRenderNode(renderNode, null, RenderNode.FLAG_CLIP_CHILDREN); 68 } 69 70 /** 71 * Draws the specified display list onto this canvas. 72 * 73 * @param renderNode The RenderNode to replay. 74 * @param dirty Ignored, can be null. 75 * @param flags Optional flags about drawing, see {@link RenderNode} for 76 * the possible flags. 77 * 78 * @return One of {@link RenderNode#STATUS_DONE} or {@link RenderNode#STATUS_DREW} 79 * if anything was drawn. 80 * 81 * @hide 82 */ 83 public abstract int drawRenderNode(RenderNode renderNode, Rect dirty, int flags); 84 85 /** 86 * Draws the specified layer onto this canvas. 87 * 88 * @param layer The layer to composite on this canvas 89 * @param x The left coordinate of the layer 90 * @param y The top coordinate of the layer 91 * @param paint The paint used to draw the layer 92 * 93 * @hide 94 */ 95 abstract void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint); 96 97 /** 98 * Calls the function specified with the drawGLFunction function pointer. This is 99 * functionality used by webkit for calling into their renderer from our display lists. 100 * This function may return true if an invalidation is needed after the call. 101 * 102 * @param drawGLFunction A native function pointer 103 * 104 * @return {@link RenderNode#STATUS_DONE} 105 * 106 * @hide 107 */ 108 public abstract int callDrawGLFunction2(long drawGLFunction); 109 110 public abstract void drawCircle(CanvasProperty<Float> cx, CanvasProperty<Float> cy, 111 CanvasProperty<Float> radius, CanvasProperty<Paint> paint); 112 113 public abstract void drawRoundRect(CanvasProperty<Float> left, CanvasProperty<Float> top, 114 CanvasProperty<Float> right, CanvasProperty<Float> bottom, 115 CanvasProperty<Float> rx, CanvasProperty<Float> ry, 116 CanvasProperty<Paint> paint); 117 118 public static void setProperty(String name, String value) { 119 GLES20Canvas.setProperty(name, value); 120 } 121} 122