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.Paint;
22import android.graphics.Rect;
23
24/**
25 * Hardware accelerated canvas.
26 *
27 * @hide
28 */
29public abstract class HardwareCanvas extends Canvas {
30    @Override
31    public boolean isHardwareAccelerated() {
32        return true;
33    }
34
35    @Override
36    public void setBitmap(Bitmap bitmap) {
37        throw new UnsupportedOperationException();
38    }
39
40    /**
41     * Invoked before any drawing operation is performed in this canvas.
42     *
43     * @param dirty The dirty rectangle to update, can be null.
44     * @return {@link DisplayList#STATUS_DREW} if anything was drawn (such as a call to clear
45     * the canvas).
46     */
47    public abstract int onPreDraw(Rect dirty);
48
49    /**
50     * Invoked after all drawing operation have been performed.
51     */
52    public abstract void onPostDraw();
53
54    /**
55     * Draws the specified display list onto this canvas.
56     *
57     * @param displayList The display list to replay.
58     * @param dirty The dirty region to redraw in the next pass, matters only
59     *        if this method returns true, can be null.
60     * @param flags Optional flags about drawing, see {@link DisplayList} for
61     *              the possible flags.
62     *
63     * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW}, or
64     *         {@link DisplayList#STATUS_INVOKE}, or'd with {@link DisplayList#STATUS_DREW}
65     *         if anything was drawn.
66     */
67    public abstract int drawDisplayList(DisplayList displayList, Rect dirty, int flags);
68
69    /**
70     * Outputs the specified display list to the log. This method exists for use by
71     * tools to output display lists for selected nodes to the log.
72     *
73     * @param displayList The display list to be logged.
74     */
75    abstract void outputDisplayList(DisplayList displayList);
76
77    /**
78     * Draws the specified layer onto this canvas.
79     *
80     * @param layer The layer to composite on this canvas
81     * @param x The left coordinate of the layer
82     * @param y The top coordinate of the layer
83     * @param paint The paint used to draw the layer
84     */
85    abstract void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint);
86
87    /**
88     * Calls the function specified with the drawGLFunction function pointer. This is
89     * functionality used by webkit for calling into their renderer from our display lists.
90     * This function may return true if an invalidation is needed after the call.
91     *
92     * @param drawGLFunction A native function pointer
93     *
94     * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or
95     *         {@link DisplayList#STATUS_INVOKE}
96     */
97    public int callDrawGLFunction(int drawGLFunction) {
98        // Noop - this is done in the display list recorder subclass
99        return DisplayList.STATUS_DONE;
100    }
101
102    /**
103     * Invoke all the functors who requested to be invoked during the previous frame.
104     *
105     * @param dirty The region to redraw when the functors return {@link DisplayList#STATUS_DRAW}
106     *
107     * @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or
108     *         {@link DisplayList#STATUS_INVOKE}
109     */
110    public int invokeFunctors(Rect dirty) {
111        return DisplayList.STATUS_DONE;
112    }
113
114    /**
115     * Detaches the specified functor from the current functor execution queue.
116     *
117     * @param functor The native functor to remove from the execution queue.
118     *
119     * @see #invokeFunctors(android.graphics.Rect)
120     * @see #callDrawGLFunction(int)
121     * @see #detachFunctor(int)
122     */
123    abstract void detachFunctor(int functor);
124
125    /**
126     * Attaches the specified functor to the current functor execution queue.
127     *
128     * @param functor The native functor to add to the execution queue.
129     *
130     * @see #invokeFunctors(android.graphics.Rect)
131     * @see #callDrawGLFunction(int)
132     * @see #detachFunctor(int)
133     */
134    abstract void attachFunctor(int functor);
135
136    /**
137     * Indicates that the specified layer must be updated as soon as possible.
138     *
139     * @param layer The layer to update
140     *
141     * @see #clearLayerUpdates()
142     */
143    abstract void pushLayerUpdate(HardwareLayer layer);
144
145    /**
146     * Removes all enqueued layer updates.
147     *
148     * @see #pushLayerUpdate(HardwareLayer)
149     */
150    abstract void clearLayerUpdates();
151}
152