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> |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 23 | #include <SkCamera.h> |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 24 | #include <SkPaint.h> |
| 25 | #include <SkPath.h> |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 26 | #include <SkRefCnt.h> |
| 27 | #include <SkTDArray.h> |
| 28 | #include <SkTSearch.h> |
| 29 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 30 | #include <cutils/compiler.h> |
| 31 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 32 | #include "DisplayListLogBuffer.h" |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 33 | #include "OpenGLRenderer.h" |
| 34 | |
| 35 | namespace android { |
| 36 | namespace uirenderer { |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | // Defines |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 42 | #define MIN_WRITER_SIZE 4096 |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 43 | #define OP_MAY_BE_SKIPPED_MASK 0xff000000 |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 44 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 45 | // Debug |
| 46 | #if DEBUG_DISPLAY_LIST |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 47 | #define DISPLAY_LIST_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 48 | #else |
| 49 | #define DISPLAY_LIST_LOGD(...) |
| 50 | #endif |
| 51 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 52 | // Set to 1 to enable native processing of View properties. 0 by default. Eventually this |
| 53 | // will go away and we will always use this approach for accelerated apps. |
Chet Haase | 76240da | 2012-03-29 09:42:34 -0700 | [diff] [blame] | 54 | #define USE_DISPLAY_LIST_PROPERTIES 0 |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 55 | |
| 56 | #define TRANSLATION 0x0001 |
| 57 | #define ROTATION 0x0002 |
| 58 | #define ROTATION_3D 0x0004 |
| 59 | #define SCALE 0x0008 |
| 60 | #define PIVOT 0x0010 |
| 61 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 62 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 63 | // Display list |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 64 | /////////////////////////////////////////////////////////////////////////////// |
| 65 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 66 | class DisplayListRenderer; |
| 67 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 68 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 69 | * Replays recorded drawing commands. |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 70 | */ |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 71 | class DisplayList { |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 72 | public: |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 73 | DisplayList(const DisplayListRenderer& recorder); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 74 | ANDROID_API ~DisplayList(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 75 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 76 | // IMPORTANT: Update the intialization of OP_NAMES in the .cpp file |
| 77 | // when modifying this file |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 78 | enum Op { |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 79 | // Non-drawing operations |
Romain Guy | 2b1847e | 2011-01-26 13:43:01 -0800 | [diff] [blame] | 80 | Save = 0, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 81 | Restore, |
| 82 | RestoreToCount, |
| 83 | SaveLayer, |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 84 | SaveLayerAlpha, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 85 | Translate, |
| 86 | Rotate, |
| 87 | Scale, |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 88 | Skew, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 89 | SetMatrix, |
| 90 | ConcatMatrix, |
| 91 | ClipRect, |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 92 | // Drawing operations |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 93 | DrawDisplayList, |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 94 | DrawLayer, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 95 | DrawBitmap, |
| 96 | DrawBitmapMatrix, |
| 97 | DrawBitmapRect, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 98 | DrawBitmapMesh, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 99 | DrawPatch, |
| 100 | DrawColor, |
| 101 | DrawRect, |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 102 | DrawRoundRect, |
| 103 | DrawCircle, |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 104 | DrawOval, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 105 | DrawArc, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 106 | DrawPath, |
| 107 | DrawLines, |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 108 | DrawPoints, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 109 | DrawText, |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 110 | DrawTextOnPath, |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 111 | DrawPosText, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 112 | ResetShader, |
| 113 | SetupShader, |
| 114 | ResetColorFilter, |
| 115 | SetupColorFilter, |
| 116 | ResetShadow, |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 117 | SetupShadow, |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 118 | ResetPaintFilter, |
| 119 | SetupPaintFilter, |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 120 | DrawGLFunction, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 123 | // See flags defined in DisplayList.java |
| 124 | enum ReplayFlag { |
| 125 | kReplayFlag_ClipChildren = 0x1 |
| 126 | }; |
| 127 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 128 | static const char* OP_NAMES[]; |
| 129 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 130 | void setViewProperties(OpenGLRenderer& renderer, uint32_t width, uint32_t height, |
| 131 | uint32_t level); |
| 132 | void outputViewProperties(OpenGLRenderer& renderer, char* indent); |
| 133 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 134 | ANDROID_API size_t getSize(); |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 135 | ANDROID_API static void destroyDisplayListDeferred(DisplayList* displayList); |
| 136 | ANDROID_API static void outputLogBuffer(int fd); |
| 137 | |
| 138 | void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 139 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 140 | status_t replay(OpenGLRenderer& renderer, uint32_t width, uint32_t height, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 141 | Rect& dirty, int32_t flags, uint32_t level = 0); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 142 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 143 | void output(OpenGLRenderer& renderer, uint32_t level = 0); |
| 144 | |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 145 | void setRenderable(bool renderable) { |
| 146 | mIsRenderable = renderable; |
| 147 | } |
| 148 | |
| 149 | bool isRenderable() const { |
| 150 | return mIsRenderable; |
| 151 | } |
| 152 | |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 153 | void setName(const char* name) { |
| 154 | if (name) { |
| 155 | mName.setTo(name); |
| 156 | } |
| 157 | } |
| 158 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 159 | void setApplicationScale(float scale) { |
| 160 | mApplicationScale = scale; |
| 161 | } |
| 162 | |
| 163 | void setClipChildren(bool clipChildren) { |
| 164 | mClipChildren = clipChildren; |
| 165 | } |
| 166 | |
| 167 | void setAlpha(float alpha) { |
| 168 | if (alpha != mAlpha) { |
| 169 | mAlpha = alpha; |
| 170 | mMultipliedAlpha = (int)(255 * alpha); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void setTranslationX(float translationX) { |
| 175 | if (translationX != mTranslationX) { |
| 176 | mTranslationX = translationX; |
| 177 | mMatrixDirty = true; |
| 178 | if (ALMOST_EQUAL(mTranslationX, 0) && ALMOST_EQUAL(mTranslationY, 0)) { |
| 179 | mMatrixFlags &= ~TRANSLATION; |
| 180 | } else { |
| 181 | mMatrixFlags |= TRANSLATION; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void setTranslationY(float translationY) { |
| 187 | if (translationY != mTranslationY) { |
| 188 | mTranslationY = translationY; |
| 189 | mMatrixDirty = true; |
| 190 | if (ALMOST_EQUAL(mTranslationX, 0) && ALMOST_EQUAL(mTranslationY, 0)) { |
| 191 | mMatrixFlags &= ~TRANSLATION; |
| 192 | } else { |
| 193 | mMatrixFlags |= TRANSLATION; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | void setRotation(float rotation) { |
| 199 | if (rotation != mRotation) { |
| 200 | mRotation = rotation; |
| 201 | mMatrixDirty = true; |
| 202 | if (ALMOST_EQUAL(mRotation, 0)) { |
| 203 | mMatrixFlags &= ~ROTATION; |
| 204 | } else { |
| 205 | mMatrixFlags |= ROTATION; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | void setRotationX(float rotationX) { |
| 211 | if (rotationX != mRotationX) { |
| 212 | mRotationX = rotationX; |
| 213 | mMatrixDirty = true; |
| 214 | if (ALMOST_EQUAL(mRotationX, 0) && ALMOST_EQUAL(mRotationY, 0)) { |
| 215 | mMatrixFlags &= ~ROTATION_3D; |
| 216 | } else { |
| 217 | mMatrixFlags |= ROTATION_3D; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | void setRotationY(float rotationY) { |
| 223 | if (rotationY != mRotationY) { |
| 224 | mRotationY = rotationY; |
| 225 | mMatrixDirty = true; |
| 226 | if (ALMOST_EQUAL(mRotationX, 0) && ALMOST_EQUAL(mRotationY, 0)) { |
| 227 | mMatrixFlags &= ~ROTATION_3D; |
| 228 | } else { |
| 229 | mMatrixFlags |= ROTATION_3D; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | void setScaleX(float scaleX) { |
| 235 | if (scaleX != mScaleX) { |
| 236 | mScaleX = scaleX; |
| 237 | mMatrixDirty = true; |
| 238 | if (ALMOST_EQUAL(mScaleX, 1) && ALMOST_EQUAL(mScaleY, 1)) { |
| 239 | mMatrixFlags &= ~SCALE; |
| 240 | } else { |
| 241 | mMatrixFlags |= SCALE; |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | void setScaleY(float scaleY) { |
| 247 | if (scaleY != mScaleY) { |
| 248 | mScaleY = scaleY; |
| 249 | mMatrixDirty = true; |
| 250 | if (ALMOST_EQUAL(mScaleX, 1) && ALMOST_EQUAL(mScaleY, 1)) { |
| 251 | mMatrixFlags &= ~SCALE; |
| 252 | } else { |
| 253 | mMatrixFlags |= SCALE; |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | void setPivotX(float pivotX) { |
| 259 | mPivotX = pivotX; |
| 260 | mMatrixDirty = true; |
| 261 | if (ALMOST_EQUAL(mPivotX, 0) && ALMOST_EQUAL(mPivotY, 0)) { |
| 262 | mMatrixFlags &= ~PIVOT; |
| 263 | } else { |
| 264 | mMatrixFlags |= PIVOT; |
| 265 | } |
| 266 | mPivotExplicitlySet = true; |
| 267 | } |
| 268 | |
| 269 | void setPivotY(float pivotY) { |
| 270 | mPivotY = pivotY; |
| 271 | mMatrixDirty = true; |
| 272 | if (ALMOST_EQUAL(mPivotX, 0) && ALMOST_EQUAL(mPivotY, 0)) { |
| 273 | mMatrixFlags &= ~PIVOT; |
| 274 | } else { |
| 275 | mMatrixFlags |= PIVOT; |
| 276 | } |
| 277 | mPivotExplicitlySet = true; |
| 278 | } |
| 279 | |
| 280 | void setCameraDistance(float distance) { |
| 281 | if (distance != mCameraDistance) { |
| 282 | mCameraDistance = distance; |
| 283 | mMatrixDirty = true; |
| 284 | if (!mTransformCamera) { |
| 285 | mTransformCamera = new Sk3DView(); |
| 286 | mTransformMatrix3D = new SkMatrix(); |
| 287 | } |
| 288 | mTransformCamera->setCameraLocation(0, 0, distance); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | void setLeft(int left) { |
| 293 | if (left != mLeft) { |
| 294 | mLeft = left; |
| 295 | mWidth = mRight - mLeft; |
| 296 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 297 | mMatrixDirty = true; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | void setTop(int top) { |
| 303 | if (top != mTop) { |
| 304 | mTop = top; |
| 305 | mHeight = mBottom - mTop; |
| 306 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 307 | mMatrixDirty = true; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | void setRight(int right) { |
| 313 | if (right != mRight) { |
| 314 | mRight = right; |
| 315 | mWidth = mRight - mLeft; |
| 316 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 317 | mMatrixDirty = true; |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | void setBottom(int bottom) { |
| 323 | if (bottom != mBottom) { |
| 324 | mBottom = bottom; |
| 325 | mHeight = mBottom - mTop; |
| 326 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 327 | mMatrixDirty = true; |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | void setLeftTop(int left, int top) { |
| 333 | if (left != mLeft || top != mTop) { |
| 334 | mLeft = left; |
| 335 | mTop = top; |
| 336 | mWidth = mRight - mLeft; |
| 337 | mHeight = mBottom - mTop; |
| 338 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 339 | mMatrixDirty = true; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | void setLeftTopRightBottom(int left, int top, int right, int bottom) { |
| 345 | if (left != mLeft || top != mTop || right != mRight || bottom != mBottom) { |
| 346 | mLeft = left; |
| 347 | mTop = top; |
| 348 | mRight = right; |
| 349 | mBottom = bottom; |
| 350 | mWidth = mRight - mLeft; |
| 351 | mHeight = mBottom - mTop; |
| 352 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 353 | mMatrixDirty = true; |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | void offsetLeftRight(int offset) { |
| 359 | if (offset != 0) { |
| 360 | mLeft += offset; |
| 361 | mRight += offset; |
| 362 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 363 | mMatrixDirty = true; |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | void offsetTopBottom(int offset) { |
| 369 | if (offset != 0) { |
| 370 | mTop += offset; |
| 371 | mBottom += offset; |
| 372 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 373 | mMatrixDirty = true; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | void setCaching(bool caching) { |
| 379 | mCaching = caching; |
| 380 | } |
| 381 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 382 | private: |
| 383 | void init(); |
| 384 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 385 | void initProperties(); |
| 386 | |
Chet Haase | d63cbd1 | 2011-02-03 16:32:46 -0800 | [diff] [blame] | 387 | void clearResources(); |
| 388 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 389 | void updateMatrix(); |
| 390 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 391 | class TextContainer { |
| 392 | public: |
| 393 | size_t length() const { |
| 394 | return mByteLength; |
| 395 | } |
| 396 | |
| 397 | const char* text() const { |
| 398 | return (const char*) mText; |
| 399 | } |
| 400 | |
| 401 | size_t mByteLength; |
| 402 | const char* mText; |
| 403 | }; |
| 404 | |
| 405 | SkBitmap* getBitmap() { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 406 | return (SkBitmap*) getInt(); |
| 407 | } |
| 408 | |
| 409 | SkiaShader* getShader() { |
| 410 | return (SkiaShader*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 413 | SkiaColorFilter* getColorFilter() { |
| 414 | return (SkiaColorFilter*) getInt(); |
| 415 | } |
| 416 | |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 417 | inline int32_t getIndex() { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 418 | return mReader.readInt(); |
| 419 | } |
| 420 | |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 421 | inline int32_t getInt() { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 422 | return mReader.readInt(); |
| 423 | } |
| 424 | |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 425 | inline uint32_t getUInt() { |
| 426 | return mReader.readU32(); |
| 427 | } |
| 428 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 429 | SkMatrix* getMatrix() { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 430 | return (SkMatrix*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | SkPath* getPath() { |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 434 | return (SkPath*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 437 | SkPaint* getPaint(OpenGLRenderer& renderer) { |
| 438 | return renderer.filterPaint((SkPaint*) getInt()); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 441 | DisplayList* getDisplayList() { |
| 442 | return (DisplayList*) getInt(); |
| 443 | } |
| 444 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 445 | inline float getFloat() { |
| 446 | return mReader.readScalar(); |
| 447 | } |
| 448 | |
| 449 | int32_t* getInts(uint32_t& count) { |
| 450 | count = getInt(); |
| 451 | return (int32_t*) mReader.skip(count * sizeof(int32_t)); |
| 452 | } |
| 453 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 454 | uint32_t* getUInts(int8_t& count) { |
| 455 | count = getInt(); |
| 456 | return (uint32_t*) mReader.skip(count * sizeof(uint32_t)); |
| 457 | } |
| 458 | |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 459 | float* getFloats(int32_t& count) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 460 | count = getInt(); |
| 461 | return (float*) mReader.skip(count * sizeof(float)); |
| 462 | } |
| 463 | |
| 464 | void getText(TextContainer* text) { |
| 465 | size_t length = text->mByteLength = getInt(); |
| 466 | text->mText = (const char*) mReader.skip(length); |
| 467 | } |
| 468 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 469 | Vector<SkBitmap*> mBitmapResources; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 470 | Vector<SkiaColorFilter*> mFilterResources; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 471 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 472 | Vector<SkPaint*> mPaints; |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 473 | Vector<SkPath*> mPaths; |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 474 | Vector<SkMatrix*> mMatrices; |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 475 | Vector<SkiaShader*> mShaders; |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 476 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 477 | mutable SkFlattenableReadBuffer mReader; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 478 | |
| 479 | size_t mSize; |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 480 | |
| 481 | bool mIsRenderable; |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 482 | |
| 483 | String8 mName; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 484 | |
| 485 | // View properties |
| 486 | float mApplicationScale; |
| 487 | bool mClipChildren; |
| 488 | float mAlpha; |
| 489 | int mMultipliedAlpha; |
| 490 | float mTranslationX, mTranslationY; |
| 491 | float mRotation, mRotationX, mRotationY; |
| 492 | float mScaleX, mScaleY; |
| 493 | float mPivotX, mPivotY; |
| 494 | float mCameraDistance; |
| 495 | int mLeft, mTop, mRight, mBottom; |
| 496 | int mWidth, mHeight; |
| 497 | int mPrevWidth, mPrevHeight; |
| 498 | bool mPivotExplicitlySet; |
| 499 | bool mMatrixDirty; |
| 500 | bool mMatrixIsIdentity; |
| 501 | uint32_t mMatrixFlags; |
| 502 | SkMatrix* mTransformMatrix; |
| 503 | Sk3DView* mTransformCamera; |
| 504 | SkMatrix* mTransformMatrix3D; |
| 505 | bool mCaching; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 506 | }; |
| 507 | |
| 508 | /////////////////////////////////////////////////////////////////////////////// |
| 509 | // Renderer |
| 510 | /////////////////////////////////////////////////////////////////////////////// |
| 511 | |
| 512 | /** |
| 513 | * Records drawing commands in a display list for latter playback. |
| 514 | */ |
| 515 | class DisplayListRenderer: public OpenGLRenderer { |
| 516 | public: |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 517 | ANDROID_API DisplayListRenderer(); |
| 518 | virtual ~DisplayListRenderer(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 519 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 520 | ANDROID_API DisplayList* getDisplayList(DisplayList* displayList); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 521 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 522 | virtual void setViewport(int width, int height); |
| 523 | virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque); |
| 524 | virtual void finish(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 525 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 526 | virtual status_t callDrawGLFunction(Functor *functor, Rect& dirty); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 527 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 528 | virtual void interrupt(); |
| 529 | virtual void resume(); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 530 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 531 | virtual int save(int flags); |
| 532 | virtual void restore(); |
| 533 | virtual void restoreToCount(int saveCount); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 534 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 535 | virtual int saveLayer(float left, float top, float right, float bottom, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 536 | SkPaint* p, int flags); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 537 | virtual int saveLayerAlpha(float left, float top, float right, float bottom, |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 538 | int alpha, int flags); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 539 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 540 | virtual void translate(float dx, float dy); |
| 541 | virtual void rotate(float degrees); |
| 542 | virtual void scale(float sx, float sy); |
| 543 | virtual void skew(float sx, float sy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 544 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 545 | virtual void setMatrix(SkMatrix* matrix); |
| 546 | virtual void concatMatrix(SkMatrix* matrix); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 547 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 548 | virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 549 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 550 | virtual status_t drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height, |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 551 | Rect& dirty, int32_t flags, uint32_t level = 0); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 552 | virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint); |
| 553 | virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint); |
| 554 | virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint); |
| 555 | virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 556 | float srcRight, float srcBottom, float dstLeft, float dstTop, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 557 | float dstRight, float dstBottom, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 558 | virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 559 | float* vertices, int* colors, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 560 | virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 561 | 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] | 562 | float left, float top, float right, float bottom, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 563 | virtual void drawColor(int color, SkXfermode::Mode mode); |
| 564 | virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint); |
| 565 | virtual void drawRoundRect(float left, float top, float right, float bottom, |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 566 | float rx, float ry, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 567 | virtual void drawCircle(float x, float y, float radius, SkPaint* paint); |
| 568 | virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint); |
| 569 | virtual void drawArc(float left, float top, float right, float bottom, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 570 | float startAngle, float sweepAngle, bool useCenter, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 571 | virtual void drawPath(SkPath* path, SkPaint* paint); |
| 572 | virtual void drawLines(float* points, int count, SkPaint* paint); |
| 573 | virtual void drawPoints(float* points, int count, SkPaint* paint); |
| 574 | virtual void drawText(const char* text, int bytesCount, int count, float x, float y, |
Romain Guy | acdd4b9 | 2012-03-15 14:36:52 -0700 | [diff] [blame] | 575 | SkPaint* paint, float length = -1.0f); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 576 | virtual void drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path, |
| 577 | float hOffset, float vOffset, SkPaint* paint); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 578 | virtual void drawPosText(const char* text, int bytesCount, int count, const float* positions, |
| 579 | SkPaint* paint); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 580 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 581 | virtual void resetShader(); |
| 582 | virtual void setupShader(SkiaShader* shader); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 583 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 584 | virtual void resetColorFilter(); |
| 585 | virtual void setupColorFilter(SkiaColorFilter* filter); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 586 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 587 | virtual void resetShadow(); |
| 588 | virtual void setupShadow(float radius, float dx, float dy, int color); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 589 | |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 590 | virtual void resetPaintFilter(); |
| 591 | virtual void setupPaintFilter(int clearBits, int setBits); |
| 592 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 593 | ANDROID_API void reset(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 594 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 595 | const SkWriter32& writeStream() const { |
| 596 | return mWriter; |
| 597 | } |
| 598 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 599 | const Vector<SkBitmap*>& getBitmapResources() const { |
| 600 | return mBitmapResources; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 603 | const Vector<SkiaColorFilter*>& getFilterResources() const { |
| 604 | return mFilterResources; |
| 605 | } |
| 606 | |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 607 | const Vector<SkiaShader*>& getShaders() const { |
| 608 | return mShaders; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 611 | const Vector<SkPaint*>& getPaints() const { |
| 612 | return mPaints; |
| 613 | } |
| 614 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 615 | const Vector<SkPath*>& getPaths() const { |
| 616 | return mPaths; |
| 617 | } |
| 618 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 619 | const Vector<SkMatrix*>& getMatrices() const { |
| 620 | return mMatrices; |
| 621 | } |
| 622 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 623 | private: |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 624 | void insertRestoreToCount() { |
| 625 | if (mRestoreSaveCount >= 0) { |
| 626 | mWriter.writeInt(DisplayList::RestoreToCount); |
| 627 | addInt(mRestoreSaveCount); |
| 628 | mRestoreSaveCount = -1; |
| 629 | } |
| 630 | } |
| 631 | |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 632 | void insertTranlate() { |
| 633 | if (mHasTranslate) { |
| 634 | if (mTranslateX != 0.0f || mTranslateY != 0.0f) { |
| 635 | mWriter.writeInt(DisplayList::Translate); |
| 636 | addPoint(mTranslateX, mTranslateY); |
| 637 | mTranslateX = mTranslateY = 0.0f; |
| 638 | } |
| 639 | mHasTranslate = false; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | inline void addOp(const DisplayList::Op drawOp) { |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 644 | insertRestoreToCount(); |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 645 | insertTranlate(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 646 | mWriter.writeInt(drawOp); |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 647 | mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 650 | uint32_t* addOp(const DisplayList::Op drawOp, const bool reject) { |
| 651 | insertRestoreToCount(); |
| 652 | insertTranlate(); |
| 653 | mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList; |
| 654 | if (reject) { |
| 655 | mWriter.writeInt(OP_MAY_BE_SKIPPED_MASK | drawOp); |
Romain Guy | ad1daaa | 2012-03-01 17:33:42 -0800 | [diff] [blame] | 656 | mWriter.writeInt(0xdeaddead); |
Romain Guy | 390f882 | 2012-03-13 18:00:10 -0700 | [diff] [blame] | 657 | mBufferSize = mWriter.size(); |
| 658 | return mWriter.peek32(mBufferSize - sizeof(int32_t)); |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 659 | } |
| 660 | mWriter.writeInt(drawOp); |
| 661 | return NULL; |
| 662 | } |
| 663 | |
| 664 | inline void addSkip(uint32_t* location) { |
| 665 | if (location) { |
Romain Guy | 390f882 | 2012-03-13 18:00:10 -0700 | [diff] [blame] | 666 | *location = (int32_t) (mWriter.size() - mBufferSize); |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
| 670 | inline void addInt(int32_t value) { |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 671 | mWriter.writeInt(value); |
| 672 | } |
| 673 | |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 674 | inline void addSize(uint32_t w, uint32_t h) { |
| 675 | mWriter.writeInt(w); |
| 676 | mWriter.writeInt(h); |
| 677 | } |
| 678 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 679 | void addInts(const int32_t* values, uint32_t count) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 680 | mWriter.writeInt(count); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 681 | for (uint32_t i = 0; i < count; i++) { |
| 682 | mWriter.writeInt(values[i]); |
| 683 | } |
| 684 | } |
| 685 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 686 | void addUInts(const uint32_t* values, int8_t count) { |
| 687 | mWriter.writeInt(count); |
| 688 | for (int8_t i = 0; i < count; i++) { |
| 689 | mWriter.writeInt(values[i]); |
| 690 | } |
| 691 | } |
| 692 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 693 | inline void addFloat(float value) { |
| 694 | mWriter.writeScalar(value); |
| 695 | } |
| 696 | |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 697 | void addFloats(const float* values, int32_t count) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 698 | mWriter.writeInt(count); |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 699 | for (int32_t i = 0; i < count; i++) { |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 700 | mWriter.writeScalar(values[i]); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | inline void addPoint(float x, float y) { |
| 705 | mWriter.writeScalar(x); |
| 706 | mWriter.writeScalar(y); |
| 707 | } |
| 708 | |
| 709 | inline void addBounds(float left, float top, float right, float bottom) { |
| 710 | mWriter.writeScalar(left); |
| 711 | mWriter.writeScalar(top); |
| 712 | mWriter.writeScalar(right); |
| 713 | mWriter.writeScalar(bottom); |
| 714 | } |
| 715 | |
| 716 | inline void addText(const void* text, size_t byteLength) { |
| 717 | mWriter.writeInt(byteLength); |
| 718 | mWriter.writePad(text, byteLength); |
| 719 | } |
| 720 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 721 | inline void addPath(SkPath* path) { |
| 722 | if (!path) { |
| 723 | addInt((int) NULL); |
| 724 | return; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 725 | } |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 726 | |
| 727 | SkPath* pathCopy = mPathMap.valueFor(path); |
| 728 | if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) { |
Romain Guy | b29cfbf | 2011-03-18 16:24:19 -0700 | [diff] [blame] | 729 | pathCopy = new SkPath(*path); |
Romain Guy | 4bcb746 | 2012-02-23 17:08:38 -0800 | [diff] [blame] | 730 | pathCopy->setSourcePath(path); |
Romain Guy | 96ebc6b | 2012-02-21 18:32:32 -0800 | [diff] [blame] | 731 | // replaceValueFor() performs an add if the entry doesn't exist |
| 732 | mPathMap.replaceValueFor(path, pathCopy); |
Romain Guy | b29cfbf | 2011-03-18 16:24:19 -0700 | [diff] [blame] | 733 | mPaths.add(pathCopy); |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | addInt((int) pathCopy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 739 | inline void addPaint(SkPaint* paint) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 740 | if (!paint) { |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 741 | addInt((int) NULL); |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 742 | return; |
| 743 | } |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 744 | |
Romain Guy | 22d4184 | 2012-01-19 18:33:25 -0800 | [diff] [blame] | 745 | SkPaint* paintCopy = mPaintMap.valueFor(paint); |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 746 | if (paintCopy == NULL || paintCopy->getGenerationID() != paint->getGenerationID()) { |
| 747 | paintCopy = new SkPaint(*paint); |
Romain Guy | 96ebc6b | 2012-02-21 18:32:32 -0800 | [diff] [blame] | 748 | // replaceValueFor() performs an add if the entry doesn't exist |
| 749 | mPaintMap.replaceValueFor(paint, paintCopy); |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 750 | mPaints.add(paintCopy); |
| 751 | } |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 752 | |
| 753 | addInt((int) paintCopy); |
| 754 | } |
| 755 | |
| 756 | inline void addDisplayList(DisplayList* displayList) { |
| 757 | // TODO: To be safe, the display list should be ref-counted in the |
| 758 | // resources cache, but we rely on the caller (UI toolkit) to |
| 759 | // do the right thing for now |
| 760 | addInt((int) displayList); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 763 | inline void addMatrix(SkMatrix* matrix) { |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 764 | // Copying the matrix is cheap and prevents against the user changing the original |
| 765 | // matrix before the operation that uses it |
Romain Guy | f6a63ae | 2011-06-22 15:13:09 -0700 | [diff] [blame] | 766 | SkMatrix* copy = new SkMatrix(*matrix); |
| 767 | addInt((int) copy); |
| 768 | mMatrices.add(copy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 771 | inline void addBitmap(SkBitmap* bitmap) { |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 772 | // Note that this assumes the bitmap is immutable. There are cases this won't handle |
| 773 | // correctly, such as creating the bitmap from scratch, drawing with it, changing its |
| 774 | // contents, and drawing again. The only fix would be to always copy it the first time, |
| 775 | // which doesn't seem worth the extra cycles for this unlikely case. |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 776 | addInt((int) bitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 777 | mBitmapResources.add(bitmap); |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 778 | Caches::getInstance().resourceCache.incrementRefcount(bitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 779 | } |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 780 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 781 | inline void addShader(SkiaShader* shader) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 782 | if (!shader) { |
| 783 | addInt((int) NULL); |
| 784 | return; |
| 785 | } |
| 786 | |
| 787 | SkiaShader* shaderCopy = mShaderMap.valueFor(shader); |
| 788 | // TODO: We also need to handle generation ID changes in compose shaders |
Romain Guy | 1f1fcb7 | 2011-01-14 15:37:54 -0800 | [diff] [blame] | 789 | if (shaderCopy == NULL || shaderCopy->getGenerationId() != shader->getGenerationId()) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 790 | shaderCopy = shader->copy(); |
Romain Guy | 96ebc6b | 2012-02-21 18:32:32 -0800 | [diff] [blame] | 791 | // replaceValueFor() performs an add if the entry doesn't exist |
| 792 | mShaderMap.replaceValueFor(shader, shaderCopy); |
Romain Guy | 1f1fcb7 | 2011-01-14 15:37:54 -0800 | [diff] [blame] | 793 | mShaders.add(shaderCopy); |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 794 | Caches::getInstance().resourceCache.incrementRefcount(shaderCopy); |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | addInt((int) shaderCopy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 800 | inline void addColorFilter(SkiaColorFilter* colorFilter) { |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 801 | addInt((int) colorFilter); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 802 | mFilterResources.add(colorFilter); |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 803 | Caches::getInstance().resourceCache.incrementRefcount(colorFilter); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 806 | Vector<SkBitmap*> mBitmapResources; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 807 | Vector<SkiaColorFilter*> mFilterResources; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 808 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 809 | Vector<SkPaint*> mPaints; |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 810 | DefaultKeyedVector<SkPaint*, SkPaint*> mPaintMap; |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 811 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 812 | Vector<SkPath*> mPaths; |
| 813 | DefaultKeyedVector<SkPath*, SkPath*> mPathMap; |
| 814 | |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 815 | Vector<SkiaShader*> mShaders; |
| 816 | DefaultKeyedVector<SkiaShader*, SkiaShader*> mShaderMap; |
| 817 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 818 | Vector<SkMatrix*> mMatrices; |
| 819 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 820 | SkWriter32 mWriter; |
Romain Guy | 390f882 | 2012-03-13 18:00:10 -0700 | [diff] [blame] | 821 | uint32_t mBufferSize; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 822 | |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 823 | int mRestoreSaveCount; |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 824 | |
| 825 | float mTranslateX; |
| 826 | float mTranslateY; |
| 827 | bool mHasTranslate; |
| 828 | |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 829 | bool mHasDrawOps; |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 830 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 831 | friend class DisplayList; |
| 832 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 833 | }; // class DisplayListRenderer |
| 834 | |
| 835 | }; // namespace uirenderer |
| 836 | }; // namespace android |
| 837 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 838 | #endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H |