blob: be6873edd98db2f467ca86a84355f94ba71e15b5 [file] [log] [blame]
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef GrClipMaskManager_DEFINED
10#define GrClipMaskManager_DEFINED
11
12#include "GrRect.h"
bsalomon@google.com8d033a12012-04-27 15:52:53 +000013#include "SkPath.h"
robertphillips@google.com1e945b72012-04-16 18:03:03 +000014
15class GrGpu;
16class GrClip;
17class GrPathRenderer;
18class GrPathRendererChain;
19class SkPath;
robertphillips@google.comf294b772012-04-27 14:29:26 +000020class GrTexture;
21class GrDrawState;
robertphillips@google.com1e945b72012-04-16 18:03:03 +000022
23/**
24 * Scissoring needs special handling during stencil clip mask creation
25 * since the creation process re-entrantly invokes setupClipAndFlushState.
26 * During this process the call stack is used to keep
27 * track of (and apply to the GPU) the current scissor settings.
28 */
29struct ScissoringSettings {
30 bool fEnableScissoring;
31 GrIRect fScissorRect;
32
33 void setupScissoring(GrGpu* gpu);
34};
35
36
37/**
38 * The clip mask creator handles the generation of the clip mask. If anti
39 * aliasing is requested it will (in the future) generate a single channel
40 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit
41 * mask in the stencil buffer. In the non anti-aliasing case, if the clip
42 * mask can be represented as a rectangle then scissoring is used. In all
43 * cases scissoring is used to bound the range of the clip mask.
44 */
45class GrClipMaskManager {
46public:
47 GrClipMaskManager()
48 : fClipMaskInStencil(false)
robertphillips@google.comf294b772012-04-27 14:29:26 +000049 , fClipMaskInAlpha(false)
robertphillips@google.com1e945b72012-04-16 18:03:03 +000050 , fPathRendererChain(NULL) {
51 }
52
53 bool createClipMask(GrGpu* gpu,
54 const GrClip& clip,
55 ScissoringSettings* scissorSettings);
56
57 void freeResources();
58
59 bool isClipInStencil() const { return fClipMaskInStencil; }
robertphillips@google.comf294b772012-04-27 14:29:26 +000060 bool isClipInAlpha() const { return fClipMaskInAlpha; }
robertphillips@google.com1e945b72012-04-16 18:03:03 +000061
62 void resetMask() {
63 fClipMaskInStencil = false;
64 }
65
66protected:
67private:
68 bool fClipMaskInStencil; // is the clip mask in the stencil buffer?
robertphillips@google.comf294b772012-04-27 14:29:26 +000069 bool fClipMaskInAlpha; // is the clip mask in an alpha texture?
robertphillips@google.com1e945b72012-04-16 18:03:03 +000070
71 // must be instantiated after GrGpu object has been given its owning
72 // GrContext ptr. (GrGpu is constructed first then handed off to GrContext).
73 GrPathRendererChain* fPathRendererChain;
74
75 bool createStencilClipMask(GrGpu* gpu,
76 const GrClip& clip,
77 const GrRect& bounds,
78 ScissoringSettings* scissorSettings);
robertphillips@google.coma72eef32012-05-01 17:22:59 +000079 bool createAlphaClipMask(GrGpu* gpu,
80 const GrClip& clipIn,
81 GrTexture** result,
82 GrRect *resultBounds);
robertphillips@google.comf294b772012-04-27 14:29:26 +000083
84 bool drawPath(GrGpu* gpu,
bsalomon@google.com8d033a12012-04-27 15:52:53 +000085 const SkPath& path,
robertphillips@google.comf294b772012-04-27 14:29:26 +000086 GrPathFill fill,
87 bool doAA);
88
89 bool drawClipShape(GrGpu* gpu,
90 GrTexture* target,
91 const GrClip& clipIn,
92 int index);
93
94 void drawTexture(GrGpu* gpu,
95 GrTexture* target,
96 const GrRect& rect,
97 GrTexture* texture);
robertphillips@google.com1e945b72012-04-16 18:03:03 +000098
99 // determines the path renderer used to draw a clip path element.
100 GrPathRenderer* getClipPathRenderer(GrGpu* gpu,
101 const SkPath& path,
robertphillips@google.comf294b772012-04-27 14:29:26 +0000102 GrPathFill fill,
103 bool antiAlias);
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000104
105};
106
107#endif // GrClipMaskManager_DEFINED