blob: 8ecba09fba3dd014423a718c98306f84d9a91c0f [file] [log] [blame]
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001/*
2 * Copyright 2012 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 */
robertphillips@google.com1e945b72012-04-16 18:03:03 +00007#ifndef GrClipMaskManager_DEFINED
8#define GrClipMaskManager_DEFINED
9
egdaniel8dd688b2015-01-22 10:16:09 -080010#include "GrPipelineBuilder.h"
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000011#include "GrReducedClip.h"
bsalomon@google.com411dad02012-06-05 20:24:20 +000012#include "GrTexture.h"
robertphillips@google.com641f8b12012-07-31 19:15:58 +000013#include "SkClipStack.h"
bsalomon@google.com411dad02012-06-05 20:24:20 +000014#include "SkDeque.h"
15#include "SkPath.h"
16#include "SkRefCnt.h"
bsalomon@google.com8182fa02012-12-04 14:06:06 +000017#include "SkTLList.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000018#include "SkTypes.h"
robertphillips@google.com1fcc1b82012-08-29 12:52:05 +000019
cdalton846c0512016-05-13 10:25:00 -070020class GrAppliedClip;
21class GrClipStackClip;
bsalomonb3b9aec2015-09-10 11:16:35 -070022class GrDrawTarget;
robertphillips@google.com1e945b72012-04-16 18:03:03 +000023class GrPathRenderer;
24class GrPathRendererChain;
robertphillips544b9aa2015-10-28 11:01:41 -070025class GrResourceProvider;
robertphillips@google.comf294b772012-04-27 14:29:26 +000026class GrTexture;
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000027class SkPath;
bsalomon0ba8c242015-10-07 09:20:28 -070028
29/**
rmistry@google.comd6176b02012-08-23 18:14:13 +000030 * The clip mask creator handles the generation of the clip mask. If anti
31 * aliasing is requested it will (in the future) generate a single channel
32 * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit
robertphillips@google.com1e945b72012-04-16 18:03:03 +000033 * mask in the stencil buffer. In the non anti-aliasing case, if the clip
34 * mask can be represented as a rectangle then scissoring is used. In all
35 * cases scissoring is used to bound the range of the clip mask.
36 */
commit-bot@chromium.orge3beb6b2014-04-07 19:34:38 +000037class GrClipMaskManager : SkNoncopyable {
robertphillips@google.com1e945b72012-04-16 18:03:03 +000038public:
cdalton846c0512016-05-13 10:25:00 -070039 GrClipMaskManager(GrDrawTarget* owner) : fDrawTarget(owner) {}
robertphillips@google.com1e945b72012-04-16 18:03:03 +000040
bsalomon@google.coma3201942012-06-21 19:58:20 +000041 /**
42 * Creates a clip mask if necessary as a stencil buffer or alpha texture
43 * and sets the GrGpu's scissor and stencil state. If the return is false
cdalton93a379b2016-05-11 13:58:08 -070044 * then the draw can be skipped. devBounds is optional but can help optimize
45 * clipping.
bsalomon@google.coma3201942012-06-21 19:58:20 +000046 */
cdalton846c0512016-05-13 10:25:00 -070047 bool setupClipping(const GrPipelineBuilder&, const GrClipStackClip&, const SkRect* devBounds,
cdalton862cff32016-05-12 15:09:48 -070048 GrAppliedClip*);
robertphillips391395d2016-03-02 09:26:36 -080049
bsalomon@google.coma3201942012-06-21 19:58:20 +000050private:
bsalomonedd77a12015-05-29 09:45:57 -070051 inline GrContext* getContext();
robertphillips544b9aa2015-10-28 11:01:41 -070052 inline const GrCaps* caps() const;
53 inline GrResourceProvider* resourceProvider();
bsalomonedd77a12015-05-29 09:45:57 -070054
robertphillips68737822015-10-29 12:12:21 -070055 static bool PathNeedsSWRenderer(GrContext* context,
cdalton93a379b2016-05-11 13:58:08 -070056 bool hasUserStencilSettings,
robertphillips68737822015-10-29 12:12:21 -070057 const GrRenderTarget* rt,
58 const SkMatrix& viewMatrix,
59 const SkClipStack::Element* element,
60 GrPathRenderer** prOut,
61 bool needsStencil);
62 static GrPathRenderer* GetPathRenderer(GrContext* context,
63 GrTexture* texture,
64 const SkMatrix& viewMatrix,
65 const SkClipStack::Element* element);
66
commit-bot@chromium.orge5a041c2014-03-07 19:43:43 +000067 // Attempts to install a series of coverage effects to implement the clip. Return indicates
bsalomon0b5b6b22015-10-14 08:31:34 -070068 // whether the element list was successfully converted to processors. *fp may be nullptr even
69 // when the function succeeds because all the elements were ignored. TODO: Make clip reduction
bsalomona912dde2015-10-14 15:01:50 -070070 // bounds-aware and stop checking bounds in this function. Similarly, we shouldn't need to pass
71 // abortIfAA, but we don't yet know if all the AA elements will be eliminated.
bsalomon0b5b6b22015-10-14 08:31:34 -070072 bool getAnalyticClipProcessor(const GrReducedClip::ElementList&,
bsalomona912dde2015-10-14 15:01:50 -070073 bool abortIfAA,
bsalomon0b5b6b22015-10-14 08:31:34 -070074 SkVector& clipOffset,
75 const SkRect* devBounds,
76 const GrFragmentProcessor** fp);
commit-bot@chromium.orge5a041c2014-03-07 19:43:43 +000077
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000078 // Draws the clip into the stencil buffer
joshualitt9853cce2014-11-17 14:22:48 -080079 bool createStencilClipMask(GrRenderTarget*,
80 int32_t elementsGenID,
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +000081 GrReducedClip::InitialState initialState,
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000082 const GrReducedClip::ElementList& elements,
83 const SkIRect& clipSpaceIBounds,
84 const SkIPoint& clipSpaceToStencilOffset);
joshualitt9853cce2014-11-17 14:22:48 -080085
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000086 // Creates an alpha mask of the clip. The mask is a rasterization of elements through the
87 // rect specified by clipSpaceIBounds.
robertphillipsc99b8f02016-05-15 07:53:35 -070088 static sk_sp<GrTexture> CreateAlphaClipMask(GrContext*,
89 int32_t elementsGenID,
90 GrReducedClip::InitialState initialState,
91 const GrReducedClip::ElementList& elements,
92 const SkVector& clipToMaskOffset,
93 const SkIRect& clipSpaceIBounds);
joshualitt9853cce2014-11-17 14:22:48 -080094
bsalomon@google.com4c2443e2012-12-06 20:58:57 +000095 // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture.
robertphillipsc99b8f02016-05-15 07:53:35 -070096 static sk_sp<GrTexture> CreateSoftwareClipMask(GrContext*,
97 int32_t elementsGenID,
98 GrReducedClip::InitialState initialState,
99 const GrReducedClip::ElementList& elements,
100 const SkVector& clipToMaskOffset,
101 const SkIRect& clipSpaceIBounds);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000102
robertphillips391395d2016-03-02 09:26:36 -0800103 static bool UseSWOnlyPath(GrContext*,
104 const GrPipelineBuilder&,
105 const GrRenderTarget* rt,
106 const SkVector& clipToMaskOffset,
107 const GrReducedClip::ElementList& elements);
bsalomon@google.comb68addd2012-12-14 13:36:53 +0000108
bsalomon473addf2015-10-02 07:49:05 -0700109 GrTexture* createCachedMask(int width, int height, const GrUniqueKey& key, bool renderTarget);
110
bsalomon0ba8c242015-10-07 09:20:28 -0700111 static const int kMaxAnalyticElements = 4;
112
bsalomonb3b9aec2015-09-10 11:16:35 -0700113 GrDrawTarget* fDrawTarget; // This is our owning draw target.
joshualitt329bf482014-10-29 12:31:28 -0700114
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000115 typedef SkNoncopyable INHERITED;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000116};
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000117#endif // GrClipMaskManager_DEFINED