Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
flutter::RasterCacheUtil Struct Reference

#include <raster_cache_util.h>

Static Public Member Functions

static bool CanRasterizeRect (const SkRect &cull_rect)
 
static SkRect GetDeviceBounds (const SkRect &rect, const SkMatrix &ctm)
 
static SkRect GetRoundedOutDeviceBounds (const SkRect &rect, const SkMatrix &ctm)
 
static SkMatrix GetIntegralTransCTM (const SkMatrix &ctm)
 Snap the translation components of the matrix to integers.
 
static bool ComputeIntegralTransCTM (const SkMatrix &in, SkMatrix *out)
 Snap the translation components of the |in| matrix to integers and store the snapped matrix in |out|.
 
static SkM44 GetIntegralTransCTM (const SkM44 &ctm)
 Snap the translation components of the matrix to integers.
 
static bool ComputeIntegralTransCTM (const SkM44 &in, SkM44 *out)
 Snap the translation components of the |in| matrix to integers and store the snapped matrix in |out|.
 

Static Public Attributes

static constexpr int kDefaultPictureAndDisplayListCacheLimitPerFrame = 3
 
static constexpr int kMinimumRendersBeforeCachingFilterLayer = 3
 

Detailed Description

Definition at line 15 of file raster_cache_util.h.

Member Function Documentation

◆ CanRasterizeRect()

static bool flutter::RasterCacheUtil::CanRasterizeRect ( const SkRect cull_rect)
inlinestatic

Definition at line 38 of file raster_cache_util.h.

38 {
39 if (cull_rect.isEmpty()) {
40 // No point in ever rasterizing an empty display list.
41 return false;
42 }
43
44 if (!cull_rect.isFinite()) {
45 // Cannot attempt to rasterize into an infinitely large surface.
46 FML_LOG(INFO) << "Attempted to raster cache non-finite display list";
47 return false;
48 }
49
50 return true;
51 }
#define FML_LOG(severity)
Definition logging.h:82
bool isFinite() const
Definition SkRect.h:711
bool isEmpty() const
Definition SkRect.h:693

◆ ComputeIntegralTransCTM() [1/2]

bool flutter::RasterCacheUtil::ComputeIntegralTransCTM ( const SkM44 in,
SkM44 out 
)
static

Snap the translation components of the |in| matrix to integers and store the snapped matrix in |out|.

The snapping will only happen if the matrix only has scale and translation transformations. This is used, along with GetRoundedOutDeviceBounds, to ensure that the textures drawn by the raster cache are exactly aligned to physical pixels. Any layers that participate in raster caching must align themselves to physical pixels even when not cached to prevent a change in apparent location if caching is later applied.

The |out| matrix will not be modified if this method returns false.

Parameters
inthe current transformation matrix.
outthe storage for the snapped matrix.
Returns
true if the integral modification was needed, false otherwise.

Definition at line 33 of file raster_cache_util.cc.

33 {
34 // Avoid integral snapping if the matrix has complex transformation to avoid
35 // the artifact observed in https://github.com/flutter/flutter/issues/41654.
36 if (in.rc(0, 1) != 0 || in.rc(0, 2) != 0) {
37 // X multiplied by either Y or Z
38 return false;
39 }
40 if (in.rc(1, 0) != 0 || in.rc(1, 2) != 0) {
41 // Y multiplied by either X or Z
42 return false;
43 }
44 if (in.rc(3, 0) != 0 || in.rc(3, 1) != 0 || in.rc(3, 2) != 0 ||
45 in.rc(3, 3) != 1) {
46 // W not identity row, therefore perspective is applied
47 return false;
48 }
49 // We do not need to worry about the Z row unless the W row
50 // has perspective entries, which we've just eliminated...
51
52 SkScalar in_tx = in.rc(0, 3);
53 SkScalar in_ty = in.rc(1, 3);
54 SkScalar out_tx = SkScalarRoundToScalar(in_tx);
55 SkScalar out_ty = SkScalarRoundToScalar(in_ty);
56 if (out_tx != in_tx || out_ty != in_ty) {
57 // As a side effect of those tests we also know that neither translation
58 // component was a NaN
59 *out = in;
60 out->setRC(0, 3, out_tx);
61 out->setRC(1, 3, out_ty);
62 // No need to worry about Z translation because it has no effect
63 // without perspective entries...
64 return true;
65 }
66
67 return false;
68}
#define SkScalarRoundToScalar(x)
Definition SkScalar.h:32
SkScalar rc(int r, int c) const
Definition SkM44.h:261
float SkScalar
Definition extension.cpp:12

◆ ComputeIntegralTransCTM() [2/2]

bool flutter::RasterCacheUtil::ComputeIntegralTransCTM ( const SkMatrix in,
SkMatrix out 
)
static

Snap the translation components of the |in| matrix to integers and store the snapped matrix in |out|.

