Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1148)

Side by Side Diff: src/gpu/GrInOrderDrawBuffer.cpp

Issue 12531015: Adds local coords to GrEffect system. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.h ('k') | src/gpu/GrSWMaskHelper.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrInOrderDrawBuffer.h" 10 #include "GrInOrderDrawBuffer.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 bounds->fTop = bounds->fBottom = point->fY; 67 bounds->fTop = bounds->fBottom = point->fY;
68 for (int i = 1; i < vertexCount; ++i) { 68 for (int i = 1; i < vertexCount; ++i) {
69 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + v ertexSize); 69 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + v ertexSize);
70 bounds->growToInclude(point->fX, point->fY); 70 bounds->growToInclude(point->fX, point->fY);
71 } 71 }
72 } 72 }
73 } 73 }
74 74
75 void GrInOrderDrawBuffer::drawRect(const GrRect& rect, 75 void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
76 const SkMatrix* matrix, 76 const SkMatrix* matrix,
77 const GrRect* srcRect, 77 const GrRect* localRect,
78 const SkMatrix* srcMatrix, 78 const SkMatrix* localMatrix) {
79 int stage) {
80 79
81 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings; 80 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings;
82 GrDrawState::AutoColorRestore acr; 81 GrDrawState::AutoColorRestore acr;
83 82
84 GrDrawState* drawState = this->drawState(); 83 GrDrawState* drawState = this->drawState();
85 84
86 GrColor color = drawState->getColor(); 85 GrColor color = drawState->getColor();
87 GrVertexAttribArray<3> attribs; 86 GrVertexAttribArray<3> attribs;
88 size_t currentOffset = 0; 87 size_t currentOffset = 0;
89 int colorOffset = -1, texOffset = -1; 88 int colorOffset = -1, localOffset = -1;
90 89
91 // set position attrib 90 // set position attrib
92 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count( )); 91 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count( ));
93 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset}; 92 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset};
94 attribs.push_back(currAttrib); 93 attribs.push_back(currAttrib);
95 currentOffset += sizeof(GrPoint); 94 currentOffset += sizeof(GrPoint);
96 95
97 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing 96 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing
98 // only in color is a common occurrence in tables). However, having per-vert ex colors disables 97 // only in color is a common occurrence in tables). However, having per-vert ex colors disables
99 // blending optimizations because we don't know if the color will be solid o r not. These 98 // blending optimizations because we don't know if the color will be solid o r not. These
100 // optimizations help determine whether coverage and color can be blended co rrectly when 99 // optimizations help determine whether coverage and color can be blended co rrectly when
101 // dual-source blending isn't available. This comes into play when there is coverage. If colors 100 // dual-source blending isn't available. This comes into play when there is coverage. If colors
102 // were a stage it could take a hint that every vertex's color will be opaqu e. 101 // were a stage it could take a hint that every vertex's color will be opaqu e.
103 if (this->getCaps().dualSourceBlendingSupport() || 102 if (this->getCaps().dualSourceBlendingSupport() ||
104 drawState->hasSolidCoverage(drawState->getAttribBindings())) { 103 drawState->hasSolidCoverage(drawState->getAttribBindings())) {
105 bindings |= GrDrawState::kColor_AttribBindingsBit; 104 bindings |= GrDrawState::kColor_AttribBindingsBit;
106 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count ()); 105 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count ());
107 currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset); 106 currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset);
108 attribs.push_back(currAttrib); 107 attribs.push_back(currAttrib);
109 colorOffset = currentOffset; 108 colorOffset = currentOffset;
110 currentOffset += sizeof(GrColor); 109 currentOffset += sizeof(GrColor);
111 // We set the draw state's color to white here. This is done so that any batching performed 110 // We set the draw state's color to white here. This is done so that any batching performed
112 // in our subclass's onDraw() won't get a false from GrDrawState::op== d ue to a color 111 // in our subclass's onDraw() won't get a false from GrDrawState::op== d ue to a color
113 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the 112 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
114 // constant color in its op== when the kColor layout bit is set and then we can remove this. 113 // constant color in its op== when the kColor layout bit is set and then we can remove this.
115 acr.set(drawState, 0xFFFFFFFF); 114 acr.set(drawState, 0xFFFFFFFF);
116 } 115 }
117 116
118 uint32_t explicitCoordMask = 0; 117 if (NULL != localRect) {
119 if (NULL != srcRect) { 118 bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
120 bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(stage); 119 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs .count());
121 drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.co unt());
122 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset); 120 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
123 attribs.push_back(currAttrib); 121 attribs.push_back(currAttrib);
124 texOffset = currentOffset; 122 localOffset = currentOffset;
125 currentOffset += sizeof(GrPoint); 123 currentOffset += sizeof(GrPoint);
126 explicitCoordMask = (1 << stage);
127 } 124 }
128 125
129 drawState->setVertexAttribs(attribs.begin(), attribs.count()); 126 drawState->setVertexAttribs(attribs.begin(), attribs.count());
130 drawState->setAttribBindings(bindings); 127 drawState->setAttribBindings(bindings);
131 AutoReleaseGeometry geo(this, 4, 0); 128 AutoReleaseGeometry geo(this, 4, 0);
132 if (!geo.succeeded()) { 129 if (!geo.succeeded()) {
133 GrPrintf("Failed to get space for vertices!\n"); 130 GrPrintf("Failed to get space for vertices!\n");
134 return; 131 return;
135 } 132 }
136 133
137 // Go to device coords to allow batching across matrix changes 134 // Go to device coords to allow batching across matrix changes
138 SkMatrix combinedMatrix; 135 SkMatrix combinedMatrix;
139 if (NULL != matrix) { 136 if (NULL != matrix) {
140 combinedMatrix = *matrix; 137 combinedMatrix = *matrix;
141 } else { 138 } else {
142 combinedMatrix.reset(); 139 combinedMatrix.reset();
143 } 140 }
144 combinedMatrix.postConcat(drawState->getViewMatrix()); 141 combinedMatrix.postConcat(drawState->getViewMatrix());
145 // When the caller has provided an explicit source rect for a stage then we don't want to 142 // When the caller has provided an explicit source rect for a stage then we don't want to
146 // modify that stage's matrix. Otherwise if the effect is generating its sou rce rect from 143 // modify that stage's matrix. Otherwise if the effect is generating its sou rce rect from
147 // the vertex positions then we have to account for the view matrix change. 144 // the vertex positions then we have to account for the view matrix change.
148 GrDrawState::AutoDeviceCoordDraw adcd(drawState, explicitCoordMask); 145 GrDrawState::AutoDeviceCoordDraw adcd(drawState);
149 if (!adcd.succeeded()) { 146 if (!adcd.succeeded()) {
150 return; 147 return;
151 } 148 }
152 149
153 size_t vsize = drawState->getVertexSize(); 150 size_t vsize = drawState->getVertexSize();
154 GrAssert(vsize == currentOffset); 151 GrAssert(vsize == currentOffset);
155 152
156 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom , vsize); 153 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom , vsize);
157 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4); 154 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
158 155
159 SkRect devBounds; 156 SkRect devBounds;
160 // since we already computed the dev verts, set the bounds hint. This will h elp us avoid 157 // since we already computed the dev verts, set the bounds hint. This will h elp us avoid
161 // unnecessary clipping in our onDraw(). 158 // unnecessary clipping in our onDraw().
162 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds); 159 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
163 160
164 if (texOffset >= 0) { 161 if (localOffset >= 0) {
165 GrAssert(explicitCoordMask != 0); 162 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset);
166 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + 163 coords->setRectFan(localRect->fLeft, localRect->fTop,
167 texOffset); 164 localRect->fRight, localRect->fBottom,
168 coords->setRectFan(srcRect->fLeft, srcRect->fTop,
169 srcRect->fRight, srcRect->fBottom,
170 vsize); 165 vsize);
171 if (NULL != srcMatrix) { 166 if (NULL != localMatrix) {
172 srcMatrix->mapPointsWithStride(coords, vsize, 4); 167 localMatrix->mapPointsWithStride(coords, vsize, 4);
173 } 168 }
174 } 169 }
175 170
176 if (colorOffset >= 0) { 171 if (colorOffset >= 0) {
177 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset); 172 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
178 for (int i = 0; i < 4; ++i) { 173 for (int i = 0; i < 4; ++i) {
179 *vertColor = color; 174 *vertColor = color;
180 vertColor = (GrColor*) ((intptr_t) vertColor + vsize); 175 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
181 } 176 }
182 } 177 }
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { 758 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
764 fCmds.push_back(kClear_Cmd); 759 fCmds.push_back(kClear_Cmd);
765 return &fClears.push_back(); 760 return &fClears.push_back();
766 } 761 }
767 762
768 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { 763 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
769 INHERITED::clipWillBeSet(newClipData); 764 INHERITED::clipWillBeSet(newClipData);
770 fClipSet = true; 765 fClipSet = true;
771 fClipProxyState = kUnknown_ClipProxyState; 766 fClipProxyState = kUnknown_ClipProxyState;
772 } 767 }
OLDNEW
« no previous file with comments | « src/gpu/GrInOrderDrawBuffer.h ('k') | src/gpu/GrSWMaskHelper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698