Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 1 | /* |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 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 | |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 17 | package android.view; |
| 18 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 19 | import android.graphics.Paint; |
| 20 | import android.graphics.Rect; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 21 | import android.graphics.SurfaceTexture; |
Romain Guy | 98e4a52 | 2013-01-07 10:58:34 -0800 | [diff] [blame] | 22 | import android.util.DisplayMetrics; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 23 | import android.view.Surface.OutOfResourcesException; |
| 24 | |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 25 | import java.io.File; |
Romain Guy | a676ad7 | 2012-02-13 17:47:10 -0800 | [diff] [blame] | 26 | import java.io.PrintWriter; |
Romain Guy | 484c719 | 2011-07-25 11:56:33 -0700 | [diff] [blame] | 27 | |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 28 | /** |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 29 | * Interface for rendering a view hierarchy using hardware acceleration. |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 30 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 31 | * @hide |
| 32 | */ |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 33 | public abstract class HardwareRenderer { |
Romain Guy | 4f6aff3 | 2011-01-12 16:21:41 -0800 | [diff] [blame] | 34 | static final String LOG_TAG = "HardwareRenderer"; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 35 | |
Romain Guy | 5233920 | 2010-09-03 16:04:46 -0700 | [diff] [blame] | 36 | /** |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 37 | * Name of the file that holds the shaders cache. |
| 38 | */ |
| 39 | private static final String CACHE_PATH_SHADERS = "com.android.opengl.shaders_cache"; |
| 40 | |
| 41 | /** |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 42 | * System property used to enable or disable dirty regions invalidation. |
| 43 | * This property is only queried if {@link #RENDER_DIRTY_REGIONS} is true. |
| 44 | * The default value of this property is assumed to be true. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 45 | * |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 46 | * Possible values: |
| 47 | * "true", to enable partial invalidates |
| 48 | * "false", to disable partial invalidates |
| 49 | */ |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 50 | static final String RENDER_DIRTY_REGIONS_PROPERTY = "debug.hwui.render_dirty_regions"; |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Romain Guy | a676ad7 | 2012-02-13 17:47:10 -0800 | [diff] [blame] | 53 | * System property used to enable or disable hardware rendering profiling. |
| 54 | * The default value of this property is assumed to be false. |
Chet Haase | 0928060 | 2012-04-03 16:15:34 -0700 | [diff] [blame] | 55 | * |
Romain Guy | a676ad7 | 2012-02-13 17:47:10 -0800 | [diff] [blame] | 56 | * When profiling is enabled, the adb shell dumpsys gfxinfo command will |
| 57 | * output extra information about the time taken to execute by the last |
| 58 | * frames. |
| 59 | * |
| 60 | * Possible values: |
| 61 | * "true", to enable profiling |
Romain Guy | 48ef4a9 | 2013-01-10 18:38:46 -0800 | [diff] [blame] | 62 | * "visual_bars", to enable profiling and visualize the results on screen |
| 63 | * "visual_lines", to enable profiling and visualize the results on screen |
Romain Guy | a676ad7 | 2012-02-13 17:47:10 -0800 | [diff] [blame] | 64 | * "false", to disable profiling |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 65 | * |
Romain Guy | 48ef4a9 | 2013-01-10 18:38:46 -0800 | [diff] [blame] | 66 | * @see #PROFILE_PROPERTY_VISUALIZE_BARS |
| 67 | * @see #PROFILE_PROPERTY_VISUALIZE_LINES |
Romain Guy | a4fef02 | 2013-01-07 11:18:38 -0800 | [diff] [blame] | 68 | * |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 69 | * @hide |
Romain Guy | a676ad7 | 2012-02-13 17:47:10 -0800 | [diff] [blame] | 70 | */ |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 71 | public static final String PROFILE_PROPERTY = "debug.hwui.profile"; |
Romain Guy | a676ad7 | 2012-02-13 17:47:10 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
Romain Guy | a4fef02 | 2013-01-07 11:18:38 -0800 | [diff] [blame] | 74 | * Value for {@link #PROFILE_PROPERTY}. When the property is set to this |
Romain Guy | 48ef4a9 | 2013-01-10 18:38:46 -0800 | [diff] [blame] | 75 | * value, profiling data will be visualized on screen as a bar chart. |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 76 | * |
| 77 | * @hide |
| 78 | */ |
Romain Guy | 48ef4a9 | 2013-01-10 18:38:46 -0800 | [diff] [blame] | 79 | public static final String PROFILE_PROPERTY_VISUALIZE_BARS = "visual_bars"; |
| 80 | |
| 81 | /** |
| 82 | * Value for {@link #PROFILE_PROPERTY}. When the property is set to this |
| 83 | * value, profiling data will be visualized on screen as a line chart. |
| 84 | * |
| 85 | * @hide |
| 86 | */ |
| 87 | public static final String PROFILE_PROPERTY_VISUALIZE_LINES = "visual_lines"; |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
Chet Haase | 0928060 | 2012-04-03 16:15:34 -0700 | [diff] [blame] | 90 | * System property used to specify the number of frames to be used |
| 91 | * when doing hardware rendering profiling. |
| 92 | * The default value of this property is #PROFILE_MAX_FRAMES. |
| 93 | * |
| 94 | * When profiling is enabled, the adb shell dumpsys gfxinfo command will |
| 95 | * output extra information about the time taken to execute by the last |
| 96 | * frames. |
| 97 | * |
| 98 | * Possible values: |
| 99 | * "60", to set the limit of frames to 60 |
| 100 | */ |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 101 | static final String PROFILE_MAXFRAMES_PROPERTY = "debug.hwui.profile.maxframes"; |
Chet Haase | 0928060 | 2012-04-03 16:15:34 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
Romain Guy | 484c719 | 2011-07-25 11:56:33 -0700 | [diff] [blame] | 104 | * System property used to debug EGL configuration choice. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 105 | * |
Romain Guy | 484c719 | 2011-07-25 11:56:33 -0700 | [diff] [blame] | 106 | * Possible values: |
Romain Guy | 484c719 | 2011-07-25 11:56:33 -0700 | [diff] [blame] | 107 | * "choice", print the chosen configuration only |
| 108 | * "all", print all possible configurations |
| 109 | */ |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 110 | static final String PRINT_CONFIG_PROPERTY = "debug.hwui.print_config"; |
Romain Guy | 484c719 | 2011-07-25 11:56:33 -0700 | [diff] [blame] | 111 | |
| 112 | /** |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 113 | * Turn on to draw dirty regions every other frame. |
Romain Guy | b04f7e9 | 2012-02-15 12:36:54 -0800 | [diff] [blame] | 114 | * |
| 115 | * Possible values: |
| 116 | * "true", to enable dirty regions debugging |
| 117 | * "false", to disable dirty regions debugging |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 118 | * |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 119 | * @hide |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 120 | */ |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 121 | public static final String DEBUG_DIRTY_REGIONS_PROPERTY = "debug.hwui.show_dirty_regions"; |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * Turn on to flash hardware layers when they update. |
| 125 | * |
| 126 | * Possible values: |
| 127 | * "true", to enable hardware layers updates debugging |
| 128 | * "false", to disable hardware layers updates debugging |
| 129 | * |
| 130 | * @hide |
| 131 | */ |
| 132 | public static final String DEBUG_SHOW_LAYERS_UPDATES_PROPERTY = |
| 133 | "debug.hwui.show_layers_updates"; |
| 134 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 135 | /** |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 136 | * Controls overdraw debugging. |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 137 | * |
| 138 | * Possible values: |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 139 | * "false", to disable overdraw debugging |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 140 | * "show", to show overdraw areas on screen |
| 141 | * "count", to display an overdraw counter |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 142 | * |
| 143 | * @hide |
| 144 | */ |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 145 | public static final String DEBUG_OVERDRAW_PROPERTY = "debug.hwui.overdraw"; |
| 146 | |
| 147 | /** |
| 148 | * Value for {@link #DEBUG_OVERDRAW_PROPERTY}. When the property is set to this |
| 149 | * value, overdraw will be shown on screen by coloring pixels. |
| 150 | * |
| 151 | * @hide |
| 152 | */ |
| 153 | public static final String OVERDRAW_PROPERTY_SHOW = "show"; |
| 154 | |
| 155 | /** |
Romain Guy | 08bca88 | 2013-02-25 16:21:30 -0800 | [diff] [blame] | 156 | * Turn on to debug non-rectangular clip operations. |
| 157 | * |
| 158 | * Possible values: |
| 159 | * "hide", to disable this debug mode |
| 160 | * "highlight", highlight drawing commands tested against a non-rectangular clip |
| 161 | * "stencil", renders the clip region on screen when set |
| 162 | * |
| 163 | * @hide |
| 164 | */ |
| 165 | public static final String DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY = |
| 166 | "debug.hwui.show_non_rect_clip"; |
| 167 | |
| 168 | /** |
Romain Guy | 5233920 | 2010-09-03 16:04:46 -0700 | [diff] [blame] | 169 | * A process can set this flag to false to prevent the use of hardware |
| 170 | * rendering. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 171 | * |
Romain Guy | 5233920 | 2010-09-03 16:04:46 -0700 | [diff] [blame] | 172 | * @hide |
| 173 | */ |
| 174 | public static boolean sRendererDisabled = false; |
| 175 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 176 | /** |
| 177 | * Further hardware renderer disabling for the system process. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 178 | * |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 179 | * @hide |
| 180 | */ |
| 181 | public static boolean sSystemRendererDisabled = false; |
| 182 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 183 | /** @hide */ |
| 184 | public static boolean sUseRenderThread = false; |
| 185 | |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 186 | private boolean mEnabled; |
| 187 | private boolean mRequested = true; |
| 188 | |
| 189 | /** |
Romain Guy | 67f2795 | 2010-12-07 20:09:23 -0800 | [diff] [blame] | 190 | * Invoke this method to disable hardware rendering in the current process. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 191 | * |
Romain Guy | 5233920 | 2010-09-03 16:04:46 -0700 | [diff] [blame] | 192 | * @hide |
| 193 | */ |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 194 | public static void disable(boolean system) { |
Romain Guy | 5233920 | 2010-09-03 16:04:46 -0700 | [diff] [blame] | 195 | sRendererDisabled = true; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 196 | if (system) { |
| 197 | sSystemRendererDisabled = true; |
| 198 | } |
Romain Guy | 5233920 | 2010-09-03 16:04:46 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /** |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 202 | * Indicates whether hardware acceleration is available under any form for |
| 203 | * the view hierarchy. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 204 | * |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 205 | * @return True if the view hierarchy can potentially be hardware accelerated, |
| 206 | * false otherwise |
| 207 | */ |
| 208 | public static boolean isAvailable() { |
| 209 | return GLES20Canvas.isAvailable(); |
| 210 | } |
| 211 | |
| 212 | /** |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 213 | * Destroys the hardware rendering context. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 214 | * |
Romain Guy | 4caa4ed | 2010-08-25 14:46:24 -0700 | [diff] [blame] | 215 | * @param full If true, destroys all associated resources. |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 216 | */ |
Romain Guy | 4caa4ed | 2010-08-25 14:46:24 -0700 | [diff] [blame] | 217 | abstract void destroy(boolean full); |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * Initializes the hardware renderer for the specified surface. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 221 | * |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 222 | * @param surface The surface to hardware accelerate |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 223 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 224 | * @return True if the initialization was successful, false otherwise. |
| 225 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 226 | abstract boolean initialize(Surface surface) throws OutOfResourcesException; |
| 227 | |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 228 | /** |
| 229 | * Updates the hardware renderer for the specified surface. |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 230 | * |
| 231 | * @param surface The surface to hardware accelerate |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 232 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 233 | abstract void updateSurface(Surface surface) throws OutOfResourcesException; |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 234 | |
| 235 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 236 | * Destroys the layers used by the specified view hierarchy. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 237 | * |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 238 | * @param view The root of the view hierarchy |
| 239 | */ |
| 240 | abstract void destroyLayers(View view); |
| 241 | |
| 242 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 243 | * Destroys all hardware rendering resources associated with the specified |
| 244 | * view hierarchy. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 245 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 246 | * @param view The root of the view hierarchy |
| 247 | */ |
| 248 | abstract void destroyHardwareResources(View view); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 249 | |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 250 | /** |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 251 | * This method should be invoked whenever the current hardware renderer |
Romain Guy | cf15efb | 2011-08-02 12:59:32 -0700 | [diff] [blame] | 252 | * context should be reset. |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 253 | * |
| 254 | * @param surface The surface to hardware accelerate |
Romain Guy | 7e1160e | 2011-07-08 15:49:50 -0700 | [diff] [blame] | 255 | */ |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 256 | abstract void invalidate(Surface surface); |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * This method should be invoked to ensure the hardware renderer is in |
| 260 | * valid state (for instance, to ensure the correct EGL context is bound |
| 261 | * to the current thread.) |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 262 | * |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 263 | * @return true if the renderer is now valid, false otherwise |
| 264 | */ |
| 265 | abstract boolean validate(); |
Romain Guy | 7e1160e | 2011-07-08 15:49:50 -0700 | [diff] [blame] | 266 | |
| 267 | /** |
Romain Guy | 1ac4765 | 2012-04-11 18:15:20 -0700 | [diff] [blame] | 268 | * This method ensures the hardware renderer is in a valid state |
| 269 | * before executing the specified action. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 270 | * |
Romain Guy | 1ac4765 | 2012-04-11 18:15:20 -0700 | [diff] [blame] | 271 | * This method will attempt to set a valid state even if the window |
| 272 | * the renderer is attached to was destroyed. |
| 273 | * |
| 274 | * @return true if the action was run |
| 275 | */ |
| 276 | abstract boolean safelyRun(Runnable action); |
| 277 | |
| 278 | /** |
Romain Guy | 7e1160e | 2011-07-08 15:49:50 -0700 | [diff] [blame] | 279 | * Setup the hardware renderer for drawing. This is called whenever the |
| 280 | * size of the target surface changes or when the surface is first created. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 281 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 282 | * @param width Width of the drawing surface. |
| 283 | * @param height Height of the drawing surface. |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 284 | */ |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 285 | abstract void setup(int width, int height); |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 286 | |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 287 | /** |
Chet Haase | 40e0383 | 2011-10-06 08:34:13 -0700 | [diff] [blame] | 288 | * Gets the current width of the surface. This is the width that the surface |
| 289 | * was last set to in a call to {@link #setup(int, int)}. |
| 290 | * |
| 291 | * @return the current width of the surface |
| 292 | */ |
| 293 | abstract int getWidth(); |
| 294 | |
| 295 | /** |
| 296 | * Gets the current height of the surface. This is the height that the surface |
| 297 | * was last set to in a call to {@link #setup(int, int)}. |
| 298 | * |
| 299 | * @return the current width of the surface |
| 300 | */ |
| 301 | abstract int getHeight(); |
| 302 | |
| 303 | /** |
Romain Guy | a676ad7 | 2012-02-13 17:47:10 -0800 | [diff] [blame] | 304 | * Outputs extra debugging information in the specified file descriptor. |
| 305 | * @param pw |
| 306 | */ |
| 307 | abstract void dumpGfxInfo(PrintWriter pw); |
Michael Jurka | a3fabff | 2012-03-28 17:22:29 +0200 | [diff] [blame] | 308 | |
| 309 | /** |
| 310 | * Outputs the total number of frames rendered (used for fps calculations) |
| 311 | * |
| 312 | * @return the number of frames rendered |
| 313 | */ |
| 314 | abstract long getFrameCount(); |
| 315 | |
Romain Guy | a676ad7 | 2012-02-13 17:47:10 -0800 | [diff] [blame] | 316 | /** |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 317 | * Loads system properties used by the renderer. This method is invoked |
| 318 | * whenever system properties are modified. Implementations can use this |
| 319 | * to trigger live updates of the renderer based on properties. |
| 320 | * |
| 321 | * @param surface The surface to update with the new properties. |
| 322 | * Can be null. |
| 323 | * |
| 324 | * @return True if a property has changed. |
| 325 | */ |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 326 | abstract boolean loadSystemProperties(); |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 327 | |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 328 | /** |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 329 | * Sets the directory to use as a persistent storage for hardware rendering |
| 330 | * resources. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 331 | * |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 332 | * @param cacheDir A directory the current process can write to |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 333 | * |
| 334 | * @hide |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 335 | */ |
| 336 | public static void setupDiskCache(File cacheDir) { |
John Reck | 3083579 | 2013-11-07 14:21:24 -0800 | [diff] [blame] | 337 | GLRenderer.setupShadersDiskCache(new File(cacheDir, CACHE_PATH_SHADERS).getAbsolutePath()); |
Romain Guy | a958265 | 2011-11-10 14:20:10 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 340 | /** |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 341 | * Indicates that the specified hardware layer needs to be updated |
| 342 | * as soon as possible. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 343 | * |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 344 | * @param layer The hardware layer that needs an update |
Romain Guy | 4054360 | 2013-06-12 15:31:28 -0700 | [diff] [blame] | 345 | * |
| 346 | * @see #flushLayerUpdates() |
Romain Guy | e93482f | 2013-06-17 13:14:51 -0700 | [diff] [blame] | 347 | * @see #cancelLayerUpdate(HardwareLayer) |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 348 | */ |
| 349 | abstract void pushLayerUpdate(HardwareLayer layer); |
| 350 | |
| 351 | /** |
Romain Guy | e93482f | 2013-06-17 13:14:51 -0700 | [diff] [blame] | 352 | * Cancels a queued layer update. If the specified layer was not |
| 353 | * queued for update, this method has no effect. |
| 354 | * |
| 355 | * @param layer The layer whose update to cancel |
| 356 | * |
| 357 | * @see #pushLayerUpdate(HardwareLayer) |
| 358 | */ |
| 359 | abstract void cancelLayerUpdate(HardwareLayer layer); |
| 360 | |
| 361 | /** |
Romain Guy | 4054360 | 2013-06-12 15:31:28 -0700 | [diff] [blame] | 362 | * Forces all enqueued layer updates to be executed immediately. |
| 363 | * |
| 364 | * @see #pushLayerUpdate(HardwareLayer) |
| 365 | */ |
| 366 | abstract void flushLayerUpdates(); |
| 367 | |
| 368 | /** |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 369 | * Interface used to receive callbacks whenever a view is drawn by |
| 370 | * a hardware renderer instance. |
| 371 | */ |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 372 | interface HardwareDrawCallbacks { |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 373 | /** |
| 374 | * Invoked before a view is drawn by a hardware renderer. |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 375 | * This method can be used to apply transformations to the |
| 376 | * canvas but no drawing command should be issued. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 377 | * |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 378 | * @param canvas The Canvas used to render the view. |
| 379 | */ |
Romain Guy | 7d70fbf | 2011-05-24 17:40:25 -0700 | [diff] [blame] | 380 | void onHardwarePreDraw(HardwareCanvas canvas); |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 381 | |
| 382 | /** |
| 383 | * Invoked after a view is drawn by a hardware renderer. |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 384 | * It is safe to invoke drawing commands from this method. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 385 | * |
Romain Guy | 069ea0e | 2011-02-08 12:24:52 -0800 | [diff] [blame] | 386 | * @param canvas The Canvas used to render the view. |
| 387 | */ |
Romain Guy | 7d70fbf | 2011-05-24 17:40:25 -0700 | [diff] [blame] | 388 | void onHardwarePostDraw(HardwareCanvas canvas); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 391 | /** |
| 392 | * Draws the specified view. |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 393 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 394 | * @param view The view to draw. |
| 395 | * @param attachInfo AttachInfo tied to the specified view. |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 396 | * @param callbacks Callbacks invoked when drawing happens. |
| 397 | * @param dirty The dirty rectangle to update, can be null. |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 398 | */ |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 399 | abstract void draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callbacks, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 400 | Rect dirty); |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 401 | |
| 402 | /** |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 403 | * Creates a new hardware layer. A hardware layer built by calling this |
| 404 | * method will be treated as a texture layer, instead of as a render target. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 405 | * |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 406 | * @param isOpaque Whether the layer should be opaque or not |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 407 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 408 | * @return A hardware layer |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 409 | */ |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 410 | abstract HardwareLayer createHardwareLayer(boolean isOpaque); |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 411 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 412 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 413 | * Creates a new hardware layer. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 414 | * |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 415 | * @param width The minimum width of the layer |
| 416 | * @param height The minimum height of the layer |
| 417 | * @param isOpaque Whether the layer should be opaque or not |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 418 | * |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 419 | * @return A hardware layer |
| 420 | */ |
| 421 | abstract HardwareLayer createHardwareLayer(int width, int height, boolean isOpaque); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 422 | |
| 423 | /** |
| 424 | * Creates a new {@link SurfaceTexture} that can be used to render into the |
| 425 | * specified hardware layer. |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 426 | * |
| 427 | * @param layer The layer to render into using a {@link android.graphics.SurfaceTexture} |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 428 | * |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 429 | * @return A {@link SurfaceTexture} |
| 430 | */ |
Romain Guy | e5e0c50 | 2011-06-15 15:18:31 -0700 | [diff] [blame] | 431 | abstract SurfaceTexture createSurfaceTexture(HardwareLayer layer); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 432 | |
| 433 | /** |
Jamie Gennis | 2af3524 | 2012-04-05 11:44:30 -0700 | [diff] [blame] | 434 | * Sets the {@link android.graphics.SurfaceTexture} that will be used to |
| 435 | * render into the specified hardware layer. |
| 436 | * |
| 437 | * @param layer The layer to render into using a {@link android.graphics.SurfaceTexture} |
| 438 | * @param surfaceTexture The {@link android.graphics.SurfaceTexture} to use for the layer |
| 439 | */ |
| 440 | abstract void setSurfaceTexture(HardwareLayer layer, SurfaceTexture surfaceTexture); |
| 441 | |
| 442 | /** |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 443 | * Detaches the specified functor from the current functor execution queue. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 444 | * |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 445 | * @param functor The native functor to remove from the execution queue. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 446 | * |
| 447 | * @see HardwareCanvas#callDrawGLFunction(int) |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 448 | * @see #attachFunctor(android.view.View.AttachInfo, long) |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 449 | */ |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 450 | abstract void detachFunctor(long functor); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 451 | |
| 452 | /** |
| 453 | * Schedules the specified functor in the functors execution queue. |
| 454 | * |
| 455 | * @param attachInfo AttachInfo tied to this renderer. |
| 456 | * @param functor The native functor to insert in the execution queue. |
| 457 | * |
| 458 | * @see HardwareCanvas#callDrawGLFunction(int) |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 459 | * @see #detachFunctor(long) |
Chris Craik | 41ee465 | 2012-05-31 15:05:57 -0700 | [diff] [blame] | 460 | * |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 461 | */ |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 462 | abstract void attachFunctor(View.AttachInfo attachInfo, long functor); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 463 | |
| 464 | /** |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 465 | * Initializes the hardware renderer for the specified surface and setup the |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 466 | * renderer for drawing, if needed. This is invoked when the ViewAncestor has |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 467 | * potentially lost the hardware renderer. The hardware renderer should be |
| 468 | * reinitialized and setup when the render {@link #isRequested()} and |
| 469 | * {@link #isEnabled()}. |
Romain Guy | 44d7974 | 2012-01-13 12:12:09 -0800 | [diff] [blame] | 470 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 471 | * @param width The width of the drawing surface. |
| 472 | * @param height The height of the drawing surface. |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 473 | * @param surface The surface to hardware accelerate |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 474 | * |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 475 | * @return true if the surface was initialized, false otherwise. Returning |
| 476 | * false might mean that the surface was already initialized. |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 477 | */ |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 478 | boolean initializeIfNeeded(int width, int height, Surface surface) |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 479 | throws OutOfResourcesException { |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 480 | if (isRequested()) { |
| 481 | // We lost the gl context, so recreate it. |
| 482 | if (!isEnabled()) { |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 483 | if (initialize(surface)) { |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 484 | setup(width, height); |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 485 | return true; |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 486 | } |
| 487 | } |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 488 | } |
| 489 | return false; |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /** |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 493 | * Optional, sets the name of the renderer. Useful for debugging purposes. |
| 494 | * |
| 495 | * @param name The name of this renderer, can be null |
| 496 | */ |
| 497 | abstract void setName(String name); |
| 498 | |
| 499 | /** |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 500 | * Creates a hardware renderer using OpenGL. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 501 | * |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 502 | * @param translucent True if the surface is translucent, false otherwise |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 503 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 504 | * @return A hardware renderer backed by OpenGL. |
| 505 | */ |
John Reck | 3083579 | 2013-11-07 14:21:24 -0800 | [diff] [blame] | 506 | static HardwareRenderer create(boolean translucent) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 507 | HardwareRenderer renderer = null; |
John Reck | 3083579 | 2013-11-07 14:21:24 -0800 | [diff] [blame] | 508 | if (GLES20Canvas.isAvailable()) { |
John Reck | 3dfe19f | 2013-12-13 14:25:19 -0800 | [diff] [blame] | 509 | if (sUseRenderThread) { |
| 510 | renderer = new ThreadedRenderer(translucent); |
| 511 | } else { |
| 512 | renderer = new GLRenderer(translucent); |
| 513 | } |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 514 | } |
| 515 | return renderer; |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /** |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 519 | * Invoke this method when the system is running out of memory. This |
| 520 | * method will attempt to recover as much memory as possible, based on |
| 521 | * the specified hint. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 522 | * |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 523 | * @param level Hint about the amount of memory that should be trimmed, |
| 524 | * see {@link android.content.ComponentCallbacks} |
| 525 | */ |
| 526 | static void trimMemory(int level) { |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 527 | startTrimMemory(level); |
| 528 | endTrimMemory(); |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Starts the process of trimming memory. Usually this call will setup |
| 533 | * hardware rendering context and reclaim memory.Extra cleanup might |
| 534 | * be required by calling {@link #endTrimMemory()}. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 535 | * |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 536 | * @param level Hint about the amount of memory that should be trimmed, |
| 537 | * see {@link android.content.ComponentCallbacks} |
| 538 | */ |
| 539 | static void startTrimMemory(int level) { |
John Reck | 3083579 | 2013-11-07 14:21:24 -0800 | [diff] [blame] | 540 | GLRenderer.startTrimMemory(level); |
Romain Guy | 19f86e8 | 2012-04-23 15:19:07 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Finishes the process of trimming memory. This method will usually |
| 545 | * cleanup special resources used by the memory trimming process. |
| 546 | */ |
| 547 | static void endTrimMemory() { |
John Reck | 3083579 | 2013-11-07 14:21:24 -0800 | [diff] [blame] | 548 | GLRenderer.endTrimMemory(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /** |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 552 | * Indicates whether hardware acceleration is currently enabled. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 553 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 554 | * @return True if hardware acceleration is in use, false otherwise. |
| 555 | */ |
| 556 | boolean isEnabled() { |
| 557 | return mEnabled; |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Indicates whether hardware acceleration is currently enabled. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 562 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 563 | * @param enabled True if the hardware renderer is in use, false otherwise. |
| 564 | */ |
| 565 | void setEnabled(boolean enabled) { |
| 566 | mEnabled = enabled; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Indicates whether hardware acceleration is currently request but not |
| 571 | * necessarily enabled yet. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 572 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 573 | * @return True if requested, false otherwise. |
| 574 | */ |
| 575 | boolean isRequested() { |
| 576 | return mRequested; |
| 577 | } |
| 578 | |
| 579 | /** |
Romain Guy | 9745fae | 2010-12-08 11:39:15 -0800 | [diff] [blame] | 580 | * Indicates whether hardware acceleration is currently requested but not |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 581 | * necessarily enabled yet. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 582 | * |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 583 | * @return True to request hardware acceleration, false otherwise. |
| 584 | */ |
| 585 | void setRequested(boolean requested) { |
| 586 | mRequested = requested; |
| 587 | } |
| 588 | |
Romain Guy | 48ef4a9 | 2013-01-10 18:38:46 -0800 | [diff] [blame] | 589 | /** |
| 590 | * Describes a series of frames that should be drawn on screen as a graph. |
| 591 | * Each frame is composed of 1 or more elements. |
| 592 | */ |
| 593 | abstract class GraphDataProvider { |
| 594 | /** |
| 595 | * Draws the graph as bars. Frame elements are stacked on top of |
| 596 | * each other. |
| 597 | */ |
| 598 | public static final int GRAPH_TYPE_BARS = 0; |
| 599 | /** |
| 600 | * Draws the graph as lines. The number of series drawn corresponds |
| 601 | * to the number of elements. |
| 602 | */ |
| 603 | public static final int GRAPH_TYPE_LINES = 1; |
| 604 | |
| 605 | /** |
| 606 | * Returns the type of graph to render. |
| 607 | * |
| 608 | * @return {@link #GRAPH_TYPE_BARS} or {@link #GRAPH_TYPE_LINES} |
| 609 | */ |
| 610 | abstract int getGraphType(); |
| 611 | |
| 612 | /** |
| 613 | * This method is invoked before the graph is drawn. This method |
| 614 | * can be used to compute sizes, etc. |
| 615 | * |
| 616 | * @param metrics The display metrics |
| 617 | */ |
| 618 | abstract void prepare(DisplayMetrics metrics); |
| 619 | |
| 620 | /** |
| 621 | * @return The size in pixels of a vertical unit. |
| 622 | */ |
| 623 | abstract int getVerticalUnitSize(); |
| 624 | |
| 625 | /** |
| 626 | * @return The size in pixels of a horizontal unit. |
| 627 | */ |
| 628 | abstract int getHorizontalUnitSize(); |
| 629 | |
| 630 | /** |
| 631 | * @return The size in pixels of the margin between horizontal units. |
| 632 | */ |
| 633 | abstract int getHorizontaUnitMargin(); |
| 634 | |
| 635 | /** |
| 636 | * An optional threshold value. |
| 637 | * |
| 638 | * @return A value >= 0 to draw the threshold, a negative value |
| 639 | * to ignore it. |
| 640 | */ |
| 641 | abstract float getThreshold(); |
| 642 | |
| 643 | /** |
| 644 | * The data to draw in the graph. The number of elements in the |
| 645 | * array must be at least {@link #getFrameCount()} * {@link #getElementCount()}. |
| 646 | * If a value is negative the following values will be ignored. |
| 647 | */ |
| 648 | abstract float[] getData(); |
| 649 | |
| 650 | /** |
| 651 | * Returns the number of frames to render in the graph. |
| 652 | */ |
| 653 | abstract int getFrameCount(); |
| 654 | |
| 655 | /** |
| 656 | * Returns the number of elements in each frame. This directly affects |
| 657 | * the number of series drawn in the graph. |
| 658 | */ |
| 659 | abstract int getElementCount(); |
| 660 | |
| 661 | /** |
| 662 | * Returns the current frame, if any. If the returned value is negative |
| 663 | * the current frame is ignored. |
| 664 | */ |
| 665 | abstract int getCurrentFrame(); |
| 666 | |
| 667 | /** |
| 668 | * Prepares the paint to draw the specified element (or series.) |
| 669 | */ |
| 670 | abstract void setupGraphPaint(Paint paint, int elementIndex); |
| 671 | |
| 672 | /** |
| 673 | * Prepares the paint to draw the threshold. |
| 674 | */ |
| 675 | abstract void setupThresholdPaint(Paint paint); |
| 676 | |
| 677 | /** |
| 678 | * Prepares the paint to draw the current frame indicator. |
| 679 | */ |
| 680 | abstract void setupCurrentFramePaint(Paint paint); |
| 681 | } |
Romain Guy | 2d61459 | 2010-06-09 18:21:37 -0700 | [diff] [blame] | 682 | } |