OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "GrNinePatch.h" | 8 #include "GrNinePatch.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 GrInitInvariantOutput* coverage, | 78 GrInitInvariantOutput* coverage, |
79 GrBatchToXPOverrides* overrides) const ove
rride { | 79 GrBatchToXPOverrides* overrides) const ove
rride { |
80 color->setUnknownFourComponents(); | 80 color->setUnknownFourComponents(); |
81 coverage->setKnownSingleComponent(0xff); | 81 coverage->setKnownSingleComponent(0xff); |
82 overrides->fUsePLSDstRead = false; | 82 overrides->fUsePLSDstRead = false; |
83 } | 83 } |
84 | 84 |
85 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 85 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
86 | 86 |
87 private: | 87 private: |
88 void onPrepareDraws(Target* target) override { | 88 void onPrepareDraws(Target* target) const override { |
89 SkAutoTUnref<const GrGeometryProcessor> gp(create_gp(fOverrides.readsCov
erage())); | 89 SkAutoTUnref<const GrGeometryProcessor> gp(create_gp(fOverrides.readsCov
erage())); |
90 if (!gp) { | 90 if (!gp) { |
91 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 91 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
92 return; | 92 return; |
93 } | 93 } |
94 | 94 |
95 target->initDraw(gp, this->pipeline()); | 95 target->initDraw(gp, this->pipeline()); |
96 | 96 |
97 size_t vertexStride = gp->getVertexStride(); | 97 size_t vertexStride = gp->getVertexStride(); |
98 int instanceCount = fGeoData.count(); | 98 int instanceCount = fGeoData.count(); |
99 | 99 |
100 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 100 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
101 target->resourceProvider()->refQuadIndexBuffer()); | 101 target->resourceProvider()->refQuadIndexBuffer()); |
102 InstancedHelper helper; | 102 InstancedHelper helper; |
103 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, | 103 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, |
104 indexBuffer, kVertsPerRect, | 104 indexBuffer, kVertsPerRect, |
105 kIndicesPerRect, instanceCount * kRectsPerI
nstance); | 105 kIndicesPerRect, instanceCount * kRectsPerI
nstance); |
106 if (!vertices || !indexBuffer) { | 106 if (!vertices || !indexBuffer) { |
107 SkDebugf("Could not allocate vertices\n"); | 107 SkDebugf("Could not allocate vertices\n"); |
108 return; | 108 return; |
109 } | 109 } |
110 | 110 |
111 for (int i = 0; i < instanceCount; i++) { | 111 for (int i = 0; i < instanceCount; i++) { |
112 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + | 112 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + |
113 i * kRectsPerInstance * kVertsPerRect * vertexStrid
e; | 113 i * kRectsPerInstance * kVertsPerRect * vertexStrid
e; |
114 | 114 |
115 Geometry& geo = fGeoData[i]; | 115 const Geometry& geo = fGeoData[i]; |
116 SkNinePatchIter iter(fImageWidth, fImageHeight, geo.fCenter, geo.fDs
t); | 116 SkNinePatchIter iter(fImageWidth, fImageHeight, geo.fCenter, geo.fDs
t); |
117 | 117 |
118 SkRect srcR, dstR; | 118 SkRect srcR, dstR; |
119 while (iter.next(&srcR, &dstR)) { | 119 while (iter.next(&srcR, &dstR)) { |
120 SkPoint* positions = reinterpret_cast<SkPoint*>(verts); | 120 SkPoint* positions = reinterpret_cast<SkPoint*>(verts); |
121 | 121 |
122 positions->setRectFan(dstR.fLeft, dstR.fTop, | 122 positions->setRectFan(dstR.fLeft, dstR.fTop, |
123 dstR.fRight, dstR.fBottom, vertexStride); | 123 dstR.fRight, dstR.fBottom, vertexStride); |
124 | 124 |
125 SkASSERT(!geo.fViewMatrix.hasPerspective()); | 125 SkASSERT(!geo.fViewMatrix.hasPerspective()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 typedef GrVertexBatch INHERITED; | 176 typedef GrVertexBatch INHERITED; |
177 }; | 177 }; |
178 | 178 |
179 namespace GrNinePatch { | 179 namespace GrNinePatch { |
180 GrDrawBatch* CreateNonAA(GrColor color, const SkMatrix& viewMatrix, int imageWid
th, int imageHeight, | 180 GrDrawBatch* CreateNonAA(GrColor color, const SkMatrix& viewMatrix, int imageWid
th, int imageHeight, |
181 const SkIRect& center, const SkRect& dst) { | 181 const SkIRect& center, const SkRect& dst) { |
182 return new GrNonAANinePatchBatch(color, viewMatrix, imageWidth, imageHeight,
center, dst); | 182 return new GrNonAANinePatchBatch(color, viewMatrix, imageWidth, imageHeight,
center, dst); |
183 } | 183 } |
184 }; | 184 }; |
OLD | NEW |