Home | History | Annotate | Download | only in gpu
      1 /*
      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  */
      7 
      8 
      9 #ifndef GrAARectRenderer_DEFINED
     10 #define GrAARectRenderer_DEFINED
     11 
     12 #include "GrRefCnt.h"
     13 #include "SkMatrix.h"
     14 #include "SkRect.h"
     15 
     16 class GrGpu;
     17 class GrDrawTarget;
     18 class GrIndexBuffer;
     19 
     20 /*
     21  * This class wraps helper functions that draw AA rects (filled & stroked)
     22  */
     23 class GrAARectRenderer : public GrRefCnt {
     24 public:
     25     SK_DECLARE_INST_COUNT(GrAARectRenderer)
     26 
     27     GrAARectRenderer()
     28     : fAAFillRectIndexBuffer(NULL)
     29     , fAAStrokeRectIndexBuffer(NULL) {
     30     }
     31 
     32     void reset();
     33 
     34     ~GrAARectRenderer() {
     35         this->reset();
     36     }
     37 
     38     // TODO: potentialy fuse the fill & stroke methods and differentiate
     39     // between them by passing in strokeWidth (<0 means fill).
     40 
     41     void fillAARect(GrGpu* gpu,
     42                     GrDrawTarget* target,
     43                     const SkRect& rect,
     44                     const SkMatrix& combinedMatrix,
     45                     const SkRect& devRect,
     46                     bool useVertexCoverage) {
     47 #ifdef SHADER_AA_FILL_RECT
     48         if (combinedMatrix.rectStaysRect()) {
     49             this->shaderFillAlignedAARect(gpu, target,
     50                                           rect, combinedMatrix);
     51         } else {
     52             this->shaderFillAARect(gpu, target,
     53                                    rect, combinedMatrix);
     54         }
     55 #else
     56         this->geometryFillAARect(gpu, target,
     57                                  rect, combinedMatrix,
     58                                  devRect, useVertexCoverage);
     59 #endif
     60     }
     61 
     62     void strokeAARect(GrGpu* gpu,
     63                       GrDrawTarget* target,
     64                       const SkRect& rect,
     65                       const SkMatrix& combinedMatrix,
     66                       const SkRect& devRect,
     67                       SkScalar width,
     68                       bool useVertexCoverage);
     69 
     70     // First rect is outer; second rect is inner
     71     void fillAANestedRects(GrGpu* gpu,
     72                            GrDrawTarget* target,
     73                            const SkRect rects[2],
     74                            const SkMatrix& combinedMatrix,
     75                            bool useVertexCoverage);
     76 
     77 private:
     78     GrIndexBuffer*              fAAFillRectIndexBuffer;
     79     GrIndexBuffer*              fAAStrokeRectIndexBuffer;
     80 
     81     GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu);
     82 
     83     static int aaStrokeRectIndexCount();
     84     GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu);
     85 
     86     // TODO: Remove the useVertexCoverage boolean. Just use it all the time
     87     // since we now have a coverage vertex attribute
     88     void geometryFillAARect(GrGpu* gpu,
     89                             GrDrawTarget* target,
     90                             const SkRect& rect,
     91                             const SkMatrix& combinedMatrix,
     92                             const SkRect& devRect,
     93                             bool useVertexCoverage);
     94 
     95     void shaderFillAARect(GrGpu* gpu,
     96                           GrDrawTarget* target,
     97                           const SkRect& rect,
     98                           const SkMatrix& combinedMatrix);
     99 
    100     void shaderFillAlignedAARect(GrGpu* gpu,
    101                                  GrDrawTarget* target,
    102                                  const SkRect& rect,
    103                                  const SkMatrix& combinedMatrix);
    104 
    105     void geometryStrokeAARect(GrGpu* gpu,
    106                               GrDrawTarget* target,
    107                               const SkRect& devOutside,
    108                               const SkRect& devInside,
    109                               bool useVertexCoverage);
    110 
    111     typedef GrRefCnt INHERITED;
    112 };
    113 
    114 #endif // GrAARectRenderer_DEFINED
    115