The snapping will only happen if the matrix only has scale and translation transformations. This is used, along with GetRoundedOutDeviceBounds, to ensure that the textures drawn by the raster cache are exactly aligned to physical pixels. Any layers that participate in raster caching must align themselves to physical pixels even when not cached to prevent a change in apparent location if caching is later applied.

The |out| matrix will not be modified if this method returns false.

Parameters
inthe current transformation matrix.
outthe storage for the snapped matrix.
Returns
true if the integral modification was needed, false otherwise.

Definition at line 9 of file raster_cache_util.cc.

10 {
11 // Avoid integral snapping if the matrix has complex transformation to avoid
12 // the artifact observed in https://github.com/flutter/flutter/issues/41654.
13 if (!in.isScaleTranslate()) {
14 return false;
15 }
16
17 SkScalar in_tx = in.getTranslateX();
18 SkScalar in_ty = in.getTranslateY();
19 SkScalar out_tx = SkScalarRoundToScalar(in_tx);
20 SkScalar out_ty = SkScalarRoundToScalar(in_ty);
21 if (out_tx != in_tx || out_ty != in_ty) {
22 // As a side effect of those tests we also know that neither translation
23 // component was a NaN
24 *out = in;
25 (*out)[SkMatrix::kMTransX] = out_tx;
26 (*out)[SkMatrix::kMTransY] = out_ty;
27 return true;
28 }
29
30 return false;
31}
static constexpr int kMTransY
vertical translation
Definition SkMatrix.h:358
SkScalar getTranslateY() const
Definition SkMatrix.h:452
bool isScaleTranslate() const
Definition SkMatrix.h:236
static constexpr int kMTransX
horizontal translation
Definition SkMatrix.h:355
SkScalar getTranslateX() const
Definition SkMatrix.h:445

◆ GetDeviceBounds()

static SkRect flutter::RasterCacheUtil::GetDeviceBounds ( const SkRect rect,
const SkMatrix ctm 
)
inlinestatic

Definition at line 53 of file raster_cache_util.h.

53 {
54 SkRect device_rect;
55 ctm.mapRect(&device_rect, rect);
56 return device_rect;
57 }
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const

◆ GetIntegralTransCTM() [1/2]

static SkM44 flutter::RasterCacheUtil::GetIntegralTransCTM ( const SkM44 ctm)
inlinestatic

Snap the translation components of the matrix to integers.

The snapping will only happen if the matrix only has scale and translation transformations. This is used, along with GetRoundedOutDeviceBounds, to ensure that the textures drawn by the raster cache are exactly aligned to physical pixels. Any layers that participate in raster caching must align themselves to physical pixels even when not cached to prevent a change in apparent location if caching is later applied.

Parameters
ctmthe current transformation matrix.
Returns
SkM44 the snapped transformation matrix.

Definition at line 117 of file raster_cache_util.h.

117 {
118 SkM44 integral;
119 return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm;
120 }
Definition SkM44.h:150
static bool ComputeIntegralTransCTM(const SkMatrix &in, SkMatrix *out)
Snap the translation components of the |in| matrix to integers and store the snapped matrix in |out|.

◆ GetIntegralTransCTM() [2/2]

static SkMatrix flutter::RasterCacheUtil::GetIntegralTransCTM ( const SkMatrix ctm)
inlinestatic

Snap the translation components of the matrix to integers.

The snapping will only happen if the matrix only has scale and translation transformations. This is used, along with GetRoundedOutDeviceBounds, to ensure that the textures drawn by the raster cache are exactly aligned to physical pixels. Any layers that participate in raster caching must align themselves to physical pixels even when not cached to prevent a change in apparent location if caching is later applied.

Parameters
ctmthe current transformation matrix.
Returns
SkMatrix the snapped transformation matrix.

Definition at line 80 of file raster_cache_util.h.

80 {
81 SkMatrix integral;
82 return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm;
83 }

◆ GetRoundedOutDeviceBounds()

static SkRect flutter::RasterCacheUtil::GetRoundedOutDeviceBounds ( const SkRect rect,
const SkMatrix ctm 
)
inlinestatic

Definition at line 59 of file raster_cache_util.h.

60 {
61 SkRect device_rect;
62 ctm.mapRect(&device_rect, rect);
63 device_rect.roundOut(&device_rect);
64 return device_rect;
65 }
void roundOut(SkIRect *dst) const
Definition SkRect.h:1241

Member Data Documentation

◆ kDefaultPictureAndDisplayListCacheLimitPerFrame

constexpr int flutter::RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame = 3
staticconstexpr

Definition at line 20 of file raster_cache_util.h.

◆ kMinimumRendersBeforeCachingFilterLayer

constexpr int flutter::RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer = 3
staticconstexpr

Definition at line 36 of file raster_cache_util.h.


The documentation for this struct was generated from the following files: