Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
SkSVGDevice Class Referencefinal

#include <SkSVGDevice.h>

Inheritance diagram for SkSVGDevice:
SkClipStackDevice SkDevice SkRefCnt SkRefCntBase

Classes

class  AutoElement
 
struct  MxCp
 
class  ResourceBucket
 

Public Member Functions

void drawPaint (const SkPaint &paint) override
 
void drawAnnotation (const SkRect &rect, const char key[], SkData *value) override
 
void drawPoints (SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint) override
 
void drawImageRect (const SkImage *image, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &paint, SkCanvas::SrcRectConstraint constraint) override
 
void drawRect (const SkRect &r, const SkPaint &paint) override
 
void drawOval (const SkRect &oval, const SkPaint &paint) override
 
void drawRRect (const SkRRect &rr, const SkPaint &paint) override
 
void drawPath (const SkPath &path, const SkPaint &paint, bool pathIsMutable=false) override
 
void drawVertices (const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool) override
 
void drawMesh (const SkMesh &, sk_sp< SkBlender >, const SkPaint &) override
 
- Public Member Functions inherited from SkClipStackDevice
 SkClipStackDevice (const SkImageInfo &info, const SkSurfaceProps &props)
 
SkClipStackcs ()
 
const SkClipStackcs () const
 
void pushClipStack () override
 
void popClipStack () override
 
void clipRect (const SkRect &rect, SkClipOp, bool aa) override
 
void clipRRect (const SkRRect &rrect, SkClipOp, bool aa) override
 
void clipPath (const SkPath &path, SkClipOp, bool aa) override
 
void clipRegion (const SkRegion &deviceRgn, SkClipOp) override
 
void replaceClip (const SkIRect &rect) override
 
bool isClipAntiAliased () const override
 
bool isClipWideOpen () const override
 
bool isClipEmpty () const override
 
bool isClipRect () const override
 
void android_utils_clipAsRgn (SkRegion *) const override
 
SkIRect devClipBounds () const override
 
- Public Member Functions inherited from SkDevice
 SkDevice (const SkImageInfo &, const SkSurfaceProps &)
 
const SkImageInfoimageInfo () const
 
int width () const
 
int height () const
 
bool isOpaque () const
 
SkIRect bounds () const
 
SkISize size () const
 
const SkSurfacePropssurfaceProps () const
 
SkScalerContextFlags scalerContextFlags () const
 
virtual SkStrikeDeviceInfo strikeDeviceInfo () const
 
bool writePixels (const SkPixmap &src, int x, int y)
 
bool readPixels (const SkPixmap &dst, int x, int y)
 
bool accessPixels (SkPixmap *pmap)
 
bool peekPixels (SkPixmap *)
 
const SkM44localToDevice44 () const
 
const SkMatrixlocalToDevice () const
 
const SkM44deviceToGlobal () const
 
const SkM44globalToDevice () const
 
SkIPoint getOrigin () const
 
bool isPixelAlignedToGlobal () const
 
SkMatrix getRelativeTransform (const SkDevice &) const
 
void setLocalToDevice (const SkM44 &localToDevice)
 
void setGlobalCTM (const SkM44 &ctm)
 
void getGlobalBounds (SkIRect *bounds) const
 
SkIRect getGlobalBounds () const
 
void clipShader (sk_sp< SkShader > sh, SkClipOp op)
 
virtual bool android_utils_clipWithStencil ()
 
virtual bool useDrawCoverageMaskForMaskFilters () const
 
virtual bool isNoPixelsDevice () const
 
virtual void * getRasterHandle () const
 
virtual GrRecordingContextrecordingContext () const
 
virtual skgpu::graphite::Recorderrecorder () const
 
virtual skgpu::ganesh::DeviceasGaneshDevice ()
 
virtual skgpu::graphite::DeviceasGraphiteDevice ()
 
virtual void setImmutable ()
 
virtual sk_sp< SkSurfacemakeSurface (const SkImageInfo &, const SkSurfaceProps &)
 
