iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IGraphicsSkia.h
1#pragma once
2
3#include "IPlugPlatform.h"
4#include "IGraphics.h"
5
6// N.B. - this must be defined according to the skia build, not the iPlug build
7#if (defined OS_MAC || defined OS_IOS) && !defined IGRAPHICS_SKIA_NO_METAL
8#define SK_METAL
9#endif
10
11#if defined IGRAPHICS_GL
12#define SK_GL
13#endif
14
15#pragma warning( push )
16#pragma warning( disable : 4244 )
17#include "SkSurface.h"
18#include "SkPath.h"
19#include "SkCanvas.h"
20#include "SkImage.h"
21#include "GrDirectContext.h"
22#pragma warning( pop )
23
24BEGIN_IPLUG_NAMESPACE
25BEGIN_IGRAPHICS_NAMESPACE
26
28SkRect SkiaRect(const IRECT& r);
29
31SkBlendMode SkiaBlendMode(const IBlend* pBlend);
32
34SkColor SkiaColor(const IColor& color, const IBlend* pBlend);
35
37SkTileMode SkiaTileMode(const IPattern& pattern);
38
40SkPaint SkiaPaint(const IPattern& pattern, const IBlend* pBlend);
41
45{
46private:
47 class Bitmap;
48 struct Font;
49public:
50 IGraphicsSkia(IGEditorDelegate& dlg, int w, int h, int fps, float scale);
52
53 const char* GetDrawingAPIStr() override ;
54
55 void BeginFrame() override;
56 void EndFrame() override;
57 void OnViewInitialized(void* pContext) override;
58 void OnViewDestroyed() override;
59 void DrawResize() override;
60
61 void DrawBitmap(const IBitmap& bitmap, const IRECT& dest, int srcX, int srcY, const IBlend* pBlend) override;
62
63 void PathClear() override { mMainPath.reset(); }
64 void PathClose() override { mMainPath.close(); }
65 void PathArc(float cx, float cy, float r, float a1, float a2, EWinding winding) override;
66
67 void PathMoveTo(float x, float y) override { mMainPath.moveTo(mMatrix.mapXY(x, y)); }
68 void PathLineTo(float x, float y) override { mMainPath.lineTo(mMatrix.mapXY(x, y)); }
69
70 void PathCubicBezierTo(float x1, float y1, float x2, float y2, float x3, float y3) override
71 {
72 mMainPath.cubicTo(mMatrix.mapXY(x1, y1), mMatrix.mapXY(x2, y2), mMatrix.mapXY(x3, y3));
73 }
74
75 void PathQuadraticBezierTo(float cx, float cy, float x2, float y2) override
76 {
77 mMainPath.quadTo(mMatrix.mapXY(cx, cy), mMatrix.mapXY(x2, y2));
78 }
79
80 void PathStroke(const IPattern& pattern, float thickness, const IStrokeOptions& options, const IBlend* pBlend) override;
81 void PathFill(const IPattern& pattern, const IFillOptions& options, const IBlend* pBlend) override;
82
83#ifdef IGRAPHICS_DRAWFILL_DIRECT
84 //void DrawPoint(const IColor& color, float x, float y, const IBlend* pBlend) override;
85 //void DrawLine(const IColor& color, float x1, float y1, float x2, float y2, const IBlend* pBlend, float thickness) override;
86 //void DrawGrid(const IColor& color, const IRECT& bounds, float gridSizeH, float gridSizeV, const IBlend* pBlend, float thickness) override;
87 //void DrawData(const IColor& color, const IRECT& bounds, float* normYPoints, int nPoints, float* normXPoints, const IBlend* pBlend, float thickness) override;
88 //void DrawDottedLine(const IColor& color, float x1, float y1, float x2, float y2, const IBlend* pBlend, float thickness, float dashLen) override;
89 //void DrawTriangle(const IColor& color, float x1, float y1, float x2, float y2, float x3, float y3, const IBlend* pBlend, float thickness) override;
90 void DrawRect(const IColor& color, const IRECT& bounds, const IBlend* pBlend, float thickness) override;
91 void DrawRoundRect(const IColor& color, const IRECT& bounds, float cornerRadius, const IBlend* pBlend, float thickness) override;
92 //void DrawRoundRect(const IColor& color, const IRECT& bounds, float cRTL, float cRTR, float cRBR, float cRBL, const IBlend* pBlend, float thickness) override;
93 //void DrawConvexPolygon(const IColor& color, float* x, float* y, int nPoints, const IBlend* pBlend, float thickness) override;
94 void DrawArc(const IColor& color, float cx, float cy, float r, float a1, float a2, const IBlend* pBlend, float thickness) override;
95 void DrawCircle(const IColor& color, float cx, float cy, float r, const IBlend* pBlend, float thickness) override;
96 //void DrawDottedRect(const IColor& color, const IRECT& bounds, const IBlend* pBlend, float thickness, float dashLen) override;
97 void DrawEllipse(const IColor& color, const IRECT& bounds, const IBlend* pBlend, float thickness) override;
98 //void DrawEllipse(const IColor& color, float x, float y, float r1, float r2, float angle, const IBlend* pBlend, float thickness) override;
99
100 //void FillTriangle(const IColor& color, float x1, float y1, float x2, float y2, float x3, float y3, const IBlend* pBlend) override;
101 void FillRect(const IColor& color, const IRECT& bounds, const IBlend* pBlend) override;
102 void FillRoundRect(const IColor& color, const IRECT& bounds, float cornerRadius, const IBlend* pBlend) override;
103 //void FillRoundRect(const IColor& color, const IRECT& bounds, float cRTL, float cRTR, float cRBR, float cRBL, const IBlend* pBlend) override;
104 //void FillConvexPolygon(const IColor& color, float* x, float* y, int nPoints, const IBlend* pBlend) override;
105 void FillArc(const IColor& color, float cx, float cy, float r, float a1, float a2, const IBlend* pBlend) override;
106 void FillCircle(const IColor& color, float cx, float cy, float r, const IBlend* pBlend) override;
107 void FillEllipse(const IColor& color, const IRECT& bounds, const IBlend* pBlend) override;
108 //void FillEllipse(const IColor& color, float x, float y, float r1, float r2, float angle, const IBlend* pBlend) override;
109#endif
110 void DrawFastDropShadow(const IRECT& innerBounds, const IRECT& outerBounds, float xyDrop, float roundness, float blur, IBlend* pBlend) override;
111
112 IColor GetPoint(int x, int y) override;
113 void* GetDrawContext() override { return (void*) mCanvas; }
114
115 bool BitmapExtSupported(const char* ext) override;
116 int AlphaChannel() const override { return 3; }
117 bool FlippedBitmap() const override { return false; }
118
119 APIBitmap* CreateAPIBitmap(int width, int height, float scale, double drawScale, bool cacheable = false) override;
120
121 void GetLayerBitmapData(const ILayerPtr& layer, RawBitmapData& data) override;
122 void ApplyShadowMask(ILayerPtr& layer, RawBitmapData& mask, const IShadow& shadow) override;
123
124 void UpdateLayer() override;
125
126protected:
127
128 float DoMeasureText(const IText& text, const char* str, IRECT& bounds) const override;
129 void DoDrawText(const IText& text, const char* str, const IRECT& bounds, const IBlend* pBlend) override;
130
131 bool LoadAPIFont(const char* fontID, const PlatformFontPtr& font) override;
132
133 APIBitmap* LoadAPIBitmap(const char* fileNameOrResID, int scale, EResourceLocation location, const char* ext) override;
134 APIBitmap* LoadAPIBitmap(const char* name, const void* pData, int dataSize, int scale) override;
135private:
136 void PrepareAndMeasureText(const IText& text, const char* str, IRECT& r, double& x, double & y, SkFont& font) const;
137
138 void PathTransformSetMatrix(const IMatrix& m) override;
139 void SetClipRegion(const IRECT& r) override;
140
141 void RenderPath(SkPaint& paint);
142
143 sk_sp<SkSurface> mSurface;
144 SkCanvas* mCanvas = nullptr;
145 SkPath mMainPath;
146 SkMatrix mMatrix;
147 SkMatrix mClipMatrix;
148 SkMatrix mFinalMatrix;
149
150#if defined OS_WIN && defined IGRAPHICS_CPU
151 WDL_TypedBuf<uint8_t> mSurfaceMemory;
152#endif
153
154#ifndef IGRAPHICS_CPU
155 sk_sp<GrDirectContext> mGrContext;
156 sk_sp<SkSurface> mScreenSurface;
157#endif
158
159#ifdef IGRAPHICS_METAL
160 void* mMTLDevice;
161 void* mMTLCommandQueue;
162 void* mMTLDrawable;
163 void* mMTLLayer;
164#endif
165
166 static StaticStorage<Font> sFontCache;
167};
168
169END_IGRAPHICS_NAMESPACE
170END_IPLUG_NAMESPACE
171
Include to get consistently named preprocessor macros for different platforms and logging functionali...
A base class interface for a bitmap abstraction around the different drawing back end bitmap represen...
User-facing bitmap abstraction that you use to manage bitmap data, independant of draw class/platform...
An editor delegate base class for a SOMETHING that uses IGraphics for it's UI.
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
Definition: IGraphics.cpp:2497
virtual void FillEllipse(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill an ellipse within a rectangular region of the graphics context.
Definition: IGraphics.cpp:2613
virtual void DrawEllipse(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw an ellipse within a rectangular region of the graphics context.
Definition: IGraphics.cpp:2548
virtual void DrawRoundRect(const IColor &color, const IRECT &bounds, float cornerRadius=5.f, const IBlend *pBlend=0, float thickness=1.f)
Draw a rounded rectangle to the graphics context.
Definition: IGraphics.cpp:2504
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
Definition: IGraphics.cpp:2569
virtual void DrawArc(const IColor &color, float cx, float cy, float r, float a1, float a2, const IBlend *pBlend=0, float thickness=1.f)
Draw an arc to the graphics context.
Definition: IGraphics.cpp:2525
virtual void DrawCircle(const IColor &color, float cx, float cy, float r, const IBlend *pBlend=0, float thickness=1.f)
Draw a circle to the graphics context.
Definition: IGraphics.cpp:2532
virtual void FillRoundRect(const IColor &color, const IRECT &bounds, float cornerRadius=5.f, const IBlend *pBlend=0)
Fill a rounded rectangle with a color.
Definition: IGraphics.cpp:2576
virtual void FillArc(const IColor &color, float cx, float cy, float r, float a1, float a2, const IBlend *pBlend=0)
Fill an arc segment with a color.
Definition: IGraphics.cpp:2597
virtual void FillCircle(const IColor &color, float cx, float cy, float r, const IBlend *pBlend=0)
Fill a circle with a color.
Definition: IGraphics.cpp:2606
IGraphics draw class using Skia.
Definition: IGraphicsSkia.h:45
APIBitmap * LoadAPIBitmap(const char *fileNameOrResID, int scale, EResourceLocation location, const char *ext) override
Drawing API method to load a bitmap, called internally.
void PathQuadraticBezierTo(float cx, float cy, float x2, float y2) override
Add a quadratic bezier to the current path from the current point to the specified location.
Definition: IGraphicsSkia.h:75
void BeginFrame() override
Called at the beginning of drawing.
void GetLayerBitmapData(const ILayerPtr &layer, RawBitmapData &data) override
Get the contents of a layer as Raw RGBA bitmap data NOTE: you should only call this within IControl::...
void DrawResize() override
void DoDrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend) override
void PathStroke(const IPattern &pattern, float thickness, const IStrokeOptions &options, const IBlend *pBlend) override
Stroke the current current path.
void EndFrame() override
Called by some drawing API classes to finally blit the draw bitmap onto the screen or perform other c...
float DoMeasureText(const IText &text, const char *str, IRECT &bounds) const override
void PathCubicBezierTo(float x1, float y1, float x2, float y2, float x3, float y3) override
Add a cubic bezier to the current path from the current point to the specified location.
Definition: IGraphicsSkia.h:70
void PathArc(float cx, float cy, float r, float a1, float a2, EWinding winding) override
Add an arc to the current path.
int AlphaChannel() const override
void ApplyShadowMask(ILayerPtr &layer, RawBitmapData &mask, const IShadow &shadow) override
Implemented by a graphics backend to apply a calculated shadow mask to a layer, according to the shad...
const char * GetDrawingAPIStr() override
APIBitmap * CreateAPIBitmap(int width, int height, float scale, double drawScale, bool cacheable=false) override
Creates a new API bitmap, either in memory or as a GPU texture.
void * GetDrawContext() override
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
bool LoadAPIFont(const char *fontID, const PlatformFontPtr &font) override
Drawing API method to load a font from a PlatformFontPtr, called internally.
void OnViewInitialized(void *pContext) override
Called after platform view initialization, so that drawing classes can e.g.
void PathClear() override
Clear the stack of path drawing commands.
Definition: IGraphicsSkia.h:63
void PathMoveTo(float x, float y) override
Move the current point in the current path.
Definition: IGraphicsSkia.h:67
void UpdateLayer() override
Implemented by a graphics backend to prepare for drawing to the layer at the top of the stack.
void PathFill(const IPattern &pattern, const IFillOptions &options, const IBlend *pBlend) override
Fill the current current path.
bool BitmapExtSupported(const char *ext) override
Checks a file extension and reports whether this drawing API supports loading that extension.
void PathClose() override
Close the path that is being specified.
Definition: IGraphicsSkia.h:64
IColor GetPoint(int x, int y) override
Get the color at an X, Y location in the graphics context.
void PathLineTo(float x, float y) override
Add a line to the current path from the current point to the specified location.
Definition: IGraphicsSkia.h:68
void DrawBitmap(const IBitmap &bitmap, const IRECT &dest, int srcX, int srcY, const IBlend *pBlend) override
Draw a bitmap (raster) image to the graphics context.
bool FlippedBitmap() const override
void DrawFastDropShadow(const IRECT &innerBounds, const IRECT &outerBounds, float xyDrop, float roundness, float blur, IBlend *pBlend) override
NanoVG only.
void OnViewDestroyed() override
Called after a platform view is destroyed, so that drawing classes can e.g.
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.
Used to manage stroke behaviour for path based drawing back ends.
Used to manage composite/blend operations, independent of draw class/platform.
Used to manage color data, independent of draw class/platform.
Used to manage fill behaviour.
Used to store transformation matrices.
Used to store pattern information for gradients.
Used to manage a rectangular area, independent of draw class/platform.
Used to specify properties of a drop-shadow to a layer.
IText is used to manage font and text/text entry style for a piece of text on the UI,...