| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright 2010 Google Inc. |    2  * Copyright 2010 Google Inc. | 
|    3  * |    3  * | 
|    4  * Use of this source code is governed by a BSD-style license that can be |    4  * Use of this source code is governed by a BSD-style license that can be | 
|    5  * found in the LICENSE file. |    5  * found in the LICENSE file. | 
|    6  */ |    6  */ | 
|    7  |    7  | 
|    8 #ifndef GrDrawTarget_DEFINED |    8 #ifndef GrDrawTarget_DEFINED | 
|    9 #define GrDrawTarget_DEFINED |    9 #define GrDrawTarget_DEFINED | 
|   10  |   10  | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|   30 #include "SkXfermode.h" |   30 #include "SkXfermode.h" | 
|   31  |   31  | 
|   32 class GrBatch; |   32 class GrBatch; | 
|   33 class GrClip; |   33 class GrClip; | 
|   34 class GrCaps; |   34 class GrCaps; | 
|   35 class GrPath; |   35 class GrPath; | 
|   36 class GrDrawBatch; |   36 class GrDrawBatch; | 
|   37 class GrDrawPathBatchBase; |   37 class GrDrawPathBatchBase; | 
|   38 class GrPathRangeDraw; |   38 class GrPathRangeDraw; | 
|   39  |   39  | 
|   40 class GrDrawTarget : public SkRefCnt { |   40 class GrDrawTarget final : public SkRefCnt { | 
|   41 public: |   41 public: | 
|   42     // The context may not be fully constructed and should not be used during Gr
     DrawTarget |   42     // The context may not be fully constructed and should not be used during Gr
     DrawTarget | 
|   43     // construction. |   43     // construction. | 
|   44     GrDrawTarget(GrGpu* gpu, GrResourceProvider*); |   44     GrDrawTarget(GrGpu* gpu, GrResourceProvider*); | 
|   45  |   45  | 
|   46     ~GrDrawTarget() override; |   46     ~GrDrawTarget() override; | 
|   47  |   47  | 
|   48     /** |   48     /** | 
|   49      * Empties the draw buffer of any queued up draws. |   49      * Empties the draw buffer of any queued up draws. | 
|   50      */ |   50      */ | 
|   51     void reset(); |   51     void reset(); | 
|   52  |   52  | 
|   53     /** |   53     /** | 
|   54      * This plays any queued up draws to its GrGpu target. It also resets this o
     bject (i.e. flushing |   54      * This plays any queued up draws to its GrGpu target. It also resets this o
     bject (i.e. flushing | 
|   55      * is destructive). |   55      * is destructive). | 
|   56      */ |   56      */ | 
|   57     void flush(); |   57     void flush(); | 
|   58  |   58  | 
|   59     /** |   59     /** | 
|   60      * Gets the capabilities of the draw target. |   60      * Gets the capabilities of the draw target. | 
|   61      */ |   61      */ | 
|   62     const GrCaps* caps() const { return fCaps; } |   62     const GrCaps* caps() const { return fGpu->caps(); } | 
|   63  |   63  | 
|   64     void drawBatch(const GrPipelineBuilder&, GrDrawBatch*); |   64     void drawBatch(const GrPipelineBuilder&, GrDrawBatch*); | 
|   65  |   65  | 
|   66     /** |   66     /** | 
|   67      * Draws path into the stencil buffer. The fill must be either even/odd or |   67      * Draws path into the stencil buffer. The fill must be either even/odd or | 
|   68      * winding (not inverse or hairline). It will respect the HW antialias flag |   68      * winding (not inverse or hairline). It will respect the HW antialias flag | 
|   69      * on the GrPipelineBuilder (if possible in the 3D API).  Note, we will neve
     r have an inverse |   69      * on the GrPipelineBuilder (if possible in the 3D API).  Note, we will neve
     r have an inverse | 
|   70      * fill with stencil path |   70      * fill with stencil path | 
|   71      */ |   71      */ | 
|   72     void stencilPath(const GrPipelineBuilder&, const SkMatrix& viewMatrix, const
      GrPath*, |   72     void stencilPath(const GrPipelineBuilder&, const SkMatrix& viewMatrix, const
      GrPath*, | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  165      * depending on the type of surface, configs, etc, and the backend-specific |  165      * depending on the type of surface, configs, etc, and the backend-specific | 
|  166      * limitations. |  166      * limitations. | 
|  167      */ |  167      */ | 
|  168     void copySurface(GrSurface* dst, |  168     void copySurface(GrSurface* dst, | 
|  169                      GrSurface* src, |  169                      GrSurface* src, | 
|  170                      const SkIRect& srcRect, |  170                      const SkIRect& srcRect, | 
|  171                      const SkIPoint& dstPoint); |  171                      const SkIPoint& dstPoint); | 
|  172     /** |  172     /** | 
|  173      * Release any resources that are cached but not currently in use. This |  173      * Release any resources that are cached but not currently in use. This | 
|  174      * is intended to give an application some recourse when resources are low. |  174      * is intended to give an application some recourse when resources are low. | 
 |  175      * TODO: Stop holding on to resources. | 
|  175      */ |  176      */ | 
|  176     virtual void purgeResources() {}; |  177     virtual void purgeResources() { | 
 |  178         // The clip mask manager can rebuild all its clip masks so just get rid 
     of them all. | 
 |  179         fClipMaskManager->purgeResources(); | 
 |  180     }; | 
|  177  |  181  | 
|  178     bool programUnitTest(GrContext* owner, int maxStages); |  182     bool programUnitTest(GrContext* owner, int maxStages); | 
|  179  |  183  | 
|  180 protected: |  184     /** Provides access to internal functions to GrClipMaskManager without frien
     ding all of | 
|  181     GrGpu* getGpu() { return fGpu; } |  185         GrDrawTarget to CMM. */ | 
|  182     const GrGpu* getGpu() const { return fGpu; } |  186     class CMMAccess { | 
 |  187     public: | 
 |  188         CMMAccess(GrDrawTarget* drawTarget) : fDrawTarget(drawTarget) {} | 
 |  189     private: | 
 |  190         void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarg
     et* rt) const { | 
 |  191             fDrawTarget->clearStencilClip(rect, insideClip, rt); | 
 |  192         } | 
|  183  |  193  | 
|  184     void recordBatch(GrBatch*); |  194         GrContext* context() const { return fDrawTarget->fContext; } | 
 |  195         GrResourceProvider* resourceProvider() const { return fDrawTarget->fReso
     urceProvider; } | 
 |  196         GrDrawTarget* fDrawTarget; | 
 |  197         friend class GrClipMaskManager; | 
 |  198     }; | 
 |  199  | 
 |  200     const CMMAccess cmmAccess() { return CMMAccess(this); } | 
|  185  |  201  | 
|  186 private: |  202 private: | 
|  187     SkSTArray<256, SkAutoTUnref<GrBatch>, true> fBatches; |  203     void recordBatch(GrBatch*); | 
|  188  |  | 
|  189     bool installPipelineInDrawBatch(const GrPipelineBuilder* pipelineBuilder, |  204     bool installPipelineInDrawBatch(const GrPipelineBuilder* pipelineBuilder, | 
|  190                                     const GrScissorState* scissor, |  205                                     const GrScissorState* scissor, | 
|  191                                     GrDrawBatch* batch); |  206                                     GrDrawBatch* batch); | 
|  192  |  207  | 
|  193     // Makes a copy of the dst if it is necessary for the draw. Returns false if
      a copy is required |  208     // Makes a copy of the dst if it is necessary for the draw. Returns false if
      a copy is required | 
|  194     // but couldn't be made. Otherwise, returns true.  This method needs to be p
     rotected because it |  209     // but couldn't be made. Otherwise, returns true.  This method needs to be p
     rotected because it | 
|  195     // needs to be accessed by GLPrograms to setup a correct drawstate |  210     // needs to be accessed by GLPrograms to setup a correct drawstate | 
|  196     bool setupDstReadIfNecessary(const GrPipelineBuilder&, |  211     bool setupDstReadIfNecessary(const GrPipelineBuilder&, | 
|  197         const GrProcOptInfo& colorPOI, |  212         const GrProcOptInfo& colorPOI, | 
|  198         const GrProcOptInfo& coveragePOI, |  213         const GrProcOptInfo& coveragePOI, | 
|  199         GrXferProcessor::DstTexture*, |  214         GrXferProcessor::DstTexture*, | 
|  200         const SkRect& batchBounds); |  215         const SkRect& batchBounds); | 
|  201  |  216  | 
|  202     void drawPathBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawPathBatch
     Base* batch, |  217     void drawPathBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawPathBatch
     Base* batch, | 
|  203                        GrPathRendering::FillType fill); |  218                        GrPathRendering::FillType fill); | 
|  204     // Check to see if this set of draw commands has been sent out |  219     // Check to see if this set of draw commands has been sent out | 
|  205     void getPathStencilSettingsForFilltype(GrPathRendering::FillType, |  220     void getPathStencilSettingsForFilltype(GrPathRendering::FillType, | 
|  206                                            const GrStencilAttachment*, |  221                                            const GrStencilAttachment*, | 
|  207                                            GrStencilSettings*); |  222                                            GrStencilSettings*); | 
|  208     virtual GrClipMaskManager* clipMaskManager() = 0; |  223     bool setupClip(const GrPipelineBuilder&, | 
|  209     virtual bool setupClip(const GrPipelineBuilder&, |  | 
|  210                            GrPipelineBuilder::AutoRestoreFragmentProcessorState*
     , |  224                            GrPipelineBuilder::AutoRestoreFragmentProcessorState*
     , | 
|  211                            GrPipelineBuilder::AutoRestoreStencil*, |  225                            GrPipelineBuilder::AutoRestoreStencil*, | 
|  212                            GrScissorState*, |  226                            GrScissorState*, | 
|  213                            const SkRect* devBounds) = 0; |  227                            const SkRect* devBounds); | 
|  214  |  228  | 
|  215     GrGpu*                  fGpu; |  229     // Used only by CMM. | 
|  216     const GrCaps*           fCaps; |  230     void clearStencilClip(const SkIRect&, bool insideClip, GrRenderTarget*); | 
|  217     GrResourceProvider*     fResourceProvider; |  231  | 
|  218     bool                    fFlushing; |  232     SkSTArray<256, SkAutoTUnref<GrBatch>, true> fBatches; | 
|  219     GrBatchToken            fLastFlushToken; |  233     SkAutoTDelete<GrClipMaskManager>            fClipMaskManager; | 
 |  234     // The context is only in service of the clip mask manager, remove once CMM 
     doesn't need this. | 
 |  235     GrContext*                                  fContext; | 
 |  236     GrGpu*                                      fGpu; | 
 |  237     GrResourceProvider*                         fResourceProvider; | 
 |  238     bool                                        fFlushing; | 
 |  239     GrBatchToken                                fLastFlushToken; | 
|  220  |  240  | 
|  221     typedef SkRefCnt INHERITED; |  241     typedef SkRefCnt INHERITED; | 
|  222 }; |  242 }; | 
|  223  |  243  | 
|  224 /* |  | 
|  225  * This class is JUST for clip mask manager.  Everyone else should just use draw
      target above. |  | 
|  226  */ |  | 
|  227 class GrClipTarget : public GrDrawTarget { |  | 
|  228 public: |  | 
|  229     GrClipTarget(GrContext*); |  | 
|  230  |  | 
|  231     /* Clip mask manager needs access to the context. |  | 
|  232      * TODO we only need a very small subset of context in the CMM. |  | 
|  233      */ |  | 
|  234     GrContext* getContext() { return fContext; } |  | 
|  235     const GrContext* getContext() const { return fContext; } |  | 
|  236  |  | 
|  237     /** |  | 
|  238      * Clip Mask Manager(and no one else) needs to clear private stencil bits. |  | 
|  239      * ClipTarget subclass sets clip bit in the stencil buffer. The subclass |  | 
|  240      * is free to clear the remaining bits to zero if masked clears are more |  | 
|  241      * expensive than clearing all bits. |  | 
|  242      */ |  | 
|  243     void clearStencilClip(const SkIRect&, bool insideClip, GrRenderTarget*); |  | 
|  244  |  | 
|  245     /** |  | 
|  246      * Release any resources that are cached but not currently in use. This |  | 
|  247      * is intended to give an application some recourse when resources are low. |  | 
|  248      */ |  | 
|  249     void purgeResources() override; |  | 
|  250  |  | 
|  251 protected: |  | 
|  252     SkAutoTDelete<GrClipMaskManager> fClipMaskManager; |  | 
|  253     GrContext*                       fContext; |  | 
|  254  |  | 
|  255 private: |  | 
|  256     GrClipMaskManager* clipMaskManager() override { return fClipMaskManager; } |  | 
|  257  |  | 
|  258     bool setupClip(const GrPipelineBuilder&, |  | 
|  259                    GrPipelineBuilder::AutoRestoreFragmentProcessorState*, |  | 
|  260                    GrPipelineBuilder::AutoRestoreStencil*, |  | 
|  261                    GrScissorState* scissorState, |  | 
|  262                    const SkRect* devBounds) override; |  | 
|  263  |  | 
|  264     typedef GrDrawTarget INHERITED; |  | 
|  265 }; |  | 
|  266  |  | 
|  267 #endif |  244 #endif | 
| OLD | NEW |