Flutter Engine
 
Loading...
Searching...
No Matches
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 DlMatrix GetIntegralTransCTM (const DlMatrix &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 bool ComputeIntegralTransCTM (const DlMatrix &in, DlMatrix *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 16 of file raster_cache_util.h.

Member Function Documentation

◆ CanRasterizeRect()

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

Definition at line 39 of file raster_cache_util.h.

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

References FML_LOG.

Referenced by flutter::IsDisplayListWorthRasterizing().

◆ ComputeIntegralTransCTM() [1/3]

bool flutter::RasterCacheUtil::ComputeIntegralTransCTM ( const DlMatrix in,
DlMatrix 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 70 of file raster_cache_util.cc.

71 {
72 // Avoid integral snapping if the matrix has complex transformation to avoid
73 // the artifact observed in https://github.com/flutter/flutter/issues/41654.
74 if (!in.IsTranslationScaleOnly()) {
75 return false;
76 }
77
78 DlScalar in_tx = in.m[12];
79 DlScalar in_ty = in.m[13];
80 DlScalar out_tx = std::round(in_tx);
81 DlScalar out_ty = std::round(in_ty);
82 if (out_tx != in_tx || out_ty != in_ty) {
83 // As a side effect of those tests we also know that neither translation
84 // component was a NaN
85 *out = in;
86 out->m[12] = out_tx;
87 out->m[13] = out_ty;
88 // No need to worry about Z translation because it has no effect
89 // without perspective entries...
90 return true;
91 }
92
93 return false;
94}
impeller::Scalar DlScalar

References impeller::Matrix::IsTranslationScaleOnly(), and impeller::Matrix::m.

◆ ComputeIntegralTransCTM() [2/3]

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}

◆ ComputeIntegralTransCTM() [3/3]

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}

Referenced by GetIntegralTransCTM(), GetIntegralTransCTM(), GetIntegralTransCTM(), flutter::DlCanvasDelegate::integralTransform(), flutter::PrerollDelegate::integralTransform(), flutter::testing::TEST(), and flutter::testing::TEST().

◆ GetDeviceBounds()

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

Definition at line 54 of file raster_cache_util.h.

54 {
55 SkRect device_rect;
56 ctm.mapRect(&device_rect, rect);
57 return device_rect;
58 }

Referenced by flutter::testing::TEST().

◆ GetIntegralTransCTM() [1/3]

static DlMatrix flutter::RasterCacheUtil::GetIntegralTransCTM ( const DlMatrix 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 99 of file raster_cache_util.h.

99 {
100 DlMatrix integral;
101 return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm;
102 }
impeller::Matrix DlMatrix
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|.

References ComputeIntegralTransCTM().

◆ GetIntegralTransCTM() [2/3]

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 136 of file raster_cache_util.h.

136 {
137 SkM44 integral;
138 return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm;
139 }

References ComputeIntegralTransCTM().

◆ GetIntegralTransCTM() [3/3]

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 81 of file raster_cache_util.h.

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

References ComputeIntegralTransCTM().

Referenced by flutter::RasterCacheResult::draw(), flutter::RasterCache::Rasterize(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST_F().

◆ GetRoundedOutDeviceBounds()

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

Definition at line 60 of file raster_cache_util.h.

61 {
62 SkRect device_rect;
63 ctm.mapRect(&device_rect, rect);
64 device_rect.roundOut(&device_rect);
65 return device_rect;
66 }

Referenced by flutter::RasterCacheResult::draw(), and flutter::RasterCache::Rasterize().

Member Data Documentation

◆ kDefaultPictureAndDisplayListCacheLimitPerFrame

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

Definition at line 21 of file raster_cache_util.h.

Referenced by flutter::testing::TEST_F().

◆ kMinimumRendersBeforeCachingFilterLayer

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

Definition at line 37 of file raster_cache_util.h.


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