blob: d3f0d159e9807218ca117546eb5776793178f892 [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"
13
14class GrGpu;
15class GrClip;
16class GrPathRenderer;
17class GrPathRendererChain;
18class SkPath;
19
20/**
21 * Scissoring needs special handling during stencil clip mask creation
22 * since the creation process re-entrantly invokes setupClipAndFlushState.
23 * During this process the call stack is used to keep
24 * track of (and apply to the GPU) the current scissor settings.
25 */
26struct ScissoringSettings {
27 bool fEnableScissoring;
28 GrIRect fScissorRect;
29
30 void setupScissoring(GrGpu* gpu);
31};
32
33
34/**
35 * The clip mask creator handles the generation of the clip mask. If anti
36 * aliasing is requested it will (in the future) generate a single channel
37 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit
38 * mask in the stencil buffer. In the non anti-aliasing case, if the clip
39 * mask can be represented as a rectangle then scissoring is used. In all
40 * cases scissoring is used to bound the range of the clip mask.
41 */
42class GrClipMaskManager {
43public:
44 GrClipMaskManager()
45 : fClipMaskInStencil(false)
46 , fPathRendererChain(NULL) {
47 }
48
49 bool createClipMask(GrGpu* gpu,
50 const GrClip& clip,
51 ScissoringSettings* scissorSettings);
52
53 void freeResources();
54
55 bool isClipInStencil() const { return fClipMaskInStencil; }
56
57 void resetMask() {
58 fClipMaskInStencil = false;
59 }
60
61protected:
62private:
63 bool fClipMaskInStencil; // is the clip mask in the stencil buffer?
64
65 // must be instantiated after GrGpu object has been given its owning
66 // GrContext ptr. (GrGpu is constructed first then handed off to GrContext).
67 GrPathRendererChain* fPathRendererChain;
68
69 bool createStencilClipMask(GrGpu* gpu,
70 const GrClip& clip,
71 const GrRect& bounds,
72 ScissoringSettings* scissorSettings);
73
74 // determines the path renderer used to draw a clip path element.
75 GrPathRenderer* getClipPathRenderer(GrGpu* gpu,
76 const SkPath& path,
77 GrPathFill fill);
78
79};
80
81#endif // GrClipMaskManager_DEFINED