Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
SkSVGRenderContext Class Reference

#include <SkSVGRenderContext.h>

Classes

class  BorrowedNode
 
struct  OBBScope
 
struct  OBBTransform
 

Public Types

enum  ApplyFlags { kLeaf = 1 << 0 }
 

Public Member Functions

 SkSVGRenderContext (SkCanvas *, const sk_sp< SkFontMgr > &, const sk_sp< skresources::ResourceProvider > &, const SkSVGIDMapper &, const SkSVGLengthContext &, const SkSVGPresentationContext &, const OBBScope &, const sk_sp< SkShapers::Factory > &)
 
 SkSVGRenderContext (const SkSVGRenderContext &)
 
 SkSVGRenderContext (const SkSVGRenderContext &, SkCanvas *)
 
 SkSVGRenderContext (const SkSVGRenderContext &, const SkSVGNode *)
 
 ~SkSVGRenderContext ()
 
const SkSVGLengthContextlengthContext () const
 
SkSVGLengthContextwritableLengthContext ()
 
const SkSVGPresentationContextpresentationContext () const
 
SkCanvascanvas () const
 
void saveOnce ()
 
void applyPresentationAttributes (const SkSVGPresentationAttributes &, uint32_t flags)
 
BorrowedNode findNodeById (const SkSVGIRI &) const
 
SkTLazy< SkPaintfillPaint () const
 
SkTLazy< SkPaintstrokePaint () const
 
SkSVGColorType resolveSvgColor (const SkSVGColor &) const
 
const SkPathclipPath () const
 
const sk_sp< skresources::ResourceProvider > & resourceProvider () const
 
sk_sp< SkFontMgrfontMgr () const
 
OBBTransform transformForCurrentOBB (SkSVGObjectBoundingBoxUnits) const
 
SkRect resolveOBBRect (const SkSVGLength &x, const SkSVGLength &y, const SkSVGLength &w, const SkSVGLength &h, SkSVGObjectBoundingBoxUnits) const
 
std::unique_ptr< SkShapermakeShaper () const
 
std::unique_ptr< SkShaper::BiDiRunIteratormakeBidiRunIterator (const char *utf8, size_t utf8Bytes, uint8_t bidiLevel) const
 
std::unique_ptr< SkShaper::ScriptRunIteratormakeScriptRunIterator (const char *utf8, size_t utf8Bytes) const
 

Detailed Description

Definition at line 63 of file SkSVGRenderContext.h.

Member Enumeration Documentation

◆ ApplyFlags

Enumerator
kLeaf 

Definition at line 93 of file SkSVGRenderContext.h.

93 {
94 kLeaf = 1 << 0, // the target node doesn't have descendants
95 };

Constructor & Destructor Documentation

◆ SkSVGRenderContext() [1/4]

SkSVGRenderContext::SkSVGRenderContext ( SkCanvas canvas,
const sk_sp< SkFontMgr > &  fmgr,
const sk_sp< skresources::ResourceProvider > &  rp,
const SkSVGIDMapper mapper,
const SkSVGLengthContext lctx,
const SkSVGPresentationContext pctx,
const OBBScope obbs,
const sk_sp< SkShapers::Factory > &  fact 
)

Definition at line 149 of file SkSVGRenderContext.cpp.

157 : fFontMgr(fmgr)
158 , fTextShapingFactory(fact)
159 , fResourceProvider(rp)
160 , fIDMapper(mapper)
161 , fLengthContext(lctx)
162 , fPresentationContext(pctx)
163 , fCanvas(canvas)
164 , fCanvasSaveCount(canvas->getSaveCount())
165 , fOBBScope(obbs) {}
int getSaveCount() const
Definition SkCanvas.cpp:435
SkCanvas * canvas() const

◆ SkSVGRenderContext() [2/4]

SkSVGRenderContext::SkSVGRenderContext ( const SkSVGRenderContext other)

Definition at line 167 of file SkSVGRenderContext.cpp.

168 : SkSVGRenderContext(other.fCanvas,
169 other.fFontMgr,
170 other.fResourceProvider,
171 other.fIDMapper,
172 *other.fLengthContext,
173 *other.fPresentationContext,
174 other.fOBBScope,
175 other.fTextShapingFactory) {}

◆ SkSVGRenderContext() [3/4]

SkSVGRenderContext::SkSVGRenderContext ( const SkSVGRenderContext other,
SkCanvas canvas 
)

Definition at line 177 of file SkSVGRenderContext.cpp.

179 other.fFontMgr,
180 other.fResourceProvider,
181 other.fIDMapper,
182 *other.fLengthContext,
183 *other.fPresentationContext,
184 other.fOBBScope,
185 other.fTextShapingFactory) {}

