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