blob: e69879167779fc28a519a7686769d163cdd48b5d [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.comf294b772012-04-27 14:29:26 +000079 bool createAlphaClipMask(GrGpu* gpu, const GrClip& clipIn);
80
81 bool drawPath(GrGpu* gpu,
bsalomon@google.com8d033a12012-04-27 15:52:53 +000082 const SkPath& path,
robertphillips@google.comf294b772012-04-27 14:29:26 +000083 GrPathFill fill,
84 bool doAA);
85
86 bool drawClipShape(GrGpu* gpu,
87 GrTexture* target,
88 const GrClip& clipIn,
89 int index);
90
91 void drawTexture(GrGpu* gpu,
92 GrTexture* target,
93 const GrRect& rect,
94 GrTexture* texture);
robertphillips@google.com1e945b72012-04-16 18:03:03 +000095
96 // determines the path renderer used to draw a clip path element.
97 GrPathRenderer* getClipPathRenderer(GrGpu* gpu,
98 const SkPath& path,
robertphillips@google.comf294b772012-04-27 14:29:26 +000099 GrPathFill fill,
100 bool antiAlias);
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000101
102};
103
104#endif // GrClipMaskManager_DEFINED