◆ SkSVGRenderContext() [4/4]

SkSVGRenderContext::SkSVGRenderContext ( const SkSVGRenderContext other,
const SkSVGNode node 
)

Definition at line 187 of file SkSVGRenderContext.cpp.

188 : SkSVGRenderContext(other.fCanvas,
189 other.fFontMgr,
190 other.fResourceProvider,
191 other.fIDMapper,
192 *other.fLengthContext,
193 *other.fPresentationContext,
194 OBBScope{node, this},
195 other.fTextShapingFactory) {}

◆ ~SkSVGRenderContext()

SkSVGRenderContext::~SkSVGRenderContext ( )

Definition at line 197 of file SkSVGRenderContext.cpp.

197 {
198 fCanvas->restoreToCount(fCanvasSaveCount);
199}
void restoreToCount(int saveCount)
Definition SkCanvas.cpp:482

Member Function Documentation

◆ applyPresentationAttributes()

void SkSVGRenderContext::applyPresentationAttributes ( const SkSVGPresentationAttributes attrs,
uint32_t  flags 
)

Definition at line 209 of file SkSVGRenderContext.cpp.

210 {
211
212#define ApplyLazyInheritedAttribute(ATTR) \
213 do { \
214 /* All attributes should be defined on the inherited context. */ \
215 SkASSERT(fPresentationContext->fInherited.f ## ATTR.isValue()); \
216 const auto& attr = attrs.f ## ATTR; \
217 if (attr.isValue() && *attr != *fPresentationContext->fInherited.f ## ATTR) { \
218 /* Update the local attribute value */ \
219 fPresentationContext.writable()->fInherited.f ## ATTR.set(*attr); \
220 } \
221 } while (false)
222
224 ApplyLazyInheritedAttribute(FillOpacity);
229 ApplyLazyInheritedAttribute(FontWeight);
232 ApplyLazyInheritedAttribute(StrokeDashOffset);
233 ApplyLazyInheritedAttribute(StrokeDashArray);
234 ApplyLazyInheritedAttribute(StrokeLineCap);
235 ApplyLazyInheritedAttribute(StrokeLineJoin);
236 ApplyLazyInheritedAttribute(StrokeMiterLimit);
237 ApplyLazyInheritedAttribute(StrokeOpacity);
238 ApplyLazyInheritedAttribute(StrokeWidth);
239 ApplyLazyInheritedAttribute(TextAnchor);
240 ApplyLazyInheritedAttribute(Visibility);
242 ApplyLazyInheritedAttribute(ColorInterpolation);
243 ApplyLazyInheritedAttribute(ColorInterpolationFilters);
244
245#undef ApplyLazyInheritedAttribute
246
247 // Uninherited attributes. Only apply to the current context.
248
249 const bool hasFilter = attrs.fFilter.isValue();
250 if (attrs.fOpacity.isValue()) {
251 this->applyOpacity(*attrs.fOpacity, flags, hasFilter);
252 }
253
254 if (attrs.fClipPath.isValue()) {
255 this->applyClip(*attrs.fClipPath);
256 }
257
258 if (attrs.fMask.isValue()) {
259 this->applyMask(*attrs.fMask);
260 }
261
262 // TODO: when both a filter and opacity are present, we can apply both with a single layer
263 if (hasFilter) {
264 this->applyFilter(*attrs.fFilter);
265 }
266
267 // Remaining uninherited presentation attributes are accessed as SkSVGNode fields, not via
268 // the render context.
269 // TODO: resolve these in a pre-render styling pass and assert here that they are values.
270 // - stop-color
271 // - stop-opacity
272 // - flood-color
273 // - flood-opacity
274 // - lighting-color
275}
#define ApplyLazyInheritedAttribute(ATTR)
bool isValue() const
Definition SkSVGTypes.h:64
FlutterSemanticsFlag flags
SkSVGProperty< SkSVGFuncIRI, false > fMask
SkSVGProperty< SkSVGFuncIRI, false > fClipPath
SkSVGProperty< SkSVGNumberType, false > fOpacity
SkSVGProperty< SkSVGFuncIRI, false > fFilter

◆ canvas()

SkCanvas * SkSVGRenderContext::canvas ( ) const
inline

Definition at line 90 of file SkSVGRenderContext.h.

90{ return fCanvas; }

◆ clipPath()

const SkPath * SkSVGRenderContext::clipPath ( ) const
inline

Definition at line 140 of file SkSVGRenderContext.h.

140{ return fClipPath.getMaybeNull(); }
const T * getMaybeNull() const
Definition SkTLazy.h:108

◆ fillPaint()

SkTLazy< SkPaint > SkSVGRenderContext::fillPaint ( ) const

Definition at line 443 of file SkSVGRenderContext.cpp.

443 {
444 const auto& props = fPresentationContext->fInherited;
445 auto p = this->commonPaint(*props.fFill, *props.fFillOpacity);
446
447 if (p.isValid()) {
448 p->setStyle(SkPaint::kFill_Style);
449 }
450
451 return p;
452}
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
SkSVGPresentationAttributes fInherited

◆ findNodeById()

SkSVGRenderContext::BorrowedNode SkSVGRenderContext::findNodeById ( const SkSVGIRI iri) const

Definition at line 201 of file SkSVGRenderContext.cpp.

201 {
202 if (iri.type() != SkSVGIRI::Type::kLocal) {
203 SkDebugf("non-local iri references not currently supported");
204 return BorrowedNode(nullptr);
205 }
206 return BorrowedNode(fIDMapper.find(iri.iri()));
207}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const SkSVGStringType & iri() const
Definition SkSVGTypes.h:164
Type type() const
Definition SkSVGTypes.h:163
V * find(const K &key) const
Definition SkTHash.h:479

◆ fontMgr()

sk_sp< SkFontMgr > SkSVGRenderContext::fontMgr ( ) const
inline

Definition at line 146 of file SkSVGRenderContext.h.

146 {
147 // It is probably an oversight to try to render <text> without having set the SkFontMgr.
148 // We will assert this in debug mode, but fallback to an empty fontmgr in release builds.
149 SkASSERT(fFontMgr);
150 return fFontMgr ? fFontMgr : SkFontMgr::RefEmpty();
151 }
#define SkASSERT(cond)
Definition SkAssert.h:116
static sk_sp< SkFontMgr > RefEmpty()

◆ lengthContext()

const SkSVGLengthContext & SkSVGRenderContext::lengthContext ( ) const
inline

Definition at line 85 of file SkSVGRenderContext.h.

85{ return *fLengthContext; }

◆ makeBidiRunIterator()

std::unique_ptr< SkShaper::BiDiRunIterator > SkSVGRenderContext::makeBidiRunIterator ( const char *  utf8,
size_t  utf8Bytes,
uint8_t  bidiLevel 
) const
inline

Definition at line 169 of file SkSVGRenderContext.h.

171 {
172 SkASSERT(fTextShapingFactory);
173 return fTextShapingFactory->makeBidiRunIterator(utf8, utf8Bytes, bidiLevel);
174 }
virtual std::unique_ptr< SkShaper::BiDiRunIterator > makeBidiRunIterator(const char *utf8, size_t utf8Bytes, uint8_t bidiLevel)=0

◆ makeScriptRunIterator()

std::unique_ptr< SkShaper::ScriptRunIterator > SkSVGRenderContext::makeScriptRunIterator ( const char *  utf8,
size_t  utf8Bytes 
) const
inline

Definition at line 176 of file SkSVGRenderContext.h.

177 {
178 SkASSERT(fTextShapingFactory);
179 constexpr SkFourByteTag unknownScript = SkSetFourByteTag('Z', 'z', 'z', 'z');
180 return fTextShapingFactory->makeScriptRunIterator(utf8, utf8Bytes, unknownScript);
181 }
uint32_t SkFourByteTag
Definition SkTypes.h:166
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition SkTypes.h:167
virtual std::unique_ptr< SkShaper::ScriptRunIterator > makeScriptRunIterator(const char *utf8, size_t utf8Bytes, SkFourByteTag script)=0

◆ makeShaper()

std::unique_ptr< SkShaper > SkSVGRenderContext::makeShaper ( ) const
inline

Definition at line 164 of file SkSVGRenderContext.h.

164 {
165 SkASSERT(fTextShapingFactory);
166 return fTextShapingFactory->makeShaper(this->fontMgr());
167 }
sk_sp< SkFontMgr > fontMgr() const
virtual std::unique_ptr< SkShaper > makeShaper(sk_sp< SkFontMgr > fallback)=0

◆ presentationContext()

const SkSVGPresentationContext & SkSVGRenderContext::presentationContext ( ) const
inline

Definition at line 88 of file SkSVGRenderContext.h.

88{ return *fPresentationContext; }

◆ resolveOBBRect()

SkRect SkSVGRenderContext::resolveOBBRect ( const SkSVGLength x,
const SkSVGLength y,
const SkSVGLength w,
const SkSVGLength h,
SkSVGObjectBoundingBoxUnits  obbu 
) const

Definition at line 503 of file SkSVGRenderContext.cpp.

505 {
506 SkTCopyOnFirstWrite<SkSVGLengthContext> lctx(fLengthContext);
507
509 *lctx.writable() = SkSVGLengthContext({1,1});
510 }
511
512 auto r = lctx->resolveRect(x, y, w, h);
513 const auto obbt = this->transformForCurrentOBB(obbu);
514
515 return SkRect::MakeXYWH(obbt.scale.x * r.x() + obbt.offset.x,
516 obbt.scale.y * r.y() + obbt.offset.y,
517 obbt.scale.x * r.width(),
518 obbt.scale.y * r.height());
519}
SkRect resolveRect(const SkSVGLength &x, const SkSVGLength &y, const SkSVGLength &w, const SkSVGLength &h) const
OBBTransform transformForCurrentOBB(SkSVGObjectBoundingBoxUnits) const
double y
double x
SkScalar w
SkScalar h
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

