Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkCanvasPriv.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkCanvasPriv_DEFINED
9#define SkCanvasPriv_DEFINED
10
16
17#include <cstddef>
18
19class SkDevice;
20class SkImageFilter;
21class SkMatrix;
22class SkReadBuffer;
23struct SkRect;
24class SkWriteBuffer;
25
26#if defined(GRAPHITE_TEST_UTILS)
27namespace skgpu::graphite {
28 class TextureProxy;
29}
30#endif
31
33public:
34 SkAutoCanvasMatrixPaint(SkCanvas*, const SkMatrix*, const SkPaint*, const SkRect& bounds);
36
37private:
38 SkCanvas* fCanvas;
39 int fSaveCount;
40};
41
43public:
44 // The lattice has pointers directly into the readbuffer
46
47 static void WriteLattice(SkWriteBuffer&, const SkCanvas::Lattice&);
48
49 // return the byte-size of the lattice, even if the buffer is null
50 // storage must be 4-byte aligned
51 static size_t WriteLattice(void* storage, const SkCanvas::Lattice&);
52
53 static int SaveBehind(SkCanvas* canvas, const SkRect* subset) {
54 return canvas->only_axis_aligned_saveBehind(subset);
55 }
56 static void DrawBehind(SkCanvas* canvas, const SkPaint& paint) {
57 canvas->drawClippedToSaveBehind(paint);
58 }
59
60 // Exposed for testing on non-Android framework builds
61 static void ResetClip(SkCanvas* canvas) {
62 canvas->internal_private_resetClip();
63 }
64
65 static SkDevice* TopDevice(const SkCanvas* canvas) {
66 return canvas->topDevice();
67 }
68
69 // The experimental_DrawEdgeAAImageSet API accepts separate dstClips and preViewMatrices arrays,
70 // where entries refer into them, but no explicit size is provided. Given a set of entries,
71 // computes the minimum length for these arrays that would provide index access errors.
72 static void GetDstClipAndMatrixCounts(const SkCanvas::ImageSetEntry set[], int count,
73 int* totalDstClipCount, int* totalMatrixCount);
74
76 const SkPaint* paint,
77 const SkImageFilter* backdrop,
78 SkScalar backdropScale,
79 SkCanvas::SaveLayerFlags saveLayerFlags,
80 SkCanvas::FilterSpan filters = {}) {
82 bounds, paint, backdrop, nullptr, backdropScale, saveLayerFlags, filters);
83 }
84
86 return rec.fExperimentalBackdropScale;
87 }
88
90 rec->fExperimentalBackdropScale = scale;
91 }
92
93 // Attempts to convert an image filter to its equivalent color filter, which if possible,
94 // modifies the paint to compose the image filter's color filter into the paint's color filter
95 // slot.
96 // Returns true if the paint has been modified.
97 // Requires the paint to have an image filter and the copy-on-write be initialized.
98 static bool ImageToColorFilter(SkPaint*);
99};
100
101/**
102 * This constant is trying to balance the speed of ref'ing a subpicture into a parent picture,
103 * against the playback cost of recursing into the subpicture to get at its actual ops.
104 *
105 * For now we pick a conservatively small value, though measurement (and other heuristics like
106 * the type of ops contained) may justify changing this value.
107 */
109
110/**
111 * We implement ImageFilters and MaskFilters for a given draw by creating a layer, then applying
112 * the filter to the pixels of that layer (its backing surface/image), and then we call restore()
113 * to blend that layer to the main canvas.
114 *
115 * If the paint has neither an image filter nor a mask filter, there will be no layer and paint()
116 * returns the original without modification.
117 *
118 * NOTE: This works by assuming all sources of color and shading are represented by the SkPaint.
119 * Operations like drawImageRect must convert to an equivalent drawRect call if there's a mask
120 * filter, or otherwise ensure there are no mask filters (e.g. drawAtlas).
121 */
123public:
124 // `rawBounds` is the original bounds of the primitive about to be drawn, unmodified by the
125 // paint. It's used to determine the size of the offscreen layer for filters.
126 // If null, the clip will be used instead.
127 //
128 // If `skipMaskFilterLayer` is true, any SkMaskFilter on `paint` will be left as-is and is
129 // assumed to be handled by the SkDevice that handles the draw.
130 //
131 // Draw functions should use layer->paint() instead of the passed-in paint.
133 const SkPaint& paint,
134 const SkRect* rawBounds,
135 bool skipMaskFilterLayer);
136
141
143
144 const SkPaint& paint() const { return fPaint; }
145
146 // This is public so that a canvas can attempt to specially handle mask filters, specifically
147 // for blurs, and then if the attempt fails fall back on a regular draw with the same autolayer.
148 void addMaskFilterLayer(const SkRect* drawBounds);
149
150private:
151 void addImageFilterLayer(const SkRect* drawBounds);
152
153 void addLayer(const SkPaint& restorePaint, const SkRect* drawBounds, bool coverageOnly);
154
155 SkPaint fPaint;
156 SkCanvas* fCanvas;
157 int fTempLayersForFilters;
158
159 SkDEBUGCODE(int fSaveCount;)
160};
161
162#endif
int count
constexpr int kMaxPictureOpsToUnrollInsteadOfRef
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
void addMaskFilterLayer(const SkRect *drawBounds)
const SkPaint & paint() const
AutoLayerForImageFilter(const AutoLayerForImageFilter &)=delete
AutoLayerForImageFilter & operator=(const AutoLayerForImageFilter &)=delete
static SkDevice * TopDevice(const SkCanvas *canvas)
static void WriteLattice(SkWriteBuffer &, const SkCanvas::Lattice &)
static SkCanvas::SaveLayerRec ScaledBackdropLayer(const SkRect *bounds, const SkPaint *paint, const SkImageFilter *backdrop, SkScalar backdropScale, SkCanvas::SaveLayerFlags saveLayerFlags, SkCanvas::FilterSpan filters={})
static void ResetClip(SkCanvas *canvas)
static void DrawBehind(SkCanvas *canvas, const SkPaint &paint)
static void SetBackdropScaleFactor(SkCanvas::SaveLayerRec *rec, SkScalar scale)
static bool ReadLattice(SkReadBuffer &, SkCanvas::Lattice *)
static bool ImageToColorFilter(SkPaint *)
static SkScalar GetBackdropScaleFactor(const SkCanvas::SaveLayerRec &rec)
static int SaveBehind(SkCanvas *canvas, const SkRect *subset)
static void GetDstClipAndMatrixCounts(const SkCanvas::ImageSetEntry set[], int count, int *totalDstClipCount, int *totalMatrixCount)
uint32_t SaveLayerFlags
Definition SkCanvas.h:677
const Paint & paint
float SkScalar
Definition extension.cpp:12
const Scalar scale