Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2016 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 GrRenderTargetContextPriv_DEFINED
      9 #define GrRenderTargetContextPriv_DEFINED
     10 
     11 #include "GrRenderTargetContext.h"
     12 #include "GrRenderTargetOpList.h"
     13 #include "GrPathRendering.h"
     14 
     15 class GrFixedClip;
     16 class GrHardClip;
     17 class GrPath;
     18 class GrRenderTargetPriv;
     19 struct GrUserStencilSettings;
     20 
     21 /** Class that adds methods to GrRenderTargetContext that are only intended for use internal to
     22     Skia. This class is purely a privileged window into GrRenderTargetContext. It should never have
     23     additional data members or virtual methods. */
     24 class GrRenderTargetContextPriv {
     25 public:
     26     // called to note the last clip drawn to the stencil buffer.
     27     // TODO: remove after clipping overhaul.
     28     void setLastClip(uint32_t clipStackGenID, const SkIRect& devClipBounds,
     29                      int numClipAnalyticFPs) {
     30         GrRenderTargetOpList* opList = fRenderTargetContext->getRTOpList();
     31         opList->fLastClipStackGenID = clipStackGenID;
     32         opList->fLastDevClipBounds = devClipBounds;
     33         opList->fLastClipNumAnalyticFPs = numClipAnalyticFPs;
     34     }
     35 
     36     // called to determine if we have to render the clip into SB.
     37     // TODO: remove after clipping overhaul.
     38     bool mustRenderClip(uint32_t clipStackGenID, const SkIRect& devClipBounds,
     39                         int numClipAnalyticFPs) const {
     40         GrRenderTargetOpList* opList = fRenderTargetContext->getRTOpList();
     41         return opList->fLastClipStackGenID != clipStackGenID ||
     42                !opList->fLastDevClipBounds.contains(devClipBounds) ||
     43                opList->fLastClipNumAnalyticFPs != numClipAnalyticFPs;
     44     }
     45 
     46     using CanClearFullscreen = GrRenderTargetContext::CanClearFullscreen;
     47 
     48     void clear(const GrFixedClip&, const GrColor, CanClearFullscreen);
     49 
     50     void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
     51 
     52     /*
     53      * Some portions of the code, which use approximate-match rendertargets (i.e., ImageFilters),
     54      * rely on clears that lie outside of the content region to still have an effect.
     55      * For example, when sampling a decimated blurred image back up to full size, the GaussianBlur
     56      * code draws 1-pixel rects along the left and bottom edges to be able to use bilerp for
     57      * upsampling. The "absClear" entry point ignores the content bounds but does use the
     58      * worst case (instantiated) bounds.
     59      *
     60      * @param rect      if (!null) the rect to clear, otherwise it is a full screen clear
     61      * @param color     the color to clear to
     62      */
     63     void absClear(const SkIRect* rect, const GrColor color);
     64 
     65     void stencilRect(const GrHardClip&,
     66                      const GrUserStencilSettings* ss,
     67                      GrAAType,
     68                      const SkMatrix& viewMatrix,
     69                      const SkRect& rect);
     70 
     71     void stencilPath(const GrHardClip&, GrAAType, const SkMatrix& viewMatrix, const GrPath*);
     72 
     73     /**
     74      * Draws a rect, either AA or not, and touches the stencil buffer with the user stencil settings
     75      * for each color sample written.
     76      */
     77     bool drawAndStencilRect(const GrHardClip&,
     78                             const GrUserStencilSettings*,
     79                             SkRegion::Op op,
     80                             bool invert,
     81                             GrAA,
     82                             const SkMatrix& viewMatrix,
     83                             const SkRect&);
     84 
     85     /**
     86      * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings
     87      * for each color sample written.
     88      */
     89     bool drawAndStencilPath(const GrHardClip&,
     90                             const GrUserStencilSettings*,
     91                             SkRegion::Op op,
     92                             bool invert,
     93                             GrAA,
     94                             const SkMatrix& viewMatrix,
     95                             const SkPath&);
     96 
     97     SkBudgeted isBudgeted() const;
     98 
     99     int maxWindowRectangles() const;
    100 
    101     /*
    102      * This unique ID will not change for a given RenderTargetContext. However, it is _NOT_
    103      * guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
    104      */
    105     GrSurfaceProxy::UniqueID uniqueID() const {
    106         return fRenderTargetContext->fRenderTargetProxy->uniqueID();
    107     }
    108 
    109     uint32_t testingOnly_getOpListID();
    110     uint32_t testingOnly_addDrawOp(std::unique_ptr<GrDrawOp>);
    111     uint32_t testingOnly_addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>);
    112 
    113     bool refsWrappedObjects() const {
    114         return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
    115     }
    116 
    117 private:
    118     explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
    119         : fRenderTargetContext(renderTargetContext) {}
    120     GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
    121     GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
    122 
    123     // No taking addresses of this type.
    124     const GrRenderTargetContextPriv* operator&() const;
    125     GrRenderTargetContextPriv* operator&();
    126 
    127     GrRenderTargetContext* fRenderTargetContext;
    128 
    129     friend class GrRenderTargetContext; // to construct/copy this type.
    130 };
    131 
    132 inline GrRenderTargetContextPriv GrRenderTargetContext::priv() {
    133     return GrRenderTargetContextPriv(this);
    134 }
    135 
    136 inline const GrRenderTargetContextPriv GrRenderTargetContext::priv() const {
    137     return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
    138 }
    139 
    140 #endif
    141