◆ resolveSvgColor()

SkSVGColorType SkSVGRenderContext::resolveSvgColor ( const SkSVGColor color) const

Definition at line 471 of file SkSVGRenderContext.cpp.

471 {
472 if (fPresentationContext->fNamedColors) {
473 for (auto&& ident : color.vars()) {
474 SkSVGColorType* c = fPresentationContext->fNamedColors->find(ident);
475 if (c) {
476 return *c;
477 }
478 }
479 }
480 switch (color.type()) {
482 return color.color();
484 return *fPresentationContext->fInherited.fColor;
486 SkDebugf("ICC color unimplemented");
487 return SK_ColorBLACK;
488 }
490}
SkColor4f color
#define SkUNREACHABLE
Definition SkAssert.h:135
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
SkColor SkSVGColorType
Definition SkSVGTypes.h:25
SkSVGProperty< SkSVGColorType, true > fColor
const skia_private::THashMap< SkString, SkSVGColorType > * fNamedColors

◆ resourceProvider()

const sk_sp< skresources::ResourceProvider > & SkSVGRenderContext::resourceProvider ( ) const
inline

Definition at line 142 of file SkSVGRenderContext.h.

142 {
143 return fResourceProvider;
144 }

◆ saveOnce()

void SkSVGRenderContext::saveOnce ( )

