diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrClip.h | 5 | ||||
-rw-r--r-- | include/gpu/GrPaint.h | 15 | ||||
-rw-r--r-- | include/gpu/GrRenderTargetContext.h | 139 | ||||
-rw-r--r-- | include/gpu/GrTypes.h | 12 | ||||
-rw-r--r-- | include/gpu/GrTypesPriv.h | 15 |
5 files changed, 117 insertions, 69 deletions
diff --git a/include/gpu/GrClip.h b/include/gpu/GrClip.h index 2d4c1f2628..9bf2da205e 100644 --- a/include/gpu/GrClip.h +++ b/include/gpu/GrClip.h @@ -8,6 +8,7 @@ #ifndef GrClip_DEFINED #define GrClip_DEFINED +#include "GrTypes.h" #include "SkRect.h" #include "SkRRect.h" @@ -45,7 +46,7 @@ public: * @return true if the clip is equivalent to a single rrect, false otherwise. * */ - virtual bool isRRect(const SkRect& rtBounds, SkRRect* rrect, bool* aa) const = 0; + virtual bool isRRect(const SkRect& rtBounds, SkRRect* rrect, GrAA* aa) const = 0; /** * This is the maximum distance that a draw may extend beyond a clip's boundary and still count @@ -140,7 +141,7 @@ private: bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip*) const final { return true; } - bool isRRect(const SkRect&, SkRRect*, bool*) const override { return false; } + bool isRRect(const SkRect&, SkRRect*, GrAA*) const override { return false; } }; #endif diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h index 9390d021a3..6cdc2de09c 100644 --- a/include/gpu/GrPaint.h +++ b/include/gpu/GrPaint.h @@ -30,10 +30,9 @@ * The primitive color computation starts with the color specified by setColor(). This color is the * input to the first color stage. Each color stage feeds its output to the next color stage. * - * Fractional pixel coverage follows a similar flow. The coverage is initially the value specified - * by setCoverage(). This is input to the first coverage stage. Coverage stages are chained - * together in the same manner as color stages. The output of the last stage is modulated by any - * fractional coverage produced by anti-aliasing. This last step produces the final coverage, C. + * Fractional pixel coverage follows a similar flow. The GrGeometryProcessor (specified elsewhere) + * provides the initial coverage which is passed to the first coverage fragment processor, which + * feeds its output to next coverage fragment processor. * * setXPFactory is used to control blending between the output color and dest. It also implements * the application of fractional coverage from the coverage pipeline. @@ -58,12 +57,6 @@ public: GrColor getColor() const { return fColor.toGrColor(); } /** - * Should primitives be anti-aliased or not. Defaults to false. - */ - void setAntiAlias(bool aa) { fAntiAlias = aa; } - bool isAntiAlias() const { return fAntiAlias; } - - /** * Should shader output conversion from linear to sRGB be disabled. * Only relevant if the destination is sRGB. Defaults to false. */ @@ -146,7 +139,6 @@ public: } GrPaint& operator=(const GrPaint& paint) { - fAntiAlias = paint.fAntiAlias; fDisableOutputConversionToSRGB = paint.fDisableOutputConversionToSRGB; fAllowSRGBInputs = paint.fAllowSRGBInputs; fUsesDistanceVectorField = paint.fUsesDistanceVectorField; @@ -185,7 +177,6 @@ private: SkSTArray<4, sk_sp<GrFragmentProcessor>> fColorFragmentProcessors; SkSTArray<2, sk_sp<GrFragmentProcessor>> fCoverageFragmentProcessors; - bool fAntiAlias; bool fDisableOutputConversionToSRGB; bool fAllowSRGBInputs; bool fUsesDistanceVectorField; diff --git a/include/gpu/GrRenderTargetContext.h b/include/gpu/GrRenderTargetContext.h index 3468528f57..afa1586d34 100644 --- a/include/gpu/GrRenderTargetContext.h +++ b/include/gpu/GrRenderTargetContext.h @@ -88,15 +88,17 @@ public: void drawPaint(const GrClip&, const GrPaint&, const SkMatrix& viewMatrix); /** - * Draw the rect using a paint. - * @param paint describes how to color pixels. - * @param viewMatrix transformation matrix - * @param style The style to apply. Null means fill. Currently path effects are not - * allowed. - * The rects coords are used to access the paint (through texture matrix) + * Draw the rect using a paint. + * @param paint describes how to color pixels. + * @param GrAA Controls whether rect is antialiased + * @param viewMatrix transformation matrix + * @param style The style to apply. Null means fill. Currently path effects are not + * allowed. + * The rects coords are used to access the paint (through texture matrix) */ void drawRect(const GrClip&, const GrPaint& paint, + GrAA, const SkMatrix& viewMatrix, const SkRect&, const GrStyle* style = nullptr); @@ -104,13 +106,15 @@ public: /** * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle. * - * @param paint describes how to color pixels. - * @param viewMatrix transformation matrix which applies to rectToDraw - * @param rectToDraw the rectangle to draw - * @param localRect the rectangle of shader coordinates applied to rectToDraw + * @param paint describes how to color pixels. + * @param GrAA Controls whether rect is antialiased + * @param viewMatrix transformation matrix which applies to rectToDraw + * @param rectToDraw the rectangle to draw + * @param localRect the rectangle of shader coordinates applied to rectToDraw */ void fillRectToRect(const GrClip&, const GrPaint& paint, + GrAA, const SkMatrix& viewMatrix, const SkRect& rectToDraw, const SkRect& localRect); @@ -120,33 +124,36 @@ public: */ void fillRectWithLocalMatrix(const GrClip& clip, const GrPaint& paint, + GrAA, const SkMatrix& viewMatrix, const SkRect& rect, const SkMatrix& localMatrix); /** - * Draw a roundrect using a paint. + * Draw a roundrect using a paint. * - * @param paint describes how to color pixels. - * @param viewMatrix transformation matrix - * @param rrect the roundrect to draw - * @param style style to apply to the rrect. Currently path effects are not allowed. + * @param paint describes how to color pixels. + * @param GrAA Controls whether rrect is antialiased. + * @param viewMatrix transformation matrix + * @param rrect the roundrect to draw + * @param style style to apply to the rrect. Currently path effects are not allowed. */ void drawRRect(const GrClip&, const GrPaint&, + GrAA, const SkMatrix& viewMatrix, const SkRRect& rrect, const GrStyle& style); /** - * Draw a roundrect using a paint and a shadow shader. This is separate from drawRRect - * because it uses different underlying geometry and GeometryProcessor + * Draw a roundrect using a paint and a shadow shader. This is separate from drawRRect + * because it uses different underlying geometry and GeometryProcessor * - * @param paint describes how to color pixels. - * @param viewMatrix transformation matrix - * @param rrect the roundrect to draw - * @param blurRadius amount of shadow blur to apply (in device space) - * @param style style to apply to the rrect. Currently path effects are not allowed. + * @param paint describes how to color pixels. + * @param viewMatrix transformation matrix + * @param rrect the roundrect to draw + * @param blurRadius amount of shadow blur to apply (in device space) + * @param style style to apply to the rrect. Currently path effects are not allowed. */ void drawShadowRRect(const GrClip&, const GrPaint&, @@ -156,17 +163,18 @@ public: const GrStyle& style); /** - * Shortcut for drawing an SkPath consisting of nested rrects using a paint. - * Does not support stroking. The result is undefined if outer does not contain - * inner. + * Shortcut for filling a SkPath consisting of nested rrects using a paint. The result is + * undefined if outer does not contain inner. * - * @param paint describes how to color pixels. - * @param viewMatrix transformation matrix - * @param outer the outer roundrect - * @param inner the inner roundrect + * @param paint describes how to color pixels. + * @param GrAA Controls whether rrects edges are antialiased + * @param viewMatrix transformation matrix + * @param outer the outer roundrect + * @param inner the inner roundrect */ void drawDRRect(const GrClip&, const GrPaint&, + GrAA, const SkMatrix& viewMatrix, const SkRRect& outer, const SkRRect& inner); @@ -175,12 +183,14 @@ public: * Draws a path. * * @param paint describes how to color pixels. + * @param GrAA Controls whether the path is antialiased. * @param viewMatrix transformation matrix * @param path the path to draw * @param style style to apply to the path. */ void drawPath(const GrClip&, const GrPaint&, + GrAA, const SkMatrix& viewMatrix, const SkPath&, const GrStyle& style); @@ -214,7 +224,8 @@ public: int indexCount); /** - * Draws textured sprites from an atlas with a paint. + * Draws textured sprites from an atlas with a paint. This currently does not support AA for the + * sprite rectangle edges. * * @param paint describes how to color pixels. * @param viewMatrix transformation matrix @@ -237,11 +248,13 @@ public: * * @param paint describes how to color pixels * @param viewMatrix transformation matrix + * @param aa should the rects of the region be antialiased. * @param region the region to be drawn * @param style style to apply to the region */ void drawRegion(const GrClip&, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRegion& region, const GrStyle& style); @@ -250,31 +263,35 @@ public: * Draws an oval. * * @param paint describes how to color pixels. + * @param GrAA Controls whether the oval is antialiased. * @param viewMatrix transformation matrix * @param oval the bounding rect of the oval. * @param style style to apply to the oval. Currently path effects are not allowed. */ void drawOval(const GrClip&, const GrPaint& paint, + GrAA, const SkMatrix& viewMatrix, const SkRect& oval, const GrStyle& style); - /** - * Draws a partial arc of an oval. - * - * @param paint describes how to color pixels. - * @param viewMatrix transformation matrix. - * @param oval the bounding rect of the oval. - * @param startAngle starting angle in degrees. - * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360) - * @param useCenter true means that the implied path begins at the oval center, connects as a - * line to the point indicated by the start contains the arc indicated by - * the sweep angle. If false the line beginning at the center point is - * omitted. - * @param style style to apply to the oval. - */ + /** + * Draws a partial arc of an oval. + * + * @param paint describes how to color pixels. + * @param GrGrAA Controls whether the arc is antialiased. + * @param viewMatrix transformation matrix. + * @param oval the bounding rect of the oval. + * @param startAngle starting angle in degrees. + * @param sweepAngle angle to sweep in degrees. Must be in (-360, 360) + * @param useCenter true means that the implied path begins at the oval center, connects as + * a line to the point indicated by the start contains the arc indicated by + * the sweep angle. If false the line beginning at the center point is + * omitted. + * @param style style to apply to the oval. + */ void drawArc(const GrClip&, const GrPaint& paint, + GrAA, const SkMatrix& viewMatrix, const SkRect& oval, SkScalar startAngle, @@ -333,10 +350,6 @@ public: bool isUnifiedMultisampled() const { return fRenderTargetProxy->isUnifiedMultisampled(); } bool hasMixedSamples() const { return fRenderTargetProxy->isMixedSampled(); } - bool mustUseHWAA(const GrPaint& paint) const { - return paint.isAntiAlias() && fRenderTargetProxy->isUnifiedMultisampled(); - } - const GrCaps* caps() const { return fContext->caps(); } const GrSurfaceDesc& desc() const { return fRenderTargetProxy->desc(); } int width() const { return fRenderTargetProxy->width(); } @@ -388,6 +401,19 @@ protected: SkDEBUGCODE(void validate() const;) private: + inline GrAAType decideAAType(GrAA aa, bool allowMixedSamples = false) { + if (GrAA::kNo == aa) { + return GrAAType::kNone; + } + if (this->isUnifiedMultisampled()) { + return GrAAType::kMSAA; + } + if (allowMixedSamples && this->isStencilBufferMultisampled()) { + return GrAAType::kMixedSamples; + } + return GrAAType::kCoverage; + } + friend class GrAtlasTextBlob; // for access to addDrawOp friend class GrStencilAndCoverTextContext; // for access to addDrawOp @@ -413,12 +439,14 @@ private: bool drawFilledDRRect(const GrClip& clip, const GrPaint& paint, + GrAA, const SkMatrix& viewMatrix, const SkRRect& origOuter, const SkRRect& origInner); bool drawFilledRect(const GrClip& clip, const GrPaint& paint, + GrAA, const SkMatrix& viewMatrix, const SkRect& rect, const GrUserStencilSettings* ss); @@ -430,13 +458,14 @@ private: const SkRect* localRect, const SkMatrix* localMatrix, const GrUserStencilSettings* ss, - bool useHWAA); - - void internalDrawPath(const GrClip& clip, - const GrPaint& paint, - const SkMatrix& viewMatrix, - const SkPath& path, - const GrStyle& style); + GrAAType hwOrNoneAAType); + + void internalDrawPath(const GrClip&, + const GrPaint&, + GrAA, + const SkMatrix&, + const SkPath&, + const GrStyle&); // This entry point allows the GrTextContext-derived classes to add their ops to the GrOpList. void addDrawOp(const GrPipelineBuilder&, const GrClip&, GrDrawOp*); diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index 846537a546..86e83f93e8 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -149,6 +149,18 @@ typedef intptr_t GrBackendContext; /////////////////////////////////////////////////////////////////////////////// /** + * Used to control antialiasing in draw calls. + */ +enum class GrAA { + kYes, + kNo +}; + +static inline GrAA GrBoolToAA(bool aa) { return aa ? GrAA::kYes : GrAA::kNo; } + +/////////////////////////////////////////////////////////////////////////////// + +/** * Geometric primitives used for drawing. */ enum GrPrimitiveType { diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h index 51dccc5f7d..53e71e74ab 100644 --- a/include/gpu/GrTypesPriv.h +++ b/include/gpu/GrTypesPriv.h @@ -11,6 +11,21 @@ #include "GrTypes.h" #include "SkRefCnt.h" +/** This enum indicates the type of antialiasing to be performed. */ +enum class GrAAType { + /** No antialiasing */ + kNone, + /** Use fragment shader code to compute a fractional pixel coverage. */ + kCoverage, + /** Use normal MSAA. */ + kMSAA, + /** + * Use "mixed samples" MSAA such that the stencil buffer is multisampled but the color buffer is + * not. + */ + kMixedSamples +}; + /** * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars, * but should be applicable to other shader languages.) |