| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#ifdef __ANDROID__ |
| 20 |
#include "DeviceInfo.h" |
| 21 |
#endif |
| 22 |
|
| 23 |
#include "Outline.h" |
| 24 |
#include "Rect.h" |
| 25 |
#include "RevealClip.h" |
| 26 |
#include "effects/StretchEffect.h" |
| 27 |
#include "utils/MathUtils.h" |
| 28 |
#include "utils/PaintUtils.h" |
| 29 |
|
| 30 |
#include <SkBlendMode.h> |
| 31 |
#include <SkImageFilter.h> |
| 32 |
#include <SkCamera.h> |
| 33 |
#include <SkColor.h> |
| 34 |
#include <SkMatrix.h> |
| 35 |
#include <SkRegion.h> |
| 36 |
|
| 37 |
#include <androidfw/ResourceTypes.h> |
| 38 |
#include <cutils/compiler.h> |
| 39 |
#include <stddef.h> |
| 40 |
#include <utils/Log.h> |
| 41 |
#include <algorithm> |
| 42 |
#include <ostream> |
| 43 |
#include <vector> |
| 44 |
|
| 45 |
class SkBitmap; |
| 46 |
class SkColorFilter; |
| 47 |
class SkPaint; |
| 48 |
|
| 49 |
namespace android { |
| 50 |
namespace uirenderer { |
| 51 |
|
| 52 |
class Matrix4; |
| 53 |
class RenderNode; |
| 54 |
class RenderProperties; |
| 55 |
|
| 56 |
|
| 57 |
#define RP_SET(a, b, ...) ((a) != (b) ? ((a) = (b), ##__VA_ARGS__, true) : false) |
| 58 |
#define RP_SET_AND_DIRTY(a, b) RP_SET(a, b, mPrimitiveFields.mMatrixOrPivotDirty = true) |
| 59 |
|
| 60 |
|
| 61 |
enum class LayerType { |
| 62 |
None = 0, |
| 63 |
|
| 64 |
|
| 65 |
Software = 1, |
| 66 |
RenderLayer = 2, |
| 67 |
}; |
| 68 |
|
| 69 |
enum ClippingFlags { |
| 70 |
CLIP_TO_BOUNDS = 0x1 << 0, |
| 71 |
CLIP_TO_CLIP_BOUNDS = 0x1 << 1, |
| 72 |
}; |
| 73 |
|
| 74 |
class LayerProperties { |
| 75 |
public: |
| 76 |
bool setType(LayerType type) { |
| 77 |
if (RP_SET(mType, type)) { |
| 78 |
reset(); |
| 79 |
return true; |
| 80 |
} |
| 81 |
return false; |
| 82 |
} |
| 83 |
|
| 84 |
bool setOpaque(bool opaque) { return RP_SET(mOpaque, opaque); } |
| 85 |
|
| 86 |
bool opaque() const { return mOpaque; } |
| 87 |
|
| 88 |
bool setAlpha(uint8_t alpha) { return RP_SET(mAlpha, alpha); } |
| 89 |
|
| 90 |
uint8_t alpha() const { return mAlpha; } |
| 91 |
|
| 92 |
bool setXferMode(SkBlendMode mode) { return RP_SET(mMode, mode); } |
| 93 |
|
| 94 |
SkBlendMode xferMode() const { return mMode; } |
| 95 |
|
| 96 |
SkColorFilter* getColorFilter() const { return mColorFilter.get(); } |
| 97 |
|
| 98 |
bool setImageFilter(SkImageFilter* imageFilter); |
| 99 |
|
| 100 |
SkImageFilter* getImageFilter() const { return mImageFilter.get(); } |
| 101 |
|
| 102 |
const StretchEffect& getStretchEffect() const { return mStretchEffect; } |
| 103 |
|
| 104 |
StretchEffect& mutableStretchEffect() { return mStretchEffect; } |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
bool setFromPaint(const SkPaint* paint); |
| 109 |
|
| 110 |
bool needsBlending() const { return !opaque() || alpha() < 255; } |
| 111 |
|
| 112 |
LayerProperties& operator=(const LayerProperties& other); |
| 113 |
|
| 114 |
|
| 115 |
LayerType type() const { return mType; } |
| 116 |
|
| 117 |
private: |
| 118 |
LayerProperties(); |
| 119 |
~LayerProperties(); |
| 120 |
void reset(); |
| 121 |
bool setColorFilter(SkColorFilter* filter); |
| 122 |
|
| 123 |
friend class RenderProperties; |
| 124 |
|
| 125 |
LayerType mType = LayerType::None; |
| 126 |
|
| 127 |
bool mOpaque; |
| 128 |
uint8_t mAlpha; |
| 129 |
SkBlendMode mMode; |
| 130 |
sk_sp<SkColorFilter> mColorFilter; |
| 131 |
sk_sp<SkImageFilter> mImageFilter; |
| 132 |
StretchEffect mStretchEffect; |
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
class RenderProperties { |
| 139 |
public: |
| 140 |
RenderProperties(); |
| 141 |
virtual ~RenderProperties(); |
| 142 |
|
| 143 |
static bool setFlag(int flag, bool newValue, int* outFlags) { |
| 144 |
if (newValue) { |
| 145 |
if (!(flag & *outFlags)) { |
| 146 |
*outFlags |= flag; |
| 147 |
return true; |
| 148 |
} |
| 149 |
return false; |
| 150 |
} else { |
| 151 |
if (flag & *outFlags) { |
| 152 |
*outFlags &= ~flag; |
| 153 |
return true; |
| 154 |
} |
| 155 |
return false; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
bool prepareForFunctorPresence(bool willHaveFunctor, bool ancestorDictatesFunctorsNeedLayer) { |
| 166 |
|
| 167 |
bool functorsNeedLayer = |
| 168 |
ancestorDictatesFunctorsNeedLayer || |
| 169 |
CC_UNLIKELY(isClipMayBeComplex()) |
| 170 |
|
| 171 |
|
| 172 |
|| CC_UNLIKELY(getOutline().willComplexClip()) || |
| 173 |
CC_UNLIKELY(getRevealClip().willClip()) |
| 174 |
|
| 175 |
|
| 176 |
|| CC_UNLIKELY(getTransformMatrix() && !getTransformMatrix()->isScaleTranslate()) || |
| 177 |
CC_UNLIKELY(getAnimationMatrix() && !getAnimationMatrix()->isScaleTranslate()) || |
| 178 |
CC_UNLIKELY(getStaticMatrix() && !getStaticMatrix()->isScaleTranslate()); |
| 179 |
|
| 180 |
mComputedFields.mNeedLayerForFunctors = (willHaveFunctor && functorsNeedLayer); |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
return CC_LIKELY(effectiveLayerType() == LayerType::None) && functorsNeedLayer; |
| 185 |
} |
| 186 |
|
| 187 |
RenderProperties& operator=(const RenderProperties& other); |
| 188 |
|
| 189 |
bool setClipToBounds(bool clipToBounds) { |
| 190 |
return setFlag(CLIP_TO_BOUNDS, clipToBounds, &mPrimitiveFields.mClippingFlags); |
| 191 |
} |
| 192 |
|
| 193 |
bool setClipBounds(const Rect& clipBounds) { |
| 194 |
bool ret = setFlag(CLIP_TO_CLIP_BOUNDS, true, &mPrimitiveFields.mClippingFlags); |
| 195 |
return RP_SET(mPrimitiveFields.mClipBounds, clipBounds) || ret; |
| 196 |
} |
| 197 |
|
| 198 |
bool setClipBoundsEmpty() { |
| 199 |
return setFlag(CLIP_TO_CLIP_BOUNDS, false, &mPrimitiveFields.mClippingFlags); |
| 200 |
} |
| 201 |
|
| 202 |
bool setProjectBackwards(bool shouldProject) { |
| 203 |
return RP_SET(mPrimitiveFields.mProjectBackwards, shouldProject); |
| 204 |
} |
| 205 |
|
| 206 |
bool setProjectionReceiver(bool shouldReceive) { |
| 207 |
return RP_SET(mPrimitiveFields.mProjectionReceiver, shouldReceive); |
| 208 |
} |
| 209 |
|
| 210 |
bool isProjectionReceiver() const { return mPrimitiveFields.mProjectionReceiver; } |
| 211 |
|
| 212 |
bool setClipMayBeComplex(bool isClipMayBeComplex) { |
| 213 |
return RP_SET(mPrimitiveFields.mClipMayBeComplex, isClipMayBeComplex); |
| 214 |
} |
| 215 |
|
| 216 |
bool isClipMayBeComplex() const { return mPrimitiveFields.mClipMayBeComplex; } |
| 217 |
|
| 218 |
bool setStaticMatrix(const SkMatrix* matrix) { |
| 219 |
delete mStaticMatrix; |
| 220 |
if (matrix) { |
| 221 |
mStaticMatrix = new SkMatrix(*matrix); |
| 222 |
} else { |
| 223 |
mStaticMatrix = nullptr; |
| 224 |
} |
| 225 |
return true; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
const SkMatrix* getStaticMatrix() const { return mStaticMatrix; } |
| 230 |
|
| 231 |
bool setAnimationMatrix(const SkMatrix* matrix) { |
| 232 |
delete mAnimationMatrix; |
| 233 |
if (matrix) { |
| 234 |
mAnimationMatrix = new SkMatrix(*matrix); |
| 235 |
} else { |
| 236 |
mAnimationMatrix = nullptr; |
| 237 |
} |
| 238 |
return true; |
| 239 |
} |
| 240 |
|
| 241 |
bool setAlpha(float alpha) { |
| 242 |
alpha = MathUtils::clampAlpha(alpha); |
| 243 |
return RP_SET(mPrimitiveFields.mAlpha, alpha); |
| 244 |
} |
| 245 |
|
| 246 |
float getAlpha() const { return mPrimitiveFields.mAlpha; } |
| 247 |
|
| 248 |
bool setHasOverlappingRendering(bool hasOverlappingRendering) { |
| 249 |
return RP_SET(mPrimitiveFields.mHasOverlappingRendering, hasOverlappingRendering); |
| 250 |
} |
| 251 |
|
| 252 |
bool hasOverlappingRendering() const { return mPrimitiveFields.mHasOverlappingRendering; } |
| 253 |
|
| 254 |
bool setElevation(float elevation) { |
| 255 |
return RP_SET(mPrimitiveFields.mElevation, elevation); |
| 256 |
|
| 257 |
} |
| 258 |
|
| 259 |
float getElevation() const { return mPrimitiveFields.mElevation; } |
| 260 |
|
| 261 |
bool setTranslationX(float translationX) { |
| 262 |
return RP_SET_AND_DIRTY(mPrimitiveFields.mTranslationX, translationX); |
| 263 |
} |
| 264 |
|
| 265 |
float getTranslationX() const { return mPrimitiveFields.mTranslationX; } |
| 266 |
|
| 267 |
bool setTranslationY(float translationY) { |
| 268 |
return RP_SET_AND_DIRTY(mPrimitiveFields.mTranslationY, translationY); |
| 269 |
} |
| 270 |
|
| 271 |
float getTranslationY() const { return mPrimitiveFields.mTranslationY; } |
| 272 |
|
| 273 |
bool setTranslationZ(float translationZ) { |
| 274 |
return RP_SET(mPrimitiveFields.mTranslationZ, translationZ); |
| 275 |
|
| 276 |
} |
| 277 |
|
| 278 |
float getTranslationZ() const { return mPrimitiveFields.mTranslationZ; } |
| 279 |
|
| 280 |
|
| 281 |
bool setX(float value) { return setTranslationX(value - getLeft()); } |
| 282 |
|
| 283 |
|
| 284 |
float getX() const { return getLeft() + getTranslationX(); } |
| 285 |
|
| 286 |
|
| 287 |
bool setY(float value) { return setTranslationY(value - getTop()); } |
| 288 |
|
| 289 |
|
| 290 |
float getY() const { return getTop() + getTranslationY(); } |
| 291 |
|
| 292 |
|
| 293 |
bool setZ(float value) { return setTranslationZ(value - getElevation()); } |
| 294 |
|
| 295 |
float getZ() const { return getElevation() + getTranslationZ(); } |
| 296 |
|
| 297 |
bool setRotation(float rotation) { |
| 298 |
return RP_SET_AND_DIRTY(mPrimitiveFields.mRotation, rotation); |
| 299 |
} |
| 300 |
|
| 301 |
float getRotation() const { return mPrimitiveFields.mRotation; } |
| 302 |
|
| 303 |
bool setRotationX(float rotationX) { |
| 304 |
return RP_SET_AND_DIRTY(mPrimitiveFields.mRotationX, rotationX); |
| 305 |
} |
| 306 |
|
| 307 |
float getRotationX() const { return mPrimitiveFields.mRotationX; } |
| 308 |
|
| 309 |
bool setRotationY(float rotationY) { |
| 310 |
return RP_SET_AND_DIRTY(mPrimitiveFields.mRotationY, rotationY); |
| 311 |
} |
| 312 |
|
| 313 |
float getRotationY() const { return mPrimitiveFields.mRotationY; } |
| 314 |
|
| 315 |
bool setScaleX(float scaleX) { return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleX, scaleX); } |
| 316 |
|
| 317 |
float getScaleX() const { return mPrimitiveFields.mScaleX; } |
| 318 |
|
| 319 |
bool setScaleY(float scaleY) { return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleY, scaleY); } |
| 320 |
|
| 321 |
float getScaleY() const { return mPrimitiveFields.mScaleY; } |
| 322 |
|
| 323 |
bool setPivotX(float pivotX) { |
| 324 |
if (RP_SET(mPrimitiveFields.mPivotX, pivotX) || !mPrimitiveFields.mPivotExplicitlySet) { |
| 325 |
mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 326 |
mPrimitiveFields.mPivotExplicitlySet = true; |
| 327 |
return true; |
| 328 |
} |
| 329 |
return false; |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
float getPivotX() const { return mPrimitiveFields.mPivotX; } |
| 337 |
|
| 338 |
bool setPivotY(float pivotY) { |
| 339 |
if (RP_SET(mPrimitiveFields.mPivotY, pivotY) || !mPrimitiveFields.mPivotExplicitlySet) { |
| 340 |
mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 341 |
mPrimitiveFields.mPivotExplicitlySet = true; |
| 342 |
return true; |
| 343 |
} |
| 344 |
return false; |
| 345 |
} |
| 346 |
|
| 347 |
float getPivotY() const { return mPrimitiveFields.mPivotY; } |
| 348 |
|
| 349 |
bool isPivotExplicitlySet() const { return mPrimitiveFields.mPivotExplicitlySet; } |
| 350 |
|
| 351 |
bool resetPivot() { return RP_SET_AND_DIRTY(mPrimitiveFields.mPivotExplicitlySet, false); } |
| 352 |
|
| 353 |
bool setCameraDistance(float distance) { |
| 354 |
if (distance != getCameraDistance()) { |
| 355 |
mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 356 |
mComputedFields.mTransformCamera.setCameraLocation(0, 0, distance); |
| 357 |
return true; |
| 358 |
} |
| 359 |
return false; |
| 360 |
} |
| 361 |
|
| 362 |
float getCameraDistance() const { |
| 363 |
|
| 364 |
return const_cast<Sk3DView*>(&mComputedFields.mTransformCamera)->getCameraLocationZ(); |
| 365 |
} |
| 366 |
|
| 367 |
bool setLeft(int left) { |
| 368 |
if (RP_SET(mPrimitiveFields.mLeft, left)) { |
| 369 |
mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
| 370 |
if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 371 |
mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 372 |
} |
| 373 |
return true; |
| 374 |
} |
| 375 |
return false; |
| 376 |
} |
| 377 |
|
| 378 |
int getLeft() const { return mPrimitiveFields.mLeft; } |
| 379 |
|
| 380 |
bool setTop(int top) { |
| 381 |
if (RP_SET(mPrimitiveFields.mTop, top)) { |
| 382 |
mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
| 383 |
if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 384 |
mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 385 |
} |
| 386 |
return true; |
| 387 |
} |
| 388 |
return false; |
| 389 |
} |
| 390 |
|
| 391 |
int getTop() const { return mPrimitiveFields.mTop; } |
| 392 |
|
| 393 |
bool setRight(int right) { |
| 394 |
if (RP_SET(mPrimitiveFields.mRight, right)) { |
| 395 |
mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
| 396 |
if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 397 |
mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 398 |
} |
| 399 |
return true; |
| 400 |
} |
| 401 |
return false; |
| 402 |
} |
| 403 |
|
| 404 |
int getRight() const { return mPrimitiveFields.mRight; } |
| 405 |
|
| 406 |
bool setBottom(int bottom) { |
| 407 |
if (RP_SET(mPrimitiveFields.mBottom, bottom)) { |
| 408 |
mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
| 409 |
if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 410 |
mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 411 |
} |
| 412 |
return true; |
| 413 |
} |
| 414 |
return false; |
| 415 |
} |
| 416 |
|
| 417 |
int getBottom() const { return mPrimitiveFields.mBottom; } |
| 418 |
|
| 419 |
bool setLeftTop(int left, int top) { |
| 420 |
bool leftResult = setLeft(left); |
| 421 |
bool topResult = setTop(top); |
| 422 |
return leftResult || topResult; |
| 423 |
} |
| 424 |
|
| 425 |
bool setLeftTopRightBottom(int left, int top, int right, int bottom) { |
| 426 |
if (left != mPrimitiveFields.mLeft || top != mPrimitiveFields.mTop || |
| 427 |
right != mPrimitiveFields.mRight || bottom != mPrimitiveFields.mBottom) { |
| 428 |
mPrimitiveFields.mLeft = left; |
| 429 |
mPrimitiveFields.mTop = top; |
| 430 |
mPrimitiveFields.mRight = right; |
| 431 |
mPrimitiveFields.mBottom = bottom; |
| 432 |
mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
| 433 |
mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
| 434 |
if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 435 |
mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 436 |
} |
| 437 |
return true; |
| 438 |
} |
| 439 |
return false; |
| 440 |
} |
| 441 |
|
| 442 |
bool offsetLeftRight(int offset) { |
| 443 |
if (offset != 0) { |
| 444 |
mPrimitiveFields.mLeft += offset; |
| 445 |
mPrimitiveFields.mRight += offset; |
| 446 |
return true; |
| 447 |
} |
| 448 |
return false; |
| 449 |
} |
| 450 |
|
| 451 |
bool offsetTopBottom(int offset) { |
| 452 |
if (offset != 0) { |
| 453 |
mPrimitiveFields.mTop += offset; |
| 454 |
mPrimitiveFields.mBottom += offset; |
| 455 |
return true; |
| 456 |
} |
| 457 |
return false; |
| 458 |
} |
| 459 |
|
| 460 |
int getWidth() const { return mPrimitiveFields.mWidth; } |
| 461 |
|
| 462 |
int getHeight() const { return mPrimitiveFields.mHeight; } |
| 463 |
|
| 464 |
const SkMatrix* getAnimationMatrix() const { return mAnimationMatrix; } |
| 465 |
|
| 466 |
bool hasTransformMatrix() const { |
| 467 |
return getTransformMatrix() && !getTransformMatrix()->isIdentity(); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
bool isTransformTranslateOnly() const { |
| 472 |
return getTransformMatrix()->getType() == SkMatrix::kTranslate_Mask; |
| 473 |
} |
| 474 |
|
| 475 |
const SkMatrix* getTransformMatrix() const { |
| 476 |
LOG_ALWAYS_FATAL_IF(mPrimitiveFields.mMatrixOrPivotDirty, "Cannot get a dirty matrix!"); |
| 477 |
return mComputedFields.mTransformMatrix; |
| 478 |
} |
| 479 |
|
| 480 |
int getClippingFlags() const { return mPrimitiveFields.mClippingFlags; } |
| 481 |
|
| 482 |
bool getClipToBounds() const { return mPrimitiveFields.mClippingFlags & CLIP_TO_BOUNDS; } |
| 483 |
|
| 484 |
const Rect& getClipBounds() const { return mPrimitiveFields.mClipBounds; } |
| 485 |
|
| 486 |
void getClippingRectForFlags(uint32_t flags, Rect* outRect) const { |
| 487 |
if (flags & CLIP_TO_BOUNDS) { |
| 488 |
outRect->set(0, 0, getWidth(), getHeight()); |
| 489 |
if (flags & CLIP_TO_CLIP_BOUNDS) { |
| 490 |
outRect->doIntersect(mPrimitiveFields.mClipBounds); |
| 491 |
} |
| 492 |
} else { |
| 493 |
outRect->set(mPrimitiveFields.mClipBounds); |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
bool getHasOverlappingRendering() const { return mPrimitiveFields.mHasOverlappingRendering; } |
| 498 |
|
| 499 |
const Outline& getOutline() const { return mPrimitiveFields.mOutline; } |
| 500 |
|
| 501 |
const RevealClip& getRevealClip() const { return mPrimitiveFields.mRevealClip; } |
| 502 |
|
| 503 |
bool getProjectBackwards() const { return mPrimitiveFields.mProjectBackwards; } |
| 504 |
|
| 505 |
void debugOutputProperties(std::ostream& output, const int level) const; |
| 506 |
|
| 507 |
void updateMatrix(); |
| 508 |
|
| 509 |
Outline& mutableOutline() { return mPrimitiveFields.mOutline; } |
| 510 |
|
| 511 |
RevealClip& mutableRevealClip() { return mPrimitiveFields.mRevealClip; } |
| 512 |
|
| 513 |
const LayerProperties& layerProperties() const { return mLayerProperties; } |
| 514 |
|
| 515 |
LayerProperties& mutateLayerProperties() { return mLayerProperties; } |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
bool getClipDamageToBounds() const { |
| 523 |
return getClipToBounds() && (getZ() <= 0 || getOutline().isEmpty()); |
| 524 |
} |
| 525 |
|
| 526 |
bool hasShadow() const { |
| 527 |
return getZ() > 0.0f && getOutline().getPath() != nullptr && |
| 528 |
getOutline().getAlpha() != 0.0f; |
| 529 |
} |
| 530 |
|
| 531 |
SkColor getSpotShadowColor() const { return mPrimitiveFields.mSpotShadowColor; } |
| 532 |
|
| 533 |
bool setSpotShadowColor(SkColor shadowColor) { |
| 534 |
return RP_SET(mPrimitiveFields.mSpotShadowColor, shadowColor); |
| 535 |
} |
| 536 |
|
| 537 |
SkColor getAmbientShadowColor() const { return mPrimitiveFields.mAmbientShadowColor; } |
| 538 |
|
| 539 |
bool setAmbientShadowColor(SkColor shadowColor) { |
| 540 |
return RP_SET(mPrimitiveFields.mAmbientShadowColor, shadowColor); |
| 541 |
} |
| 542 |
|
| 543 |
bool fitsOnLayer() const { |
| 544 |
#ifdef __ANDROID__ |
| 545 |
const DeviceInfo* deviceInfo = DeviceInfo::get(); |
| 546 |
return mPrimitiveFields.mWidth <= deviceInfo->maxTextureSize() && |
| 547 |
mPrimitiveFields.mHeight <= deviceInfo->maxTextureSize(); |
| 548 |
#else |
| 549 |
return mPrimitiveFields.mWidth <= 4096 && mPrimitiveFields.mHeight <= 4096; |
| 550 |
#endif |
| 551 |
} |
| 552 |
|
| 553 |
bool promotedToLayer() const { |
| 554 |
return mLayerProperties.mType == LayerType::None && fitsOnLayer() && |
| 555 |
(mComputedFields.mNeedLayerForFunctors || mLayerProperties.mImageFilter != nullptr || |
| 556 |
mLayerProperties.getStretchEffect().requiresLayer() || |
| 557 |
(!MathUtils::isZero(mPrimitiveFields.mAlpha) && mPrimitiveFields.mAlpha < 1 && |
| 558 |
mPrimitiveFields.mHasOverlappingRendering)); |
| 559 |
} |
| 560 |
|
| 561 |
LayerType effectiveLayerType() const { |
| 562 |
return CC_UNLIKELY(promotedToLayer()) ? LayerType::RenderLayer : mLayerProperties.mType; |
| 563 |
} |
| 564 |
|
| 565 |
bool setAllowForceDark(bool allow) { |
| 566 |
return RP_SET(mPrimitiveFields.mAllowForceDark, allow); |
| 567 |
} |
| 568 |
|
| 569 |
bool getAllowForceDark() const { |
| 570 |
return mPrimitiveFields.mAllowForceDark; |
| 571 |
} |
| 572 |
|
| 573 |
private: |
| 574 |
|
| 575 |
struct PrimitiveFields { |
| 576 |
int mLeft = 0, mTop = 0, mRight = 0, mBottom = 0; |
| 577 |
int mWidth = 0, mHeight = 0; |
| 578 |
int mClippingFlags = CLIP_TO_BOUNDS; |
| 579 |
SkColor mSpotShadowColor = SK_ColorBLACK; |
| 580 |
SkColor mAmbientShadowColor = SK_ColorBLACK; |
| 581 |
float mAlpha = 1; |
| 582 |
float mTranslationX = 0, mTranslationY = 0, mTranslationZ = 0; |
| 583 |
float mElevation = 0; |
| 584 |
float mRotation = 0, mRotationX = 0, mRotationY = 0; |
| 585 |
float mScaleX = 1, mScaleY = 1; |
| 586 |
float mPivotX = 0, mPivotY = 0; |
| 587 |
bool mHasOverlappingRendering = false; |
| 588 |
bool mPivotExplicitlySet = false; |
| 589 |
bool mMatrixOrPivotDirty = false; |
| 590 |
bool mProjectBackwards = false; |
| 591 |
bool mProjectionReceiver = false; |
| 592 |
bool mAllowForceDark = true; |
| 593 |
bool mClipMayBeComplex = false; |
| 594 |
Rect mClipBounds; |
| 595 |
Outline mOutline; |
| 596 |
RevealClip mRevealClip; |
| 597 |
} mPrimitiveFields; |
| 598 |
|
| 599 |
SkMatrix* mStaticMatrix; |
| 600 |
SkMatrix* mAnimationMatrix; |
| 601 |
LayerProperties mLayerProperties; |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
struct ComputedFields { |
| 607 |
ComputedFields(); |
| 608 |
~ComputedFields(); |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
SkMatrix* mTransformMatrix; |
| 618 |
|
| 619 |
Sk3DView mTransformCamera; |
| 620 |
|
| 621 |
|
| 622 |
bool mNeedLayerForFunctors = false; |
| 623 |
} mComputedFields; |
| 624 |
}; |
| 625 |
|
| 626 |
} |
| 627 |
} |