Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
SkRecordOpts.cpp File Reference
#include "src/core/SkRecordOpts.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRefCnt.h"
#include "include/private/base/SkMath.h"
#include "include/private/base/SkTemplates.h"
#include "src/core/SkRecord.h"
#include "src/core/SkRecordPattern.h"
#include "src/core/SkRecords.h"
#include <cstdint>
#include <optional>

Go to the source code of this file.

Classes

struct  SaveOnlyDrawsRestoreNooper
 
struct  SaveNoDrawsRestoreNooper
 
struct  SaveLayerDrawRestoreNooper
 
struct  SvgOpacityAndFilterLayerMergePass
 

Functions

template<typename Pass >
static bool apply (Pass *pass, SkRecord *record)
 
static bool fold_opacity_layer_color_to_paint (const SkPaint *layerPaint, bool isSaveLayer, SkPaint *paint)
 
void SkRecordNoopSaveRestores (SkRecord *record)
 
static bool effectively_srcover (const SkPaint *paint)
 
void SkRecordNoopSaveLayerDrawRestores (SkRecord *record)
 
void SkRecordMergeSvgOpacityAndFilterLayers (SkRecord *record)
 
void SkRecordOptimize (SkRecord *record)
 

Function Documentation

◆ apply()

template<typename Pass >
static bool apply ( Pass *  pass,
SkRecord record 
)
static

Definition at line 35 of file SkRecordOpts.cpp.

35 {
36 typename Pass::Match match;
37 bool changed = false;
38 int begin, end = 0;
39
40 while (match.search(record, &begin, &end)) {
41 changed |= pass->onMatch(record, &match, begin, end);
42 }
43 return changed;
44}
static bool match(const char *needle, const char *haystack)
Definition DM.cpp:1132
static const char * begin(const StringSlice &s)
Definition editor.cpp:252
glong glong end

◆ effectively_srcover()

static bool effectively_srcover ( const SkPaint paint)
static

Definition at line 145 of file SkRecordOpts.cpp.

145 {
146 if (!paint || paint->isSrcOver()) {
147 return true;
148 }
149 // src-mode with opaque and no effects (which might change opaqueness) is ok too.
150 return !paint->getShader() && !paint->getColorFilter() && !paint->getImageFilter() &&
151 0xFF == paint->getAlpha() && paint->asBlendMode() == SkBlendMode::kSrc;
152}
Optional< SkPaint > paint
Definition SkRecords.h:190

◆ fold_opacity_layer_color_to_paint()

static bool fold_opacity_layer_color_to_paint ( const SkPaint layerPaint,
bool  isSaveLayer,
SkPaint paint 
)
static

Definition at line 62 of file SkRecordOpts.cpp.

64 {
65 // We assume layerPaint is always from a saveLayer. If isSaveLayer is
66 // true, we assume paint is too.
67
68 // The alpha folding can proceed if the filter layer paint does not have properties which cause
69 // the resulting filter layer to be "blended" in complex ways to the parent layer.
70 // TODO: most likely only some xfer modes are the hard constraints
71 if (!paint->isSrcOver()) {
72 return false;
73 }
74
75 if (!isSaveLayer && paint->getImageFilter()) {
76 // For normal draws, the paint color is used as one input for the color for the draw. Image
77 // filter will operate on the result, and thus we can not change the input.
78 // For layer saves, the image filter is applied to the layer contents. The layer is then
79 // modulated with the paint color, so it's fine to proceed with the fold for saveLayer
80 // paints with image filters.
81 return false;
82 }
83
84 if (paint->getColorFilter()) {
85 // Filter input depends on the paint color.
86
87 // Here we could filter the color if we knew the draw is going to be uniform color. This
88 // should be detectable as drawPath/drawRect/.. without a shader being uniform, while
89 // drawBitmap/drawSprite or a shader being non-uniform. However, current matchers don't
90 // give the type out easily, so just do not optimize that at the moment.
91 return false;
92 }
93
94 if (layerPaint) {
95 const uint32_t layerColor = layerPaint->getColor();
96 // The layer paint color must have only alpha component.
98 return false;
99 }
100
101 // The layer paint can not have any effects.
102 if (layerPaint->getPathEffect() ||
103 layerPaint->getShader() ||
104 !layerPaint->isSrcOver() ||
105 layerPaint->getMaskFilter() ||
106 layerPaint->getColorFilter() ||
107 layerPaint->getImageFilter()) {
108 return false;
109 }
110 paint->setAlpha(SkMulDiv255Round(paint->getAlpha(), SkColorGetA(layerColor)));
111 }
112
113 return true;
114}
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
static constexpr SkColor SkColorSetA(SkColor c, U8CPU a)
Definition SkColor.h:82
#define SkColorGetA(color)
Definition SkColor.h:61
constexpr SkAlpha SK_AlphaTRANSPARENT
Definition SkColor.h:89
static U8CPU SkMulDiv255Round(U16CPU a, U16CPU b)
Definition SkMath.h:73
SkPathEffect * getPathEffect() const
Definition SkPaint.h:506
bool isSrcOver() const
Definition SkPaint.cpp:147
SkColor getColor() const
Definition SkPaint.h:225
SkColorFilter * getColorFilter() const
Definition SkPaint.h:426
SkMaskFilter * getMaskFilter() const
Definition SkPaint.h:534
SkImageFilter * getImageFilter() const
Definition SkPaint.h:564
SkShader * getShader() const
Definition SkPaint.h:397

◆ SkRecordMergeSvgOpacityAndFilterLayers()

void SkRecordMergeSvgOpacityAndFilterLayers ( SkRecord record)

Definition at line 262 of file SkRecordOpts.cpp.

262 {
264 apply(&pass, record);
265}
static bool apply(Pass *pass, SkRecord *record)

◆ SkRecordNoopSaveLayerDrawRestores()

void SkRecordNoopSaveLayerDrawRestores ( SkRecord record)

Definition at line 201 of file SkRecordOpts.cpp.

201 {
203 apply(&pass, record);
204}

◆ SkRecordNoopSaveRestores()

void SkRecordNoopSaveRestores ( SkRecord record)

Definition at line 136 of file SkRecordOpts.cpp.

136 {
139
140 // Run until they stop changing things.
141 while (apply(&onlyDraws, record) || apply(&noDraws, record));
142}

◆ SkRecordOptimize()

void SkRecordOptimize ( SkRecord record)

Definition at line 269 of file SkRecordOpts.cpp.

269 {
270 // This might be useful as a first pass in the future if we want to weed
271 // out junk for other optimization passes. Right now, nothing needs it,
272 // and the bounding box hierarchy will do the work of skipping no-op
273 // Save-NoDraw-Restore sequences better than we can here.
274 // As there is a known problem with this peephole and drawAnnotation, disable this.
275 // If we want to enable this we must first fix this bug:
276 // https://bugs.chromium.org/p/skia/issues/detail?id=5548
277// SkRecordNoopSaveRestores(record);
278
279 // Turn off this optimization completely for Android framework
280 // because it makes the following Android CTS test fail:
281 // android.uirendering.cts.testclasses.LayerTests#testSaveLayerClippedWithAlpha
282#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
284#endif
286
287 record->defrag();
288}
void SkRecordMergeSvgOpacityAndFilterLayers(SkRecord *record)
void SkRecordNoopSaveLayerDrawRestores(SkRecord *record)
void defrag()
Definition SkRecord.cpp:30