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

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

Issue 19789006: Fix texture allocation in SWMaskHelper (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Remove more code Created 7 years, 5 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/GrSWMaskHelper.h ('k') | no next file » | 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 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "GrSWMaskHelper.h" 8 #include "GrSWMaskHelper.h"
9 #include "GrDrawState.h" 9 #include "GrDrawState.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 desc.fHeight = fBM.height(); 123 desc.fHeight = fBM.height();
124 desc.fConfig = kAlpha_8_GrPixelConfig; 124 desc.fConfig = kAlpha_8_GrPixelConfig;
125 125
126 texture->set(fContext, desc); 126 texture->set(fContext, desc);
127 return NULL != texture->texture(); 127 return NULL != texture->texture();
128 } 128 }
129 129
130 /** 130 /**
131 * Move the result of the software mask generation back to the gpu 131 * Move the result of the software mask generation back to the gpu
132 */ 132 */
133 void GrSWMaskHelper::toTexture(GrTexture *texture, uint8_t alpha) { 133 void GrSWMaskHelper::toTexture(GrTexture *texture) {
134 SkAutoLockPixels alp(fBM); 134 SkAutoLockPixels alp(fBM);
135 135
136 // The destination texture is almost always larger than "fBM". Clear
137 // it appropriately so we don't get mask artifacts outside of the path's
138 // bounding box
139
140 // "texture" needs to be installed as the render target for the clear
141 // and the texture upload but cannot remain the render target upon
142 // return. Callers typically use it as a texture and it would then
143 // be both source and dest.
144 GrDrawState::AutoRenderTargetRestore artr(fContext->getGpu()->drawState(),
145 texture->asRenderTarget());
146
147 fContext->getGpu()->clear(NULL, GrColorPackRGBA(alpha, alpha, alpha, alpha)) ;
148
149 texture->writePixels(0, 0, fBM.width(), fBM.height(), 136 texture->writePixels(0, 0, fBM.width(), fBM.height(),
150 kAlpha_8_GrPixelConfig, 137 kAlpha_8_GrPixelConfig,
151 fBM.getPixels(), fBM.rowBytes()); 138 fBM.getPixels(), fBM.rowBytes());
152 } 139 }
153 140
154 //////////////////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////////////////
155 /** 142 /**
156 * Software rasterizes path to A8 mask (possibly using the context's matrix) 143 * Software rasterizes path to A8 mask (possibly using the context's matrix)
157 * and uploads the result to a scratch texture. Returns the resulting 144 * and uploads the result to a scratch texture. Returns the resulting
158 * texture on success; NULL on failure. 145 * texture on success; NULL on failure.
(...skipping 11 matching lines...) Expand all
170 if (!helper.init(resultBounds, matrix)) { 157 if (!helper.init(resultBounds, matrix)) {
171 return NULL; 158 return NULL;
172 } 159 }
173 160
174 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); 161 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF);
175 162
176 if (!helper.getTexture(&ast)) { 163 if (!helper.getTexture(&ast)) {
177 return NULL; 164 return NULL;
178 } 165 }
179 166
180 helper.toTexture(ast.texture(), 0x00); 167 helper.toTexture(ast.texture());
181 168
182 return ast.detach(); 169 return ast.detach();
183 } 170 }
184 171
185 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture, 172 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
186 GrDrawTarget* target, 173 GrDrawTarget* target,
187 const SkIRect& rect) { 174 const SkIRect& rect) {
188 GrDrawState* drawState = target->drawState(); 175 GrDrawState* drawState = target->drawState();
189 176
190 GrDrawState::AutoViewMatrixRestore avmr; 177 GrDrawState::AutoViewMatrixRestore avmr;
(...skipping 17 matching lines...) Expand all
208 maskMatrix.preConcat(drawState->getViewMatrix()); 195 maskMatrix.preConcat(drawState->getViewMatrix());
209 196
210 drawState->addCoverageEffect( 197 drawState->addCoverageEffect(
211 GrSimpleTextureEffect::Create(texture, 198 GrSimpleTextureEffect::Create(texture,
212 maskMatrix, 199 maskMatrix,
213 false, 200 false,
214 GrEffect::kPosition_Coord sType))->unref(); 201 GrEffect::kPosition_Coord sType))->unref();
215 202
216 target->drawSimpleRect(dstRect); 203 target->drawSimpleRect(dstRect);
217 } 204 }
OLDNEW
« no previous file with comments | « src/gpu/GrSWMaskHelper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698