#include "SkTLList.h"
#include "SkTypes.h"
-class GrGpu;
+class GrClipTarget;
class GrPathRenderer;
class GrPathRendererChain;
class GrTexture;
* mask can be represented as a rectangle then scissoring is used. In all
* cases scissoring is used to bound the range of the clip mask.
*/
-class GrClipMaskManager : public SkNoncopyable {
+class GrClipMaskManager : SkNoncopyable {
public:
GrClipMaskManager()
- : fGpu(NULL)
- , fCurrClipMaskType(kNone_ClipMaskType) {
+ : fCurrClipMaskType(kNone_ClipMaskType)
+ , fClipTarget(NULL)
+ , fClipMode(kIgnoreClip_StencilClipMode) {
}
+ // The state of the scissor is controlled by the clip manager, no one else should set
+ // Scissor state. This should really be on Gpu itself. We should revist this when GPU
+ // and drawtarget are separate
+ struct ScissorState {
+ ScissorState() : fEnabled(false) {}
+ void set(const SkIRect& rect) { fRect = rect; fEnabled = true; }
+ bool fEnabled;
+ SkIRect fRect;
+ };
+
/**
* Creates a clip mask if necessary as a stencil buffer or alpha texture
* and sets the GrGpu's scissor and stencil state. If the return is false
* the manager when it must install additional effects to implement the
* clip. devBounds is optional but can help optimize clipping.
*/
- bool setupClipping(const GrClipData* clipDataIn, GrDrawState::AutoRestoreEffects*,
- const SkRect* devBounds);
+ bool setupClipping(const GrClipData* clipDataIn,
+ const SkRect* devBounds,
+ GrDrawState::AutoRestoreEffects*,
+ GrDrawState::AutoRestoreStencil*,
+ ScissorState*);
- void releaseResources();
+ /**
+ * Purge resources to free up memory. TODO: This class shouldn't hold any long lived refs
+ * which will allow ResourceCache2 to automatically purge anything this class has created.
+ */
+ void purgeResources();
bool isClipInStencil() const {
return kStencil_ClipMaskType == fCurrClipMaskType;
return kAlpha_ClipMaskType == fCurrClipMaskType;
}
- void invalidateStencilMask() {
- if (kStencil_ClipMaskType == fCurrClipMaskType) {
- fCurrClipMaskType = kNone_ClipMaskType;
- }
- }
-
GrContext* getContext() {
return fAACache.getContext();
}
- void setGpu(GrGpu* gpu);
+ void setClipTarget(GrClipTarget*);
+
+ void adjustPathStencilParams(GrStencilSettings*);
- void adjustPathStencilParams(GrStencilSettings* settings);
private:
/**
* Informs the helper function adjustStencilParams() about how the stencil
kIgnoreClip_StencilClipMode,
};
- GrGpu* fGpu;
-
- /**
- * We may represent the clip as a mask in the stencil buffer or as an alpha
- * texture. It may be neither because the scissor rect suffices or we
- * haven't yet examined the clip.
- */
- enum ClipMaskType {
- kNone_ClipMaskType,
- kStencil_ClipMaskType,
- kAlpha_ClipMaskType,
- } fCurrClipMaskType;
-
- GrClipMaskCache fAACache; // cache for the AA path
-
// Attempts to install a series of coverage effects to implement the clip. Return indicates
// whether the element list was successfully converted to effects.
bool installClipEffects(const GrReducedClip::ElementList&,
const GrReducedClip::ElementList& elements,
const SkIRect& clipSpaceIBounds);
- // Gets a texture to use for the clip mask. If true is returned then a cached mask was found
- // that already contains the rasterization of the clip stack, otherwise an uninitialized texture
- // is returned. 'willUpload' is set when the alpha mask needs to be uploaded from the CPU.
- bool getMaskTexture(int32_t elementsGenID,
- const SkIRect& clipSpaceIBounds,
- GrTexture** result,
- bool willUpload);
+ // Returns the cached mask texture if it matches the elementsGenID and the clipSpaceIBounds.
+ // Returns NULL if not found.
+ GrTexture* getCachedMaskTexture(int32_t elementsGenID, const SkIRect& clipSpaceIBounds);
+
+
+ // Handles allocation (if needed) of a clip alpha-mask texture for both the sw-upload
+ // or gpu-rendered cases.
+ GrTexture* allocMaskTexture(int32_t elementsGenID,
+ const SkIRect& clipSpaceIBounds,
+ bool willUpload);
bool useSWOnlyPath(const GrReducedClip::ElementList& elements);
const SkIRect& dstBound,
const SkIRect& srcBound);
- void getTemp(int width, int height, GrAutoScratchTexture* temp);
+ GrTexture* createTempMask(int width, int height);
void setupCache(const SkClipStack& clip,
const SkIRect& bounds);
* updates the GrGpu with stencil settings that account stencil-based
* clipping.
*/
- void setGpuStencil();
+ void setDrawStateStencil(GrDrawState::AutoRestoreStencil* asr);
/**
* Adjusts the stencil settings to account for interaction with stencil
StencilClipMode mode,
int stencilBitCnt);
+ /**
+ * We may represent the clip as a mask in the stencil buffer or as an alpha
+ * texture. It may be neither because the scissor rect suffices or we
+ * haven't yet examined the clip.
+ */
+ enum ClipMaskType {
+ kNone_ClipMaskType,
+ kStencil_ClipMaskType,
+ kAlpha_ClipMaskType,
+ } fCurrClipMaskType;
+
+ GrClipMaskCache fAACache; // cache for the AA path
+ GrClipTarget* fClipTarget;
+ StencilClipMode fClipMode;
+
typedef SkNoncopyable INHERITED;
};