Definition at line 323 of file SkSVGRenderContext.cpp.

323 {
324 // The canvas only needs to be saved once, per local SkSVGRenderContext.
325 if (fCanvas->getSaveCount() == fCanvasSaveCount) {
326 fCanvas->save();
327 }
328
329 SkASSERT(fCanvas->getSaveCount() > fCanvasSaveCount);
330}
int save()
Definition SkCanvas.cpp:451

◆ strokePaint()

SkTLazy< SkPaint > SkSVGRenderContext::strokePaint ( ) const

Definition at line 454 of file SkSVGRenderContext.cpp.

454 {
455 const auto& props = fPresentationContext->fInherited;
456 auto p = this->commonPaint(*props.fStroke, *props.fStrokeOpacity);
457
458 if (p.isValid()) {
459 p->setStyle(SkPaint::kStroke_Style);
460 p->setStrokeWidth(fLengthContext->resolve(*props.fStrokeWidth,
462 p->setStrokeCap(toSkCap(*props.fStrokeLineCap));
463 p->setStrokeJoin(toSkJoin(*props.fStrokeLineJoin));
464 p->setStrokeMiter(*props.fStrokeMiterLimit);
465 p->setPathEffect(dash_effect(props, *fLengthContext));
466 }
467
468 return p;
469}
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
SkScalar resolve(const SkSVGLength &, LengthType) const

◆ transformForCurrentOBB()

SkSVGRenderContext::OBBTransform SkSVGRenderContext::transformForCurrentOBB ( SkSVGObjectBoundingBoxUnits  u) const

Definition at line 493 of file SkSVGRenderContext.cpp.

493 {
495 return {{0,0},{1,1}};
496 }
497 SkASSERT(fOBBScope.fCtx);
498
499 const auto obb = fOBBScope.fNode->objectBoundingBox(*fOBBScope.fCtx);
500 return {{obb.x(), obb.y()}, {obb.width(), obb.height()}};
501}
SkRect objectBoundingBox(const SkSVGRenderContext &) const
Definition SkSVGNode.cpp:58
constexpr float x() const
Definition SkRect.h:720
const SkSVGRenderContext * fCtx

◆ writableLengthContext()

SkSVGLengthContext * SkSVGRenderContext::writableLengthContext ( )
inline

Definition at line 86 of file SkSVGRenderContext.h.

86{ return fLengthContext.writable(); }

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