blob: d01b8ce37854edf91a0ade050ca262eec735ed63 [file] [log] [blame]
Romain Guy6c319ca2011-01-11 14:29:25 -08001/*
2 * Copyright (C) 2011 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.Canvas;
20
21/**
22 * A hardware layer can be used to render graphics operations into a hardware
23 * friendly buffer. For instance, with an OpenGL backend, a hardware layer
24 * would use a Frame Buffer Object (FBO.) The hardware layer can be used as
25 * a drawing cache when a complex set of graphics operations needs to be
26 * drawn several times.
27 */
28abstract class HardwareLayer {
29 int mWidth;
30 int mHeight;
31
32 final boolean mOpaque;
33
34 /**
35 * Creates a new hardware layer at least as large as the supplied
36 * dimensions.
37 *
38 * @param width The minimum width of the layer
39 * @param height The minimum height of the layer
40 * @param isOpaque Whether the layer should be opaque or not
41 */
42 HardwareLayer(int width, int height, boolean isOpaque) {
43 mWidth = width;
44 mHeight = height;
45 mOpaque = isOpaque;
46 }
47
48 /**
49 * Returns the minimum width of the layer.
50 *
51 * @return The minimum desired width of the hardware layer
52 */
53 int getWidth() {
54 return mWidth;
55 }
56
57 /**
58 * Returns the minimum height of the layer.
59 *
60 * @return The minimum desired height of the hardware layer
61 */
62 int getHeight() {
63 return mHeight;
64 }
65
66 /**
67 * Returns whether or not this layer is opaque.
68 *
69 * @return True if the layer is opaque, false otherwise
70 */
71 boolean isOpaque() {
72 return mOpaque;
73 }
74
75 /**
76 * Indicates whether this layer can be rendered.
77 *
78 * @return True if the layer can be rendered into, false otherwise
79 */
80 abstract boolean isValid();
81
82 /**
83 * Resizes the layer, if necessary, to be at least as large
84 * as the supplied dimensions.
85 *
86 * @param width The new desired minimum width for this layer
87 * @param height The new desired minimum height for this layer
88 */
89 abstract void resize(int width, int height);
90
91 /**
92 * Returns a hardware canvas that can be used to render onto
93 * this layer.
94 *
95 * @return A hardware canvas, or null if a canvas cannot be created
96 */
97 abstract HardwareCanvas getCanvas();
98
99 /**
100 * Destroys resources without waiting for a GC.
101 */
102 abstract void destroy();
103
104 /**
105 * This must be invoked before drawing onto this layer.
106 * @param currentCanvas
107 */
108 abstract HardwareCanvas start(Canvas currentCanvas);
109
110 /**
111 * This must be invoked after drawing onto this layer.
112 * @param currentCanvas
113 */
114 abstract void end(Canvas currentCanvas);
115}