Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_DISPLAY_LIST_RENDERER_H |
| 18 | #define ANDROID_HWUI_DISPLAY_LIST_RENDERER_H |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 19 | |
| 20 | #include <SkChunkAlloc.h> |
| 21 | #include <SkFlattenable.h> |
| 22 | #include <SkMatrix.h> |
| 23 | #include <SkPaint.h> |
| 24 | #include <SkPath.h> |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 25 | #include <SkRefCnt.h> |
| 26 | #include <SkTDArray.h> |
| 27 | #include <SkTSearch.h> |
| 28 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 29 | #include "DisplayListLogBuffer.h" |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 30 | #include "OpenGLRenderer.h" |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 31 | #include "utils/Functor.h" |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | namespace uirenderer { |
| 35 | |
| 36 | /////////////////////////////////////////////////////////////////////////////// |
| 37 | // Defines |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 40 | #define MIN_WRITER_SIZE 4096 |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 41 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 42 | // Debug |
| 43 | #if DEBUG_DISPLAY_LIST |
| 44 | #define DISPLAY_LIST_LOGD(...) LOGD(__VA_ARGS__) |
| 45 | #else |
| 46 | #define DISPLAY_LIST_LOGD(...) |
| 47 | #endif |
| 48 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 49 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 50 | // Display list |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 51 | /////////////////////////////////////////////////////////////////////////////// |
| 52 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 53 | class DisplayListRenderer; |
| 54 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 55 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 56 | * Replays recorded drawing commands. |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 57 | */ |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 58 | class DisplayList { |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 59 | public: |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 60 | DisplayList(const DisplayListRenderer& recorder); |
| 61 | ~DisplayList(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 62 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 63 | // IMPORTANT: Update the intialization of OP_NAMES in the .cpp file |
| 64 | // when modifying this file |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 65 | enum Op { |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 66 | // Non-drawing operations |
Romain Guy | 2b1847e | 2011-01-26 13:43:01 -0800 | [diff] [blame] | 67 | Save = 0, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 68 | Restore, |
| 69 | RestoreToCount, |
| 70 | SaveLayer, |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 71 | SaveLayerAlpha, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 72 | Translate, |
| 73 | Rotate, |
| 74 | Scale, |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 75 | Skew, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 76 | SetMatrix, |
| 77 | ConcatMatrix, |
| 78 | ClipRect, |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 79 | // Drawing operations |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 80 | DrawDisplayList, |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 81 | DrawLayer, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 82 | DrawBitmap, |
| 83 | DrawBitmapMatrix, |
| 84 | DrawBitmapRect, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 85 | DrawBitmapMesh, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 86 | DrawPatch, |
| 87 | DrawColor, |
| 88 | DrawRect, |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 89 | DrawRoundRect, |
| 90 | DrawCircle, |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 91 | DrawOval, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 92 | DrawArc, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 93 | DrawPath, |
| 94 | DrawLines, |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 95 | DrawPoints, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 96 | DrawText, |
| 97 | ResetShader, |
| 98 | SetupShader, |
| 99 | ResetColorFilter, |
| 100 | SetupColorFilter, |
| 101 | ResetShadow, |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 102 | SetupShadow, |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 103 | DrawGLFunction, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 106 | static const char* OP_NAMES[]; |
| 107 | |
Chet Haase | d63cbd1 | 2011-02-03 16:32:46 -0800 | [diff] [blame] | 108 | void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 109 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 110 | size_t getSize(); |
| 111 | |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 112 | bool replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level = 0); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 113 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 114 | void output(OpenGLRenderer& renderer, uint32_t level = 0); |
| 115 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 116 | static void outputLogBuffer(int fd); |
| 117 | |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 118 | void setRenderable(bool renderable) { |
| 119 | mIsRenderable = renderable; |
| 120 | } |
| 121 | |
| 122 | bool isRenderable() const { |
| 123 | return mIsRenderable; |
| 124 | } |
| 125 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 126 | private: |
| 127 | void init(); |
| 128 | |
Chet Haase | d63cbd1 | 2011-02-03 16:32:46 -0800 | [diff] [blame] | 129 | void clearResources(); |
| 130 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 131 | class TextContainer { |
| 132 | public: |
| 133 | size_t length() const { |
| 134 | return mByteLength; |
| 135 | } |
| 136 | |
| 137 | const char* text() const { |
| 138 | return (const char*) mText; |
| 139 | } |
| 140 | |
| 141 | size_t mByteLength; |
| 142 | const char* mText; |
| 143 | }; |
| 144 | |
| 145 | SkBitmap* getBitmap() { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 146 | return (SkBitmap*) getInt(); |
| 147 | } |
| 148 | |
| 149 | SkiaShader* getShader() { |
| 150 | return (SkiaShader*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 153 | SkiaColorFilter* getColorFilter() { |
| 154 | return (SkiaColorFilter*) getInt(); |
| 155 | } |
| 156 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 157 | inline int getIndex() { |
| 158 | return mReader.readInt(); |
| 159 | } |
| 160 | |
| 161 | inline int getInt() { |
| 162 | return mReader.readInt(); |
| 163 | } |
| 164 | |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 165 | inline uint32_t getUInt() { |
| 166 | return mReader.readU32(); |
| 167 | } |
| 168 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 169 | SkMatrix* getMatrix() { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 170 | return (SkMatrix*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | SkPath* getPath() { |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 174 | return (SkPath*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | SkPaint* getPaint() { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 178 | return (SkPaint*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 181 | DisplayList* getDisplayList() { |
| 182 | return (DisplayList*) getInt(); |
| 183 | } |
| 184 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 185 | inline float getFloat() { |
| 186 | return mReader.readScalar(); |
| 187 | } |
| 188 | |
| 189 | int32_t* getInts(uint32_t& count) { |
| 190 | count = getInt(); |
| 191 | return (int32_t*) mReader.skip(count * sizeof(int32_t)); |
| 192 | } |
| 193 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 194 | uint32_t* getUInts(int8_t& count) { |
| 195 | count = getInt(); |
| 196 | return (uint32_t*) mReader.skip(count * sizeof(uint32_t)); |
| 197 | } |
| 198 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 199 | float* getFloats(int& count) { |
| 200 | count = getInt(); |
| 201 | return (float*) mReader.skip(count * sizeof(float)); |
| 202 | } |
| 203 | |
| 204 | void getText(TextContainer* text) { |
| 205 | size_t length = text->mByteLength = getInt(); |
| 206 | text->mText = (const char*) mReader.skip(length); |
| 207 | } |
| 208 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 209 | Vector<SkBitmap*> mBitmapResources; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 210 | Vector<SkiaColorFilter*> mFilterResources; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 211 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 212 | Vector<SkPaint*> mPaints; |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 213 | Vector<SkPath*> mPaths; |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 214 | Vector<SkMatrix*> mMatrices; |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 215 | Vector<SkiaShader*> mShaders; |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 216 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 217 | mutable SkFlattenableReadBuffer mReader; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 218 | |
| 219 | size_t mSize; |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 220 | |
| 221 | bool mIsRenderable; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | /////////////////////////////////////////////////////////////////////////////// |
| 225 | // Renderer |
| 226 | /////////////////////////////////////////////////////////////////////////////// |
| 227 | |
| 228 | /** |
| 229 | * Records drawing commands in a display list for latter playback. |
| 230 | */ |
| 231 | class DisplayListRenderer: public OpenGLRenderer { |
| 232 | public: |
| 233 | DisplayListRenderer(); |
| 234 | ~DisplayListRenderer(); |
| 235 | |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 236 | DisplayList* getDisplayList(DisplayList* displayList); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 237 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 238 | void setViewport(int width, int height); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 239 | void prepareDirty(float left, float top, float right, float bottom, bool opaque); |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 240 | void finish(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 241 | |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 242 | bool callDrawGLFunction(Functor *functor, Rect& dirty); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 243 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 244 | void interrupt(); |
| 245 | void resume(); |
| 246 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 247 | int save(int flags); |
| 248 | void restore(); |
| 249 | void restoreToCount(int saveCount); |
| 250 | |
| 251 | int saveLayer(float left, float top, float right, float bottom, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 252 | SkPaint* p, int flags); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 253 | int saveLayerAlpha(float left, float top, float right, float bottom, |
| 254 | int alpha, int flags); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 255 | |
| 256 | void translate(float dx, float dy); |
| 257 | void rotate(float degrees); |
| 258 | void scale(float sx, float sy); |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 259 | void skew(float sx, float sy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 260 | |
| 261 | void setMatrix(SkMatrix* matrix); |
| 262 | void concatMatrix(SkMatrix* matrix); |
| 263 | |
| 264 | bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); |
| 265 | |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 266 | bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height, |
| 267 | Rect& dirty, uint32_t level = 0); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 268 | void drawLayer(Layer* layer, float x, float y, SkPaint* paint); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 269 | void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint); |
| 270 | void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 271 | void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, |
| 272 | float srcRight, float srcBottom, float dstLeft, float dstTop, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 273 | float dstRight, float dstBottom, SkPaint* paint); |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 274 | void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, |
| 275 | float* vertices, int* colors, SkPaint* paint); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 276 | void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 277 | const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 278 | float left, float top, float right, float bottom, SkPaint* paint); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 279 | void drawColor(int color, SkXfermode::Mode mode); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 280 | void drawRect(float left, float top, float right, float bottom, SkPaint* paint); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 281 | void drawRoundRect(float left, float top, float right, float bottom, |
| 282 | float rx, float ry, SkPaint* paint); |
| 283 | void drawCircle(float x, float y, float radius, SkPaint* paint); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 284 | void drawOval(float left, float top, float right, float bottom, SkPaint* paint); |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 285 | void drawArc(float left, float top, float right, float bottom, |
| 286 | float startAngle, float sweepAngle, bool useCenter, SkPaint* paint); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 287 | void drawPath(SkPath* path, SkPaint* paint); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 288 | void drawLines(float* points, int count, SkPaint* paint); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 289 | void drawPoints(float* points, int count, SkPaint* paint); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 290 | void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint); |
| 291 | |
| 292 | void resetShader(); |
| 293 | void setupShader(SkiaShader* shader); |
| 294 | |
| 295 | void resetColorFilter(); |
| 296 | void setupColorFilter(SkiaColorFilter* filter); |
| 297 | |
| 298 | void resetShadow(); |
| 299 | void setupShadow(float radius, float dx, float dy, int color); |
| 300 | |
| 301 | void reset(); |
| 302 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 303 | const SkWriter32& writeStream() const { |
| 304 | return mWriter; |
| 305 | } |
| 306 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 307 | const Vector<SkBitmap*>& getBitmapResources() const { |
| 308 | return mBitmapResources; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 311 | const Vector<SkiaColorFilter*>& getFilterResources() const { |
| 312 | return mFilterResources; |
| 313 | } |
| 314 | |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 315 | const Vector<SkiaShader*>& getShaders() const { |
| 316 | return mShaders; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 319 | const Vector<SkPaint*>& getPaints() const { |
| 320 | return mPaints; |
| 321 | } |
| 322 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 323 | const Vector<SkPath*>& getPaths() const { |
| 324 | return mPaths; |
| 325 | } |
| 326 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 327 | const Vector<SkMatrix*>& getMatrices() const { |
| 328 | return mMatrices; |
| 329 | } |
| 330 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 331 | private: |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 332 | void insertRestoreToCount() { |
| 333 | if (mRestoreSaveCount >= 0) { |
| 334 | mWriter.writeInt(DisplayList::RestoreToCount); |
| 335 | addInt(mRestoreSaveCount); |
| 336 | mRestoreSaveCount = -1; |
| 337 | } |
| 338 | } |
| 339 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 340 | inline void addOp(DisplayList::Op drawOp) { |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 341 | insertRestoreToCount(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 342 | mWriter.writeInt(drawOp); |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 343 | mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | inline void addInt(int value) { |
| 347 | mWriter.writeInt(value); |
| 348 | } |
| 349 | |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 350 | inline void addSize(uint32_t w, uint32_t h) { |
| 351 | mWriter.writeInt(w); |
| 352 | mWriter.writeInt(h); |
| 353 | } |
| 354 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 355 | void addInts(const int32_t* values, uint32_t count) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 356 | mWriter.writeInt(count); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 357 | for (uint32_t i = 0; i < count; i++) { |
| 358 | mWriter.writeInt(values[i]); |
| 359 | } |
| 360 | } |
| 361 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 362 | void addUInts(const uint32_t* values, int8_t count) { |
| 363 | mWriter.writeInt(count); |
| 364 | for (int8_t i = 0; i < count; i++) { |
| 365 | mWriter.writeInt(values[i]); |
| 366 | } |
| 367 | } |
| 368 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 369 | inline void addFloat(float value) { |
| 370 | mWriter.writeScalar(value); |
| 371 | } |
| 372 | |
| 373 | void addFloats(const float* values, int count) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 374 | mWriter.writeInt(count); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 375 | for (int i = 0; i < count; i++) { |
| 376 | mWriter.writeScalar(values[i]); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | inline void addPoint(float x, float y) { |
| 381 | mWriter.writeScalar(x); |
| 382 | mWriter.writeScalar(y); |
| 383 | } |
| 384 | |
| 385 | inline void addBounds(float left, float top, float right, float bottom) { |
| 386 | mWriter.writeScalar(left); |
| 387 | mWriter.writeScalar(top); |
| 388 | mWriter.writeScalar(right); |
| 389 | mWriter.writeScalar(bottom); |
| 390 | } |
| 391 | |
| 392 | inline void addText(const void* text, size_t byteLength) { |
| 393 | mWriter.writeInt(byteLength); |
| 394 | mWriter.writePad(text, byteLength); |
| 395 | } |
| 396 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 397 | inline void addPath(SkPath* path) { |
| 398 | if (!path) { |
| 399 | addInt((int) NULL); |
| 400 | return; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 401 | } |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 402 | |
| 403 | SkPath* pathCopy = mPathMap.valueFor(path); |
| 404 | if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) { |
Romain Guy | b29cfbf | 2011-03-18 16:24:19 -0700 | [diff] [blame] | 405 | pathCopy = new SkPath(*path); |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 406 | mPathMap.add(path, pathCopy); |
Romain Guy | b29cfbf | 2011-03-18 16:24:19 -0700 | [diff] [blame] | 407 | mPaths.add(pathCopy); |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | addInt((int) pathCopy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 413 | inline void addPaint(SkPaint* paint) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 414 | if (!paint) { |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 415 | addInt((int) NULL); |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 416 | return; |
| 417 | } |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 418 | |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 419 | SkPaint* paintCopy = mPaintMap.valueFor(paint); |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 420 | if (paintCopy == NULL || paintCopy->getGenerationID() != paint->getGenerationID()) { |
| 421 | paintCopy = new SkPaint(*paint); |
| 422 | mPaintMap.add(paint, paintCopy); |
| 423 | mPaints.add(paintCopy); |
| 424 | } |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 425 | |
| 426 | addInt((int) paintCopy); |
| 427 | } |
| 428 | |
| 429 | inline void addDisplayList(DisplayList* displayList) { |
| 430 | // TODO: To be safe, the display list should be ref-counted in the |
| 431 | // resources cache, but we rely on the caller (UI toolkit) to |
| 432 | // do the right thing for now |
| 433 | addInt((int) displayList); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 436 | inline void addMatrix(SkMatrix* matrix) { |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 437 | // Copying the matrix is cheap and prevents against the user changing the original |
| 438 | // matrix before the operation that uses it |
Romain Guy | f6a63ae | 2011-06-22 15:13:09 -0700 | [diff] [blame] | 439 | SkMatrix* copy = new SkMatrix(*matrix); |
| 440 | addInt((int) copy); |
| 441 | mMatrices.add(copy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 444 | inline void addBitmap(SkBitmap* bitmap) { |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 445 | // Note that this assumes the bitmap is immutable. There are cases this won't handle |
| 446 | // correctly, such as creating the bitmap from scratch, drawing with it, changing its |
| 447 | // contents, and drawing again. The only fix would be to always copy it the first time, |
| 448 | // which doesn't seem worth the extra cycles for this unlikely case. |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 449 | addInt((int) bitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 450 | mBitmapResources.add(bitmap); |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 451 | Caches::getInstance().resourceCache.incrementRefcount(bitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 452 | } |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 453 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 454 | inline void addShader(SkiaShader* shader) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 455 | if (!shader) { |
| 456 | addInt((int) NULL); |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | SkiaShader* shaderCopy = mShaderMap.valueFor(shader); |
| 461 | // TODO: We also need to handle generation ID changes in compose shaders |
Romain Guy | 1f1fcb7 | 2011-01-14 15:37:54 -0800 | [diff] [blame] | 462 | if (shaderCopy == NULL || shaderCopy->getGenerationId() != shader->getGenerationId()) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 463 | shaderCopy = shader->copy(); |
| 464 | mShaderMap.add(shader, shaderCopy); |
Romain Guy | 1f1fcb7 | 2011-01-14 15:37:54 -0800 | [diff] [blame] | 465 | mShaders.add(shaderCopy); |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 466 | Caches::getInstance().resourceCache.incrementRefcount(shaderCopy); |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | addInt((int) shaderCopy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 472 | inline void addColorFilter(SkiaColorFilter* colorFilter) { |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 473 | addInt((int) colorFilter); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 474 | mFilterResources.add(colorFilter); |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 475 | Caches::getInstance().resourceCache.incrementRefcount(colorFilter); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 478 | Vector<SkBitmap*> mBitmapResources; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 479 | Vector<SkiaColorFilter*> mFilterResources; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 480 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 481 | Vector<SkPaint*> mPaints; |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 482 | DefaultKeyedVector<SkPaint*, SkPaint*> mPaintMap; |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 483 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 484 | Vector<SkPath*> mPaths; |
| 485 | DefaultKeyedVector<SkPath*, SkPath*> mPathMap; |
| 486 | |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 487 | Vector<SkiaShader*> mShaders; |
| 488 | DefaultKeyedVector<SkiaShader*, SkiaShader*> mShaderMap; |
| 489 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 490 | Vector<SkMatrix*> mMatrices; |
| 491 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 492 | SkWriter32 mWriter; |
| 493 | |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 494 | int mRestoreSaveCount; |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 495 | bool mHasDrawOps; |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 496 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 497 | friend class DisplayList; |
| 498 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 499 | }; // class DisplayListRenderer |
| 500 | |
| 501 | }; // namespace uirenderer |
| 502 | }; // namespace android |
| 503 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 504 | #endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H |