Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 */
8 #ifndef GrAARectRenderer_DEFINED
9 #define GrAARectRenderer_DEFINED
11 #include "SkMatrix.h"
12 #include "SkRect.h"
13 #include "SkRefCnt.h"
14 #include "SkStrokeRec.h"
16 class GrGpu;
17 class GrDrawTarget;
18 class GrIndexBuffer;
20 /*
21 * This class wraps helper functions that draw AA rects (filled & stroked)
22 */
23 class GrAARectRenderer : public SkRefCnt {
24 public:
25 SK_DECLARE_INST_COUNT(GrAARectRenderer)
27 GrAARectRenderer()
28 : fAAFillRectIndexBuffer(NULL)
29 , fAAMiterStrokeRectIndexBuffer(NULL)
30 , fAABevelStrokeRectIndexBuffer(NULL) {
31 }
33 void reset();
35 ~GrAARectRenderer() {
36 this->reset();
37 }
39 // TODO: potentialy fuse the fill & stroke methods and differentiate
40 // between them by passing in stroke (==NULL means fill).
42 void fillAARect(GrGpu* gpu,
43 GrDrawTarget* target,
44 const SkRect& rect,
45 const SkMatrix& combinedMatrix,
46 const SkRect& devRect,
47 bool useVertexCoverage) {
48 #ifdef SHADER_AA_FILL_RECT
49 if (combinedMatrix.rectStaysRect()) {
50 this->shaderFillAlignedAARect(gpu, target,
51 rect, combinedMatrix);
52 } else {
53 this->shaderFillAARect(gpu, target,
54 rect, combinedMatrix);
55 }
56 #else
57 this->geometryFillAARect(gpu, target,
58 rect, combinedMatrix,
59 devRect, useVertexCoverage);
60 #endif
61 }
63 void strokeAARect(GrGpu* gpu,
64 GrDrawTarget* target,
65 const SkRect& rect,
66 const SkMatrix& combinedMatrix,
67 const SkRect& devRect,
68 const SkStrokeRec* stroke,
69 bool useVertexCoverage);
71 // First rect is outer; second rect is inner
72 void fillAANestedRects(GrGpu* gpu,
73 GrDrawTarget* target,
74 const SkRect rects[2],
75 const SkMatrix& combinedMatrix,
76 bool useVertexCoverage);
78 private:
79 GrIndexBuffer* fAAFillRectIndexBuffer;
80 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
81 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
83 GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu);
85 static int aaStrokeRectIndexCount(bool miterStroke);
86 GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke);
88 // TODO: Remove the useVertexCoverage boolean. Just use it all the time
89 // since we now have a coverage vertex attribute
90 void geometryFillAARect(GrGpu* gpu,
91 GrDrawTarget* target,
92 const SkRect& rect,
93 const SkMatrix& combinedMatrix,
94 const SkRect& devRect,
95 bool useVertexCoverage);
97 void shaderFillAARect(GrGpu* gpu,
98 GrDrawTarget* target,
99 const SkRect& rect,
100 const SkMatrix& combinedMatrix);
102 void shaderFillAlignedAARect(GrGpu* gpu,
103 GrDrawTarget* target,
104 const SkRect& rect,
105 const SkMatrix& combinedMatrix);
107 void geometryStrokeAARect(GrGpu* gpu,
108 GrDrawTarget* target,
109 const SkRect& devOutside,
110 const SkRect& devOutsideAssist,
111 const SkRect& devInside,
112 bool useVertexCoverage,
113 bool miterStroke);
115 typedef SkRefCnt INHERITED;
116 };
118 #endif // GrAARectRenderer_DEFINED