Flutter Engine
 
Loading...
Searching...
No Matches
raster_cache_util.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_FLOW_RASTER_CACHE_UTIL_H_
6#define FLUTTER_FLOW_RASTER_CACHE_UTIL_H_
7
10#include "include/core/SkM44.h"
11#include "include/core/SkMatrix.h"
12#include "include/core/SkRect.h"
13
14namespace flutter {
15
17 // The default max number of picture and display list raster caches to be
18 // generated per frame. Generating too many caches in one frame may cause jank
19 // on that frame. This limit allows us to throttle the cache and distribute
20 // the work across multiple frames.
22
23 // The ImageFilterLayer might cache the filtered output of this layer
24 // if the layer remains stable (if it is not animating for instance).
25 // If the ImageFilterLayer is not the same between rendered frames,
26 // though, it will cache its children instead and filter their cached
27 // output on the fly.
28 // Caching just the children saves the time to render them and also
29 // avoids a rendering surface switch to draw them.
30 // Caching the layer itself avoids all of that and additionally avoids
31 // the cost of applying the filter, but can be worse than caching the
32 // children if the filter itself is not stable from frame to frame.
33 // This constant controls how many times we will Preroll and Paint this
34 // same ImageFilterLayer before we consider the layer and filter to be
35 // stable enough to switch from caching the children to caching the
36 // filtered output of this layer.
38
39 static bool CanRasterizeRect(const SkRect& cull_rect) {
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 }
53
54 static SkRect GetDeviceBounds(const SkRect& rect, const SkMatrix& ctm) {
55 SkRect device_rect;
56 ctm.mapRect(&device_rect, rect);
57 return device_rect;
58 }
59
60 static SkRect GetRoundedOutDeviceBounds(const SkRect& rect,
61 const SkMatrix& ctm) {
62 SkRect device_rect;
63 ctm.mapRect(&device_rect, rect);
64 device_rect.roundOut(&device_rect);
65 return device_rect;
66 }
67
68 /**
69 * @brief Snap the translation components of the matrix to integers.
70 *
71 * The snapping will only happen if the matrix only has scale and translation
72 * transformations. This is used, along with GetRoundedOutDeviceBounds, to
73 * ensure that the textures drawn by the raster cache are exactly aligned to
74 * physical pixels. Any layers that participate in raster caching must align
75 * themselves to physical pixels even when not cached to prevent a change in
76 * apparent location if caching is later applied.
77 *
78 * @param ctm the current transformation matrix.
79 * @return SkMatrix the snapped transformation matrix.
80 */
81 static SkMatrix GetIntegralTransCTM(const SkMatrix& ctm) {
82 SkMatrix integral;
83 return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm;
84 }
85
86 /**
87 * @brief Snap the translation components of the matrix to integers.
88 *
89 * The snapping will only happen if the matrix only has scale and translation
90 * transformations. This is used, along with GetRoundedOutDeviceBounds, to
91 * ensure that the textures drawn by the raster cache are exactly aligned to
92 * physical pixels. Any layers that participate in raster caching must align
93 * themselves to physical pixels even when not cached to prevent a change in
94 * apparent location if caching is later applied.
95 *
96 * @param ctm the current transformation matrix.
97 * @return SkMatrix the snapped transformation matrix.
98 */
100 DlMatrix integral;
101 return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm;
102 }
103
104 /**
105 * @brief Snap the translation components of the |in| matrix to integers
106 * and store the snapped matrix in |out|.
107 *
108 * The snapping will only happen if the matrix only has scale and translation
109 * transformations. This is used, along with GetRoundedOutDeviceBounds, to
110 * ensure that the textures drawn by the raster cache are exactly aligned to
111 * physical pixels. Any layers that participate in raster caching must align
112 * themselves to physical pixels even when not cached to prevent a change in
113 * apparent location if caching is later applied.
114 *
115 * The |out| matrix will not be modified if this method returns false.
116 *
117 * @param in the current transformation matrix.
118 * @param out the storage for the snapped matrix.
119 * @return true if the integral modification was needed, false otherwise.
120 */
121 static bool ComputeIntegralTransCTM(const SkMatrix& in, SkMatrix* out);
122
123 /**
124 * @brief Snap the translation components of the matrix to integers.
125 *
126 * The snapping will only happen if the matrix only has scale and translation
127 * transformations. This is used, along with GetRoundedOutDeviceBounds, to
128 * ensure that the textures drawn by the raster cache are exactly aligned to
129 * physical pixels. Any layers that participate in raster caching must align
130 * themselves to physical pixels even when not cached to prevent a change in
131 * apparent location if caching is later applied.
132 *
133 * @param ctm the current transformation matrix.
134 * @return SkM44 the snapped transformation matrix.
135 */
136 static SkM44 GetIntegralTransCTM(const SkM44& ctm) {
137 SkM44 integral;
138 return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm;
139 }
140
141 /**
142 * @brief Snap the translation components of the |in| matrix to integers
143 * and store the snapped matrix in |out|.
144 *
145 * The snapping will only happen if the matrix only has scale and translation
146 * transformations. This is used, along with GetRoundedOutDeviceBounds, to
147 * ensure that the textures drawn by the raster cache are exactly aligned to
148 * physical pixels. Any layers that participate in raster caching must align
149 * themselves to physical pixels even when not cached to prevent a change in
150 * apparent location if caching is later applied.
151 *
152 * The |out| matrix will not be modified if this method returns false.
153 *
154 * @param in the current transformation matrix.
155 * @param out the storage for the snapped matrix.
156 * @return true if the integral modification was needed, false otherwise.
157 */
158 static bool ComputeIntegralTransCTM(const SkM44& in, SkM44* out);
159
160 /**
161 * @brief Snap the translation components of the |in| matrix to integers
162 * and store the snapped matrix in |out|.
163 *
164 * The snapping will only happen if the matrix only has scale and translation
165 * transformations. This is used, along with GetRoundedOutDeviceBounds, to
166 * ensure that the textures drawn by the raster cache are exactly aligned to
167 * physical pixels. Any layers that participate in raster caching must align
168 * themselves to physical pixels even when not cached to prevent a change in
169 * apparent location if caching is later applied.
170 *
171 * The |out| matrix will not be modified if this method returns false.
172 *
173 * @param in the current transformation matrix.
174 * @param out the storage for the snapped matrix.
175 * @return true if the integral modification was needed, false otherwise.
176 */
177 static bool ComputeIntegralTransCTM(const DlMatrix& in, DlMatrix* out);
178};
179
180} // namespace flutter
181
182#endif // FLUTTER_FLOW_RASTER_CACHE_UTIL_H_
#define FML_LOG(severity)
Definition logging.h:101
static bool CanRasterizeRect(const SkRect &cull_rect)
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 SkMatrix GetIntegralTransCTM(const SkMatrix &ctm)
Snap the translation components of the matrix to integers.
static SkRect GetRoundedOutDeviceBounds(const SkRect &rect, const SkMatrix &ctm)
static constexpr int kDefaultPictureAndDisplayListCacheLimitPerFrame
static constexpr int kMinimumRendersBeforeCachingFilterLayer
static SkM44 GetIntegralTransCTM(const SkM44 &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 SkRect GetDeviceBounds(const SkRect &rect, const SkMatrix &ctm)
A 4x4 matrix using column-major storage.
Definition matrix.h:37