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

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

Issue 330593004: Use scratch with LATC data if possible (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Code review changes Created 6 years, 6 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
« 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 9
10 #include "GrDrawState.h" 10 #include "GrDrawState.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
119 119
120 /** 120 /**
121 * Get a texture (from the texture cache) of the correct size & format. 121 * Get a texture (from the texture cache) of the correct size & format.
122 * Return true on success; false on failure. 122 * Return true on success; false on failure.
123 */ 123 */
124 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) { 124 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) {
125 GrTextureDesc desc; 125 GrTextureDesc desc;
126 desc.fWidth = fBM.width(); 126 desc.fWidth = fBM.width();
127 desc.fHeight = fBM.height(); 127 desc.fHeight = fBM.height();
128 desc.fConfig = kAlpha_8_GrPixelConfig; 128
129 #if GR_COMPRESS_ALPHA_MASK
130 static const int kLATCBlockSize = 4;
131 if (desc.fWidth % kLATCBlockSize == 0 && desc.fHeight % kLATCBlockSize == 0) {
132 desc.fConfig = kLATC_GrPixelConfig;
133 } else {
134 #endif
135 desc.fConfig = kAlpha_8_GrPixelConfig;
136 #if GR_COMPRESS_ALPHA_MASK
137 }
138 #endif
129 139
130 texture->set(fContext, desc); 140 texture->set(fContext, desc);
131 return NULL != texture->texture(); 141 return NULL != texture->texture();
132 } 142 }
133 143
134 GrTexture* GrSWMaskHelper::toLATCTexture(GrContext* ctx) { 144 void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de sc,
135 // Encode the BM into LATC data: 145 const void *data, int rowbytes) {
136 SkAutoLockPixels alp(fBM); 146 // If we aren't reusing scratch textures we don't need to flush before
137 SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format; 147 // writing since no one else will be using 'texture'
138 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(fBM, fo rmat)); 148 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures();
139 if (NULL == latcData) {
140 return NULL;
141 }
142 149
143 GrTextureDesc desc; 150 // Since we're uploading to it, and it's compressed, 'texture' shouldn't
144 desc.fWidth = fBM.width(); 151 // have a render target.
145 desc.fHeight = fBM.height(); 152 SkASSERT(NULL == texture->asRenderTarget());
146 desc.fConfig = kLATC_GrPixelConfig; 153
147 return ctx->getGpu()->createTexture(desc, latcData->bytes(), 0); 154 texture->writePixels(0, 0, desc.fWidth, desc.fHeight,
155 desc.fConfig, data, rowbytes,
156 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag);
148 } 157 }
149 158
150 /** 159 /**
151 * Move the result of the software mask generation back to the gpu 160 * Move the result of the software mask generation back to the gpu
152 */ 161 */
153 void GrSWMaskHelper::toTexture(GrTexture *texture) { 162 void GrSWMaskHelper::toTexture(GrTexture *texture) {
154 SkAutoLockPixels alp(fBM); 163 SkAutoLockPixels alp(fBM);
155 164
156 // If we aren't reusing scratch textures we don't need to flush before 165 GrTextureDesc desc;
157 // writing since no one else will be using 'texture' 166 desc.fWidth = fBM.width();
158 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); 167 desc.fHeight = fBM.height();
168 desc.fConfig = texture->config();
169
170 // First see if we should compress this texture before uploading.
171 if (texture->config() == kLATC_GrPixelConfig) {
172 SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format;
173 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(fBM , format));
174 SkASSERT(NULL != latcData);
159 175
160 // Since we're uploading to it, 'texture' shouldn't have a render target. 176 this->sendTextureData(texture, desc, latcData->data(), 0);
161 SkASSERT(NULL == texture->asRenderTarget()); 177 } else {
162 178 // Looks like we have to send a full A8 texture.
163 texture->writePixels(0, 0, fBM.width(), fBM.height(), 179 this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes());
164 kAlpha_8_GrPixelConfig, 180 }
165 fBM.getPixels(), fBM.rowBytes(),
166 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag);
167 } 181 }
168 182
169 //////////////////////////////////////////////////////////////////////////////// 183 ////////////////////////////////////////////////////////////////////////////////
170 /** 184 /**
171 * Software rasterizes path to A8 mask (possibly using the context's matrix) 185 * Software rasterizes path to A8 mask (possibly using the context's matrix)
172 * and uploads the result to a scratch texture. Returns the resulting 186 * and uploads the result to a scratch texture. Returns the resulting
173 * texture on success; NULL on failure. 187 * texture on success; NULL on failure.
174 */ 188 */
175 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, 189 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context,
176 const SkPath& path, 190 const SkPath& path,
177 const SkStrokeRec& stroke, 191 const SkStrokeRec& stroke,
178 const SkIRect& resultBounds, 192 const SkIRect& resultBounds,
179 bool antiAlias, 193 bool antiAlias,
180 SkMatrix* matrix) { 194 SkMatrix* matrix) {
181 GrSWMaskHelper helper(context); 195 GrSWMaskHelper helper(context);
182 196
183 if (!helper.init(resultBounds, matrix)) { 197 if (!helper.init(resultBounds, matrix)) {
184 return NULL; 198 return NULL;
185 } 199 }
186 200
187 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); 201 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF);
188 202
189 #if GR_COMPRESS_ALPHA_MASK
190 // Can we create an LATC texture?
191 GrTexture *latc = helper.toLATCTexture(context);
192 if (NULL != latc) {
193 return latc;
194 }
195 #endif
196
197 // Looks like we have to send a full A8 texture.
198 GrAutoScratchTexture ast; 203 GrAutoScratchTexture ast;
199 if (!helper.getTexture(&ast)) { 204 if (!helper.getTexture(&ast)) {
200 return NULL; 205 return NULL;
201 } 206 }
202 207
203 helper.toTexture(ast.texture()); 208 helper.toTexture(ast.texture());
204 209
205 return ast.detach(); 210 return ast.detach();
206 } 211 }
207 212
(...skipping 23 matching lines...) Expand all
231 maskMatrix.preConcat(drawState->getViewMatrix()); 236 maskMatrix.preConcat(drawState->getViewMatrix());
232 237
233 drawState->addCoverageEffect( 238 drawState->addCoverageEffect(
234 GrSimpleTextureEffect::Create(texture, 239 GrSimpleTextureEffect::Create(texture,
235 maskMatrix, 240 maskMatrix,
236 GrTextureParams::kNone_Fi lterMode, 241 GrTextureParams::kNone_Fi lterMode,
237 kPosition_GrCoordSet))->u nref(); 242 kPosition_GrCoordSet))->u nref();
238 243
239 target->drawSimpleRect(dstRect); 244 target->drawSimpleRect(dstRect);
240 } 245 }
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