Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
| 17 | #ifndef ANDROID_HWUI_DISPLAY_LIST_H |
| 18 | #define ANDROID_HWUI_DISPLAY_LIST_H |
| 19 | |
Romain Guy | 7031ff6 | 2013-02-22 11:48:16 -0800 | [diff] [blame] | 20 | #ifndef LOG_TAG |
| 21 | #define LOG_TAG "OpenGLRenderer" |
| 22 | #endif |
| 23 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 24 | #include <SkCamera.h> |
| 25 | #include <SkMatrix.h> |
| 26 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 27 | #include <private/hwui/DrawGlInfo.h> |
| 28 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 29 | #include <utils/KeyedVector.h> |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 30 | #include <utils/LinearAllocator.h> |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 31 | #include <utils/RefBase.h> |
| 32 | #include <utils/SortedVector.h> |
| 33 | #include <utils/String8.h> |
| 34 | #include <utils/Vector.h> |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 35 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 36 | #include <cutils/compiler.h> |
| 37 | |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 38 | #include <androidfw/ResourceTypes.h> |
| 39 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 40 | #include "Debug.h" |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 41 | #include "Matrix.h" |
| 42 | #include "DeferredDisplayList.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 43 | |
| 44 | #define TRANSLATION 0x0001 |
| 45 | #define ROTATION 0x0002 |
| 46 | #define ROTATION_3D 0x0004 |
| 47 | #define SCALE 0x0008 |
| 48 | #define PIVOT 0x0010 |
| 49 | |
| 50 | class SkBitmap; |
| 51 | class SkPaint; |
| 52 | class SkPath; |
| 53 | class SkRegion; |
| 54 | |
| 55 | namespace android { |
| 56 | namespace uirenderer { |
| 57 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 58 | class DeferredDisplayList; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 59 | class DisplayListOp; |
| 60 | class DisplayListRenderer; |
| 61 | class OpenGLRenderer; |
| 62 | class Rect; |
| 63 | class Layer; |
| 64 | class SkiaColorFilter; |
| 65 | class SkiaShader; |
| 66 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 67 | class ClipRectOp; |
| 68 | class SaveLayerOp; |
| 69 | class SaveOp; |
| 70 | class RestoreToCountOp; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 71 | class DrawDisplayListOp; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 72 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 73 | /** |
| 74 | * Holds data used in the playback a tree of DisplayLists. |
| 75 | */ |
| 76 | class PlaybackStateStruct { |
| 77 | protected: |
| 78 | PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator) |
| 79 | : mRenderer(renderer), mReplayFlags(replayFlags), mAllocator(allocator){} |
| 80 | |
| 81 | public: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 82 | OpenGLRenderer& mRenderer; |
| 83 | const int mReplayFlags; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 84 | |
| 85 | // Allocator with the lifetime of a single frame. |
| 86 | // replay uses an Allocator owned by the struct, while defer shares the DeferredDisplayList's Allocator |
| 87 | LinearAllocator * const mAllocator; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 90 | class DeferStateStruct : public PlaybackStateStruct { |
| 91 | public: |
| 92 | DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags) |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame^] | 93 | : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)), |
| 94 | mDeferredList(deferredList) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 95 | |
| 96 | DeferredDisplayList& mDeferredList; |
| 97 | }; |
| 98 | |
| 99 | class ReplayStateStruct : public PlaybackStateStruct { |
| 100 | public: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 101 | ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 102 | : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), |
| 103 | mDirty(dirty), mDrawGlStatus(DrawGlInfo::kStatusDone) {} |
| 104 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 105 | Rect& mDirty; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 106 | status_t mDrawGlStatus; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 107 | LinearAllocator mReplayAllocator; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 110 | /** |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 111 | * Refcounted structure that holds the list of commands used in display list stream. |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 112 | */ |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 113 | class DisplayListData : public LightRefBase<DisplayListData> { |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 114 | public: |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 115 | // allocator into which all ops were allocated |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 116 | LinearAllocator allocator; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 117 | |
| 118 | // pointers to all ops within display list, pointing into allocator data |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 119 | Vector<DisplayListOp*> displayListOps; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 120 | |
| 121 | // list of children display lists for quick, non-drawing traversal |
| 122 | Vector<DrawDisplayListOp*> children; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | /** |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 126 | * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display properties. |
| 127 | * |
| 128 | * Recording of canvas commands is somewhat similar to SkPicture, except the canvas-recording |
| 129 | * functionality is split between DisplayListRenderer (which manages the recording), DisplayListData |
| 130 | * (which holds the actual data), and DisplayList (which holds properties and performs playback onto |
| 131 | * a renderer). |
| 132 | * |
| 133 | * Note that DisplayListData is swapped out from beneath an individual DisplayList when a view's |
| 134 | * recorded stream of canvas operations is refreshed. The DisplayList (and its properties) stay |
| 135 | * attached. |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 136 | */ |
| 137 | class DisplayList { |
| 138 | public: |
| 139 | DisplayList(const DisplayListRenderer& recorder); |
| 140 | ANDROID_API ~DisplayList(); |
| 141 | |
| 142 | // See flags defined in DisplayList.java |
| 143 | enum ReplayFlag { |
| 144 | kReplayFlag_ClipChildren = 0x1 |
| 145 | }; |
| 146 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 147 | ANDROID_API size_t getSize(); |
| 148 | ANDROID_API static void destroyDisplayListDeferred(DisplayList* displayList); |
| 149 | ANDROID_API static void outputLogBuffer(int fd); |
| 150 | |
| 151 | void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false); |
| 152 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 153 | void computeOrdering(); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 154 | void defer(DeferStateStruct& deferStruct, const int level); |
| 155 | void replay(ReplayStateStruct& replayStruct, const int level); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 156 | |
John Reck | 6304919 | 2013-12-10 15:22:01 -0800 | [diff] [blame] | 157 | ANDROID_API void output(uint32_t level = 1); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 158 | |
| 159 | ANDROID_API void reset(); |
| 160 | |
| 161 | void setRenderable(bool renderable) { |
| 162 | mIsRenderable = renderable; |
| 163 | } |
| 164 | |
| 165 | bool isRenderable() const { |
| 166 | return mIsRenderable; |
| 167 | } |
| 168 | |
| 169 | void setName(const char* name) { |
| 170 | if (name) { |
Romain Guy | 450dc75 | 2013-06-05 14:14:03 -0700 | [diff] [blame] | 171 | char* lastPeriod = strrchr(name, '.'); |
| 172 | if (lastPeriod) { |
| 173 | mName.setTo(lastPeriod + 1); |
| 174 | } else { |
| 175 | mName.setTo(name); |
| 176 | } |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 180 | const char* getName() const { |
| 181 | return mName.string(); |
| 182 | } |
| 183 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 184 | void setClipToBounds(bool clipToBounds) { |
| 185 | mClipToBounds = clipToBounds; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Chris Craik | d863a10 | 2013-12-19 13:31:15 -0800 | [diff] [blame] | 188 | void setIsContainedVolume(bool isContainedVolume) { |
| 189 | mIsContainedVolume = isContainedVolume; |
| 190 | } |
| 191 | |
Alan Viverette | 58f09b3 | 2014-01-08 17:18:19 -0800 | [diff] [blame] | 192 | void setProjectToContainedVolume(bool shouldProject) { |
| 193 | mProjectToContainedVolume = shouldProject; |
| 194 | } |
| 195 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 196 | void setStaticMatrix(SkMatrix* matrix) { |
| 197 | delete mStaticMatrix; |
| 198 | mStaticMatrix = new SkMatrix(*matrix); |
| 199 | } |
| 200 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 201 | // Can return NULL |
| 202 | SkMatrix* getStaticMatrix() { |
| 203 | return mStaticMatrix; |
| 204 | } |
| 205 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 206 | void setAnimationMatrix(SkMatrix* matrix) { |
| 207 | delete mAnimationMatrix; |
| 208 | if (matrix) { |
| 209 | mAnimationMatrix = new SkMatrix(*matrix); |
| 210 | } else { |
| 211 | mAnimationMatrix = NULL; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | void setAlpha(float alpha) { |
| 216 | alpha = fminf(1.0f, fmaxf(0.0f, alpha)); |
| 217 | if (alpha != mAlpha) { |
| 218 | mAlpha = alpha; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 222 | float getAlpha() const { |
| 223 | return mAlpha; |
| 224 | } |
| 225 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 226 | void setHasOverlappingRendering(bool hasOverlappingRendering) { |
| 227 | mHasOverlappingRendering = hasOverlappingRendering; |
| 228 | } |
| 229 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 230 | bool hasOverlappingRendering() const { |
| 231 | return mHasOverlappingRendering; |
| 232 | } |
| 233 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 234 | void setTranslationX(float translationX) { |
| 235 | if (translationX != mTranslationX) { |
| 236 | mTranslationX = translationX; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 237 | onTranslationUpdate(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 241 | float getTranslationX() const { |
| 242 | return mTranslationX; |
| 243 | } |
| 244 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 245 | void setTranslationY(float translationY) { |
| 246 | if (translationY != mTranslationY) { |
| 247 | mTranslationY = translationY; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 248 | onTranslationUpdate(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 252 | float getTranslationY() const { |
| 253 | return mTranslationY; |
| 254 | } |
| 255 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 256 | void setTranslationZ(float translationZ) { |
| 257 | if (translationZ != mTranslationZ) { |
| 258 | mTranslationZ = translationZ; |
| 259 | onTranslationUpdate(); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | float getTranslationZ() const { |
| 264 | return mTranslationZ; |
| 265 | } |
| 266 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 267 | void setRotation(float rotation) { |
| 268 | if (rotation != mRotation) { |
| 269 | mRotation = rotation; |
| 270 | mMatrixDirty = true; |
| 271 | if (mRotation == 0.0f) { |
| 272 | mMatrixFlags &= ~ROTATION; |
| 273 | } else { |
| 274 | mMatrixFlags |= ROTATION; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 279 | float getRotation() const { |
| 280 | return mRotation; |
| 281 | } |
| 282 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 283 | void setRotationX(float rotationX) { |
| 284 | if (rotationX != mRotationX) { |
| 285 | mRotationX = rotationX; |
| 286 | mMatrixDirty = true; |
| 287 | if (mRotationX == 0.0f && mRotationY == 0.0f) { |
| 288 | mMatrixFlags &= ~ROTATION_3D; |
| 289 | } else { |
| 290 | mMatrixFlags |= ROTATION_3D; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 295 | float getRotationX() const { |
| 296 | return mRotationX; |
| 297 | } |
| 298 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 299 | void setRotationY(float rotationY) { |
| 300 | if (rotationY != mRotationY) { |
| 301 | mRotationY = rotationY; |
| 302 | mMatrixDirty = true; |
| 303 | if (mRotationX == 0.0f && mRotationY == 0.0f) { |
| 304 | mMatrixFlags &= ~ROTATION_3D; |
| 305 | } else { |
| 306 | mMatrixFlags |= ROTATION_3D; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 311 | float getRotationY() const { |
| 312 | return mRotationY; |
| 313 | } |
| 314 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 315 | void setScaleX(float scaleX) { |
| 316 | if (scaleX != mScaleX) { |
| 317 | mScaleX = scaleX; |
| 318 | mMatrixDirty = true; |
| 319 | if (mScaleX == 1.0f && mScaleY == 1.0f) { |
| 320 | mMatrixFlags &= ~SCALE; |
| 321 | } else { |
| 322 | mMatrixFlags |= SCALE; |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 327 | float getScaleX() const { |
| 328 | return mScaleX; |
| 329 | } |
| 330 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 331 | void setScaleY(float scaleY) { |
| 332 | if (scaleY != mScaleY) { |
| 333 | mScaleY = scaleY; |
| 334 | mMatrixDirty = true; |
| 335 | if (mScaleX == 1.0f && mScaleY == 1.0f) { |
| 336 | mMatrixFlags &= ~SCALE; |
| 337 | } else { |
| 338 | mMatrixFlags |= SCALE; |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 343 | float getScaleY() const { |
| 344 | return mScaleY; |
| 345 | } |
| 346 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 347 | void setPivotX(float pivotX) { |
| 348 | mPivotX = pivotX; |
| 349 | mMatrixDirty = true; |
| 350 | if (mPivotX == 0.0f && mPivotY == 0.0f) { |
| 351 | mMatrixFlags &= ~PIVOT; |
| 352 | } else { |
| 353 | mMatrixFlags |= PIVOT; |
| 354 | } |
| 355 | mPivotExplicitlySet = true; |
| 356 | } |
| 357 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 358 | ANDROID_API float getPivotX(); |
| 359 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 360 | void setPivotY(float pivotY) { |
| 361 | mPivotY = pivotY; |
| 362 | mMatrixDirty = true; |
| 363 | if (mPivotX == 0.0f && mPivotY == 0.0f) { |
| 364 | mMatrixFlags &= ~PIVOT; |
| 365 | } else { |
| 366 | mMatrixFlags |= PIVOT; |
| 367 | } |
| 368 | mPivotExplicitlySet = true; |
| 369 | } |
| 370 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 371 | ANDROID_API float getPivotY(); |
| 372 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 373 | void setCameraDistance(float distance) { |
| 374 | if (distance != mCameraDistance) { |
| 375 | mCameraDistance = distance; |
| 376 | mMatrixDirty = true; |
| 377 | if (!mTransformCamera) { |
| 378 | mTransformCamera = new Sk3DView(); |
| 379 | mTransformMatrix3D = new SkMatrix(); |
| 380 | } |
| 381 | mTransformCamera->setCameraLocation(0, 0, distance); |
| 382 | } |
| 383 | } |
| 384 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 385 | float getCameraDistance() const { |
| 386 | return mCameraDistance; |
| 387 | } |
| 388 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 389 | void setLeft(int left) { |
| 390 | if (left != mLeft) { |
| 391 | mLeft = left; |
| 392 | mWidth = mRight - mLeft; |
| 393 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 394 | mMatrixDirty = true; |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 399 | float getLeft() const { |
| 400 | return mLeft; |
| 401 | } |
| 402 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 403 | void setTop(int top) { |
| 404 | if (top != mTop) { |
| 405 | mTop = top; |
| 406 | mHeight = mBottom - mTop; |
| 407 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 408 | mMatrixDirty = true; |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 413 | float getTop() const { |
| 414 | return mTop; |
| 415 | } |
| 416 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 417 | void setRight(int right) { |
| 418 | if (right != mRight) { |
| 419 | mRight = right; |
| 420 | mWidth = mRight - mLeft; |
| 421 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 422 | mMatrixDirty = true; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 427 | float getRight() const { |
| 428 | return mRight; |
| 429 | } |
| 430 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 431 | void setBottom(int bottom) { |
| 432 | if (bottom != mBottom) { |
| 433 | mBottom = bottom; |
| 434 | mHeight = mBottom - mTop; |
| 435 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 436 | mMatrixDirty = true; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 441 | float getBottom() const { |
| 442 | return mBottom; |
| 443 | } |
| 444 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 445 | void setLeftTop(int left, int top) { |
| 446 | if (left != mLeft || top != mTop) { |
| 447 | mLeft = left; |
| 448 | mTop = top; |
| 449 | mWidth = mRight - mLeft; |
| 450 | mHeight = mBottom - mTop; |
| 451 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 452 | mMatrixDirty = true; |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | void setLeftTopRightBottom(int left, int top, int right, int bottom) { |
| 458 | if (left != mLeft || top != mTop || right != mRight || bottom != mBottom) { |
| 459 | mLeft = left; |
| 460 | mTop = top; |
| 461 | mRight = right; |
| 462 | mBottom = bottom; |
| 463 | mWidth = mRight - mLeft; |
| 464 | mHeight = mBottom - mTop; |
| 465 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 466 | mMatrixDirty = true; |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 471 | void offsetLeftRight(float offset) { |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 472 | if (offset != 0) { |
| 473 | mLeft += offset; |
| 474 | mRight += offset; |
| 475 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 476 | mMatrixDirty = true; |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 481 | void offsetTopBottom(float offset) { |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 482 | if (offset != 0) { |
| 483 | mTop += offset; |
| 484 | mBottom += offset; |
| 485 | if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) { |
| 486 | mMatrixDirty = true; |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | void setCaching(bool caching) { |
| 492 | mCaching = caching; |
| 493 | } |
| 494 | |
| 495 | int getWidth() { |
| 496 | return mWidth; |
| 497 | } |
| 498 | |
| 499 | int getHeight() { |
| 500 | return mHeight; |
| 501 | } |
| 502 | |
| 503 | private: |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame^] | 504 | typedef key_value_pair_t<float, DrawDisplayListOp*> ZDrawDisplayListOpPair; |
| 505 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 506 | enum ChildrenSelectMode { |
| 507 | kNegativeZChildren, |
| 508 | kPositiveZChildren |
| 509 | }; |
| 510 | |
| 511 | void onTranslationUpdate() { |
| 512 | mMatrixDirty = true; |
| 513 | if (mTranslationX == 0.0f && mTranslationY == 0.0f && mTranslationZ == 0.0f) { |
| 514 | mMatrixFlags &= ~TRANSLATION; |
| 515 | } else { |
| 516 | mMatrixFlags |= TRANSLATION; |
| 517 | } |
| 518 | } |
| 519 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 520 | void outputViewProperties(const int level); |
| 521 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 522 | void applyViewPropertyTransforms(mat4& matrix); |
| 523 | |
| 524 | void computeOrderingImpl(DrawDisplayListOp* opState, |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame^] | 525 | Vector<ZDrawDisplayListOpPair>* compositedChildrenOf3dRoot, |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 526 | const mat4* transformFromRoot); |
| 527 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 528 | template <class T> |
| 529 | inline void setViewProperties(OpenGLRenderer& renderer, T& handler, const int level); |
| 530 | |
| 531 | template <class T> |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 532 | inline void iterate3dChildren(ChildrenSelectMode mode, OpenGLRenderer& renderer, |
| 533 | T& handler, const int level); |
| 534 | |
| 535 | template <class T> |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 536 | inline void iterate(OpenGLRenderer& renderer, T& handler, const int level); |
| 537 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 538 | void init(); |
| 539 | |
| 540 | void clearResources(); |
| 541 | |
| 542 | void updateMatrix(); |
| 543 | |
| 544 | class TextContainer { |
| 545 | public: |
| 546 | size_t length() const { |
| 547 | return mByteLength; |
| 548 | } |
| 549 | |
| 550 | const char* text() const { |
| 551 | return (const char*) mText; |
| 552 | } |
| 553 | |
| 554 | size_t mByteLength; |
| 555 | const char* mText; |
| 556 | }; |
| 557 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 558 | Vector<const SkBitmap*> mBitmapResources; |
| 559 | Vector<const SkBitmap*> mOwnedBitmapResources; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 560 | Vector<SkiaColorFilter*> mFilterResources; |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 561 | Vector<const Res_png_9patch*> mPatchResources; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 562 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 563 | Vector<const SkPaint*> mPaints; |
| 564 | Vector<const SkPath*> mPaths; |
| 565 | SortedVector<const SkPath*> mSourcePaths; |
| 566 | Vector<const SkRegion*> mRegions; |
| 567 | Vector<const SkMatrix*> mMatrices; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 568 | Vector<SkiaShader*> mShaders; |
| 569 | Vector<Layer*> mLayers; |
| 570 | |
| 571 | sp<DisplayListData> mDisplayListData; |
| 572 | |
| 573 | size_t mSize; |
| 574 | |
| 575 | bool mIsRenderable; |
| 576 | uint32_t mFunctorCount; |
| 577 | |
| 578 | String8 mName; |
Chris Craik | 9846de6 | 2013-06-12 16:23:00 -0700 | [diff] [blame] | 579 | bool mDestroyed; // used for debugging crash, TODO: remove once invalid state crash fixed |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 580 | |
Alan Viverette | 58f09b3 | 2014-01-08 17:18:19 -0800 | [diff] [blame] | 581 | // Rendering properties |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 582 | bool mClipToBounds; |
Chris Craik | d863a10 | 2013-12-19 13:31:15 -0800 | [diff] [blame] | 583 | bool mIsContainedVolume; |
Alan Viverette | 58f09b3 | 2014-01-08 17:18:19 -0800 | [diff] [blame] | 584 | bool mProjectToContainedVolume; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 585 | float mAlpha; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 586 | bool mHasOverlappingRendering; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 587 | float mTranslationX, mTranslationY, mTranslationZ; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 588 | float mRotation, mRotationX, mRotationY; |
| 589 | float mScaleX, mScaleY; |
| 590 | float mPivotX, mPivotY; |
| 591 | float mCameraDistance; |
| 592 | int mLeft, mTop, mRight, mBottom; |
| 593 | int mWidth, mHeight; |
| 594 | int mPrevWidth, mPrevHeight; |
| 595 | bool mPivotExplicitlySet; |
| 596 | bool mMatrixDirty; |
| 597 | bool mMatrixIsIdentity; |
| 598 | uint32_t mMatrixFlags; |
| 599 | SkMatrix* mTransformMatrix; |
| 600 | Sk3DView* mTransformCamera; |
| 601 | SkMatrix* mTransformMatrix3D; |
| 602 | SkMatrix* mStaticMatrix; |
| 603 | SkMatrix* mAnimationMatrix; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 604 | Matrix4 mTransform; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 605 | bool mCaching; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 606 | |
| 607 | /** |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 608 | * Draw time state - these properties are only set and used during rendering |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 609 | */ |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 610 | |
| 611 | // for 3d roots, contains a z sorted list of all children items |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame^] | 612 | Vector<ZDrawDisplayListOpPair> m3dNodes; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 613 | }; // class DisplayList |
| 614 | |
| 615 | }; // namespace uirenderer |
| 616 | }; // namespace android |
| 617 | |
| 618 | #endif // ANDROID_HWUI_OPENGL_RENDERER_H |