virtual sk_sp< SkDevicecreateDevice (const CreateInfo &, const SkPaint *)
 
void drawGlyphRunList (SkCanvas *, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
 
virtual sk_sp< sktext::gpu::SlugconvertGlyphRunListToSlug (const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
 
virtual void drawSlug (SkCanvas *, const sktext::gpu::Slug *slug, const SkPaint &paint)
 
virtual void drawRegion (const SkRegion &r, const SkPaint &paint)
 
virtual void drawArc (const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
 
virtual void drawDRRect (const SkRRect &outer, const SkRRect &inner, const SkPaint &)
 
virtual bool shouldDrawAsTiledImageRect () const
 
virtual bool drawAsTiledImageRect (SkCanvas *, const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
 
virtual void drawImageLattice (const SkImage *, const SkCanvas::Lattice &, const SkRect &dst, SkFilterMode, const SkPaint &)
 
virtual void drawShadow (const SkPath &, const SkDrawShadowRec &)
 
virtual void drawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], sk_sp< SkBlender >, const SkPaint &paint)
 
virtual void drawAtlas (const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &)
 
virtual void drawEdgeAAQuad (const SkRect &rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
 
virtual void drawEdgeAAImageSet (const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
 
virtual void drawDrawable (SkCanvas *, SkDrawable *, const SkMatrix *)
 
virtual sk_sp< SkSpecialImagesnapSpecial (const SkIRect &subset, bool forceCopy=false)
 
virtual sk_sp< SkSpecialImagesnapSpecialScaled (const SkIRect &subset, const SkISize &dstDims)
 
sk_sp< SkSpecialImagesnapSpecial ()
 
virtual void drawDevice (SkDevice *, const SkSamplingOptions &, const SkPaint &)
 
virtual void drawSpecial (SkSpecialImage *, const SkMatrix &localToDevice, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint constraint=SkCanvas::kStrict_SrcRectConstraint)
 
virtual void drawCoverageMask (const SkSpecialImage *, const SkMatrix &maskToDevice, const SkSamplingOptions &, const SkPaint &)
 
virtual bool drawBlurredRRect (const SkRRect &, const SkPaint &, float deviceSigma)
 
void drawFilteredImage (const skif::Mapping &mapping, SkSpecialImage *src, SkColorType ct, const SkImageFilter *, const SkSamplingOptions &, const SkPaint &)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< SkDeviceMake (const SkISize &size, std::unique_ptr< SkXMLWriter >, uint32_t flags)
 

Private Member Functions

 ~SkSVGDevice () override
 
void onDrawGlyphRunList (SkCanvas *, const sktext::GlyphRunList &, const SkPaint &paint) override
 

Additional Inherited Members

- Protected Member Functions inherited from SkDevice
virtual sk_sp< SkSpecialImagemakeSpecial (const SkBitmap &)
 
virtual sk_sp< SkSpecialImagemakeSpecial (const SkImage *)
 
void setDeviceCoordinateSystem (const SkM44 &deviceToGlobal, const SkM44 &globalToDevice, const SkM44 &localToDevice, int bufferOriginX, int bufferOriginY)
 
void setOrigin (const SkM44 &globalCTM, int x, int y)
 
bool checkLocalToDeviceDirty ()
 

Detailed Description

Definition at line 45 of file SkSVGDevice.h.

Member Function Documentation

◆ drawAnnotation()

void SkSVGDevice::drawAnnotation ( const SkRect rect,
const char  key[],
SkData value 
)
overridevirtual

Reimplemented from SkDevice.

Definition at line 853 of file SkSVGDevice.cpp.

853 {
854 if (!value) {
855 return;
856 }
857
858 if (!strcmp(SkAnnotationKeys::URL_Key(), key) ||
860 this->cs().save();
861 this->cs().clipRect(rect, this->localToDevice(), SkClipOp::kIntersect, true);
862 SkRect transformedRect = this->cs().bounds(this->getGlobalBounds());
863 this->cs().restore();
864 if (transformedRect.isEmpty()) {
865 return;
866 }
867
868 SkString url(static_cast<const char*>(value->data()), value->size() - 1);
869 AutoElement a("a", fWriter);
870 a.addAttribute("xlink:href", url.c_str());
871 {
872 AutoElement r("rect", fWriter);
873 r.addAttribute("fill-opacity", "0.0");
874 r.addRectAttributes(transformedRect);
875 }
876 }
877}
static const char * Link_Named_Dest_Key()
static const char * URL_Key()
SkClipStack & cs()
void clipRect(const SkRect &, const SkMatrix &matrix, SkClipOp, bool doAA)
SkRect bounds(const SkIRect &deviceBounds) const
const SkMatrix & localToDevice() const
Definition SkDevice.h:179
SkIRect getGlobalBounds() const
Definition SkDevice.h:230
struct MyStruct a[10]
uint8_t value
bool isEmpty() const
Definition SkRect.h:693

◆ drawImageRect()

void SkSVGDevice::drawImageRect ( const SkImage image,
const SkRect src,
const SkRect dst,
const SkSamplingOptions sampling,
const SkPaint paint,
SkCanvas::SrcRectConstraint  constraint 
)
overridevirtual

Implements SkDevice.

Definition at line 1026 of file SkSVGDevice.cpp.

1028 {
1029 SkBitmap bm;
1030 // TODO: support gpu images
1031 if (!as_IB(image)->getROPixels(nullptr, &bm)) {
1032 return;
1033 }
1034
1035 SkClipStack* cs = &this->cs();
1036 SkClipStack::AutoRestore ar(cs, false);
1037 if (src && *src != SkRect::Make(bm.bounds())) {
1038 cs->save();
1039 cs->clipRect(dst, this->localToDevice(), SkClipOp::kIntersect, paint.isAntiAlias());
1040 }
1041
1042 SkMatrix adjustedMatrix = this->localToDevice()
1043 * SkMatrix::RectToRect(src ? *src : SkRect::Make(bm.bounds()), dst);
1044
1045 drawBitmapCommon(MxCp(&adjustedMatrix, cs), bm, paint);
1046}
static SkImage_Base * as_IB(SkImage *image)
SkIRect bounds() const
Definition SkBitmap.h:382
SkIRect bounds() const
Definition SkDevice.h:125
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition SkMatrix.h:157
bool isAntiAlias() const
Definition SkPaint.h:162
static sk_sp< SkDevice > Make(const SkISize &size, std::unique_ptr< SkXMLWriter >, uint32_t flags)
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
dst
Definition cp.py:12
static SkRect Make(const SkISize &size)
Definition SkRect.h:669

◆ drawMesh()

void SkSVGDevice::drawMesh ( const SkMesh ,
sk_sp< SkBlender ,
const SkPaint  
)
overridevirtual

Implements SkDevice.

Definition at line 1172 of file SkSVGDevice.cpp.

1172 {
1173 // todo
1174}

◆ drawOval()

void SkSVGDevice::drawOval ( const SkRect oval,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 929 of file SkSVGDevice.cpp.

929 {
930 if (paint.getPathEffect()) {
931 this->drawPath(SkPath::Oval(oval), paint, true);
932 return;
933 }
934
935 AutoElement ellipse("ellipse", this, fResourceBucket.get(), MxCp(this), paint);
936 ellipse.addAttribute("cx", oval.centerX());
937 ellipse.addAttribute("cy", oval.centerY());
938 ellipse.addAttribute("rx", oval.width() / 2);
939 ellipse.addAttribute("ry", oval.height() / 2);
940}
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
Definition SkPath.cpp:3522
void drawPath(const SkPath &path, const SkPaint &paint, bool pathIsMutable=false) override
SkRect oval
Definition SkRecords.h:249
constexpr float centerX() const
Definition SkRect.h:776
constexpr float height() const
Definition SkRect.h:769
constexpr float centerY() const
Definition SkRect.h:785
constexpr float width() const
Definition SkRect.h:762

◆ drawPaint()

void SkSVGDevice::drawPaint ( const SkPaint paint)
overridevirtual

Implements SkDevice.

Definition at line 847 of file SkSVGDevice.cpp.

847 {
848 AutoElement rect("rect", this, fResourceBucket.get(), MxCp(this), paint);
849 rect.addRectAttributes(SkRect::MakeWH(SkIntToScalar(this->width()),
850 SkIntToScalar(this->height())));
851}
#define SkIntToScalar(x)
Definition SkScalar.h:57
int height() const
Definition SkDevice.h:120
int width() const
Definition SkDevice.h:119
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ drawPath()

void SkSVGDevice::drawPath ( const SkPath path,
const SkPaint paint,
bool  pathIsMutable = false 
)
overridevirtual

If pathIsMutable, then the implementation is allowed to cast path to a non-const pointer and modify it in place (as an optimization). Canvas may do this to implement helpers such as drawOval, by placing a temp path on the stack to hold the representation of the oval.

Implements SkDevice.

Definition at line 952 of file SkSVGDevice.cpp.

952 {
953 if (path.isInverseFillType()) {
954 SkDebugf("Inverse path fill type not yet implemented.");
955 return;
956 }
957
958 SkPath pathStorage;
959 SkPath* pathPtr = const_cast<SkPath*>(&path);
961
962 // Apply path effect from paint to path.
963 if (path_paint->getPathEffect()) {
964 if (!pathIsMutable) {
965 pathPtr = &pathStorage;
966 }
967 bool fill = skpathutils::FillPathWithPaint(path, *path_paint, pathPtr);
968 if (fill) {
969 // Path should be filled.
970 path_paint.writable()->setStyle(SkPaint::kFill_Style);
971 } else {
972 // Path should be drawn with a hairline (width == 0).
973 path_paint.writable()->setStyle(SkPaint::kStroke_Style);
974 path_paint.writable()->setStrokeWidth(0);
975 }
976
977 path_paint.writable()->setPathEffect(nullptr); // path effect processed
978 }
979
980 // Create path element.
981 AutoElement elem("path", this, fResourceBucket.get(), MxCp(this), *path_paint);
982 elem.addPathAttributes(*pathPtr, this->pathEncoding());
983
984 // TODO: inverse fill types?
985 if (pathPtr->getFillType() == SkPathFillType::kEvenOdd) {
986 elem.addAttribute("fill-rule", "evenodd");
987 }
988}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
SkPathFillType getFillType() const
Definition SkPath.h:230
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)

◆ drawPoints()

void SkSVGDevice::drawPoints ( SkCanvas::PointMode  mode,
size_t  count,
const SkPoint  pts[],
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 879 of file SkSVGDevice.cpp.

880 {
882
883 switch (mode) {
884 // todo
886 // TODO?
887 break;
889 count -= 1;
890 for (size_t i = 0; i < count; i += 2) {
891 path.moveTo(pts[i]);
892 path.lineTo(pts[i+1]);
893 }
894 break;
896 if (count > 1) {
897 path.addPolygon(pts, SkToInt(count), false);
898 }
899 break;
900 }
901
902 this->drawPath(path.detach(), paint, true);
903}
int count
constexpr int SkToInt(S x)
Definition SkTo.h:29
@ kLines_PointMode
draw each pair of points as a line segment
Definition SkCanvas.h:1242
@ kPolygon_PointMode
draw the array of points as a open polygon
Definition SkCanvas.h:1243
@ kPoints_PointMode
draw each point separately
Definition SkCanvas.h:1241

◆ drawRect()

void SkSVGDevice::drawRect ( const SkRect r,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 905 of file SkSVGDevice.cpp.

905 {
906 if (paint.getPathEffect()) {
907 this->drawPath(SkPath::Rect(r), paint, true);
908 return;
909 }
910
911 std::unique_ptr<AutoElement> svg;
912 if (RequiresViewportReset(paint)) {
913 svg = std::make_unique<AutoElement>("svg", this, fResourceBucket.get(), MxCp(this), paint);
914 svg->addRectAttributes(r);
915 }
916
917 AutoElement rect("rect", this, fResourceBucket.get(), MxCp(this), paint);
918
919 if (svg) {
920 rect.addAttribute("x", 0);
921 rect.addAttribute("y", 0);
922 rect.addAttribute("width", "100%");
923 rect.addAttribute("height", "100%");
924 } else {
925 rect.addRectAttributes(r);
926 }
927}
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition SkPath.cpp:3518
const char * svg

◆ drawRRect()

void SkSVGDevice::drawRRect ( const SkRRect rr,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 942 of file SkSVGDevice.cpp.

942 {
943 if (paint.getPathEffect()) {
944 this->drawPath(SkPath::RRect(rr), paint, true);
945 return;
946 }
947
948 AutoElement elem("path", this, fResourceBucket.get(), MxCp(this), paint);
949 elem.addPathAttributes(SkPath::RRect(rr), this->pathEncoding());
950}
static SkPath RRect(const SkRRect &, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:3534

◆ drawVertices()

void SkSVGDevice::drawVertices ( const SkVertices ,
sk_sp< SkBlender ,
const SkPaint ,
bool  skipColorXform 
)
overridevirtual

If skipColorXform is true, then the implementation should assume that the provided vertex colors are already in the destination color space.

Implements SkDevice.

Definition at line 1168 of file SkSVGDevice.cpp.

1168 {
1169 // todo
1170}

◆ Make()

sk_sp< SkDevice > SkSVGDevice::Make ( const SkISize size,
std::unique_ptr< SkXMLWriter writer,
uint32_t  flags 
)
static

Definition at line 731 of file SkSVGDevice.cpp.

733 {
734 return writer ? sk_sp<SkDevice>(new SkSVGDevice(size, std::move(writer), flags))
735 : nullptr;
736}
SkISize size() const
Definition SkDevice.h:126
FlutterSemanticsFlag flags

◆ onDrawGlyphRunList()

void SkSVGDevice::onDrawGlyphRunList ( SkCanvas canvas,
const sktext::GlyphRunList glyphRunList,
const SkPaint paint 
)
overrideprivatevirtual

Implements SkDevice.

Definition at line 1137 of file SkSVGDevice.cpp.

1139 {
1140 SkASSERT(!glyphRunList.hasRSXForm());
1141 const auto draw_as_path =
1142 (fFlags & SkSVGCanvas::kConvertTextToPaths_Flag) || paint.getPathEffect();
1143
1144 if (draw_as_path) {
1145 // Emit a single <path> element.
1146 SkPath path;
1147 for (auto& glyphRun : glyphRunList) {
1148 AddPath(glyphRun, glyphRunList.origin(), &path);
1149 }
1150
1151 this->drawPath(path, paint);
1152
1153 return;
1154 }
1155
1156 // Emit one <text> element for each run.
1157 for (auto& glyphRun : glyphRunList) {
1158 AutoElement elem("text", this, fResourceBucket.get(), MxCp(this), paint);
1159 elem.addTextAttributes(glyphRun.font());
1160
1161 SVGTextBuilder builder(glyphRunList.origin(), glyphRun);
1162 elem.addAttribute("x", builder.posX());
1163 elem.addAttribute("y", builder.posY());
1164 elem.addText(builder.text());
1165 }
1166}
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kConvertTextToPaths_Flag
Definition SkSVGCanvas.h:23
bool hasRSXForm() const
Definition GlyphRun.h:105
SkPoint origin() const
Definition GlyphRun.h:114

◆ ~SkSVGDevice()

SkSVGDevice::~SkSVGDevice ( )
overrideprivate

Definition at line 759 of file SkSVGDevice.cpp.

759 {
760 // Pop order is important.
761 while (!fClipStack.empty()) {
762 fClipStack.pop_back();
763 }
764}
bool empty() const
Definition SkTArray.h:194

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