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

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

Issue 1148793007: change SkDraw and all Blitters to use pixmap instead of bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 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') | src/utils/SkTextureCompressor.h » ('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 * 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 "GrPipelineBuilder.h" 10 #include "GrPipelineBuilder.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 paint.setStrokeWidth(stroke.getWidth()); 139 paint.setStrokeWidth(stroke.getWidth());
140 } 140 }
141 } 141 }
142 paint.setAntiAlias(antiAlias); 142 paint.setAntiAlias(antiAlias);
143 143
144 SkTBlitterAllocator allocator; 144 SkTBlitterAllocator allocator;
145 SkBlitter* blitter = NULL; 145 SkBlitter* blitter = NULL;
146 if (kBlitter_CompressionMode == fCompressionMode) { 146 if (kBlitter_CompressionMode == fCompressionMode) {
147 SkASSERT(fCompressedBuffer.get()); 147 SkASSERT(fCompressedBuffer.get());
148 blitter = SkTextureCompressor::CreateBlitterForFormat( 148 blitter = SkTextureCompressor::CreateBlitterForFormat(
149 fBM.width(), fBM.height(), fCompressedBuffer.get(), &allocator, fCom pressedFormat); 149 fPixels.width(), fPixels.height(), fCompressedBuffer.get(), &allocat or,
150 fCompressedFormat) ;
150 } 151 }
151 152
152 if (SkRegion::kReplace_Op == op && 0xFF == alpha) { 153 if (SkRegion::kReplace_Op == op && 0xFF == alpha) {
153 SkASSERT(0xFF == paint.getAlpha()); 154 SkASSERT(0xFF == paint.getAlpha());
154 fDraw.drawPathCoverage(path, paint, blitter); 155 fDraw.drawPathCoverage(path, paint, blitter);
155 } else { 156 } else {
156 paint.setXfermodeMode(op_to_mode(op)); 157 paint.setXfermodeMode(op_to_mode(op));
157 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); 158 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
158 fDraw.drawPath(path, paint, blitter); 159 fDraw.drawPath(path, paint, blitter);
159 } 160 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 int cmpSz = SkTextureCompressor::GetCompressedDataSize( 196 int cmpSz = SkTextureCompressor::GetCompressedDataSize(
196 fCompressedFormat, cmpWidth, cmpHeight); 197 fCompressedFormat, cmpWidth, cmpHeight);
197 198
198 SkASSERT(cmpSz > 0); 199 SkASSERT(cmpSz > 0);
199 SkASSERT(NULL == fCompressedBuffer.get()); 200 SkASSERT(NULL == fCompressedBuffer.get());
200 fCompressedBuffer.reset(cmpSz); 201 fCompressedBuffer.reset(cmpSz);
201 fCompressionMode = kBlitter_CompressionMode; 202 fCompressionMode = kBlitter_CompressionMode;
202 } 203 }
203 } 204 }
204 205
206 sk_bzero(&fDraw, sizeof(fDraw));
207
205 // If we don't have a custom blitter, then we either need a bitmap to compre ss 208 // If we don't have a custom blitter, then we either need a bitmap to compre ss
206 // from or a bitmap that we're going to use as a texture. In any case, we sh ould 209 // from or a bitmap that we're going to use as a texture. In any case, we sh ould
207 // allocate the pixels for a bitmap 210 // allocate the pixels for a bitmap
208 const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight); 211 const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight);
209 if (kBlitter_CompressionMode != fCompressionMode) { 212 if (kBlitter_CompressionMode != fCompressionMode) {
210 if (!fBM.tryAllocPixels(bmImageInfo)) { 213 if (!fPixels.tryAlloc(bmImageInfo)) {
211 return false; 214 return false;
212 } 215 }
213 216 fPixels.erase(0);
214 sk_bzero(fBM.getPixels(), fBM.getSafeSize());
215 } else { 217 } else {
216 // Otherwise, we just need to remember how big the buffer is... 218 // Otherwise, we just need to remember how big the buffer is...
217 fBM.setInfo(bmImageInfo); 219 fPixels.reset(bmImageInfo);
218 } 220 }
219 221 fDraw.fDst = fPixels;
220 sk_bzero(&fDraw, sizeof(fDraw));
221
222 fRasterClip.setRect(bounds); 222 fRasterClip.setRect(bounds);
223 fDraw.fRC = &fRasterClip; 223 fDraw.fRC = &fRasterClip;
224 fDraw.fClip = &fRasterClip.bwRgn(); 224 fDraw.fClip = &fRasterClip.bwRgn();
225 fDraw.fMatrix = &fMatrix; 225 fDraw.fMatrix = &fMatrix;
226 fDraw.fBitmap = &fBM;
227 return true; 226 return true;
228 } 227 }
229 228
230 /** 229 /**
231 * Get a texture (from the texture cache) of the correct size & format. 230 * Get a texture (from the texture cache) of the correct size & format.
232 */ 231 */
233 GrTexture* GrSWMaskHelper::createTexture() { 232 GrTexture* GrSWMaskHelper::createTexture() {
234 GrSurfaceDesc desc; 233 GrSurfaceDesc desc;
235 desc.fWidth = fBM.width(); 234 desc.fWidth = fPixels.width();
236 desc.fHeight = fBM.height(); 235 desc.fHeight = fPixels.height();
237 desc.fConfig = kAlpha_8_GrPixelConfig; 236 desc.fConfig = kAlpha_8_GrPixelConfig;
238 237
239 if (kNone_CompressionMode != fCompressionMode) { 238 if (kNone_CompressionMode != fCompressionMode) {
240 239
241 #ifdef SK_DEBUG 240 #ifdef SK_DEBUG
242 int dimX, dimY; 241 int dimX, dimY;
243 SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY) ; 242 SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY) ;
244 SkASSERT((desc.fWidth % dimX) == 0); 243 SkASSERT((desc.fWidth % dimX) == 0);
245 SkASSERT((desc.fHeight % dimY) == 0); 244 SkASSERT((desc.fHeight % dimY) == 0);
246 #endif 245 #endif
(...skipping 19 matching lines...) Expand all
266 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, 265 texture->writePixels(0, 0, desc.fWidth, desc.fHeight,
267 desc.fConfig, data, rowbytes, 266 desc.fConfig, data, rowbytes,
268 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag); 267 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag);
269 } 268 }
270 269
271 void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrSurfaceDesc & desc) { 270 void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrSurfaceDesc & desc) {
272 271
273 SkASSERT(GrPixelConfigIsCompressed(desc.fConfig)); 272 SkASSERT(GrPixelConfigIsCompressed(desc.fConfig));
274 SkASSERT(fmt_to_config(fCompressedFormat) == desc.fConfig); 273 SkASSERT(fmt_to_config(fCompressedFormat) == desc.fConfig);
275 274
276 SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fBM, fCo mpressedFormat)); 275 SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fPixels,
276 fCompres sedFormat));
277 SkASSERT(cmpData); 277 SkASSERT(cmpData);
278 278
279 this->sendTextureData(texture, desc, cmpData->data(), 0); 279 this->sendTextureData(texture, desc, cmpData->data(), 0);
280 } 280 }
281 281
282 /** 282 /**
283 * Move the result of the software mask generation back to the gpu 283 * Move the result of the software mask generation back to the gpu
284 */ 284 */
285 void GrSWMaskHelper::toTexture(GrTexture *texture) { 285 void GrSWMaskHelper::toTexture(GrTexture *texture) {
286 SkAutoLockPixels alp(fBM);
287
288 GrSurfaceDesc desc; 286 GrSurfaceDesc desc;
289 desc.fWidth = fBM.width(); 287 desc.fWidth = fPixels.width();
290 desc.fHeight = fBM.height(); 288 desc.fHeight = fPixels.height();
291 desc.fConfig = texture->config(); 289 desc.fConfig = texture->config();
292 290
293 // First see if we should compress this texture before uploading. 291 // First see if we should compress this texture before uploading.
294 switch (fCompressionMode) { 292 switch (fCompressionMode) {
295 case kNone_CompressionMode: 293 case kNone_CompressionMode:
296 this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes() ); 294 this->sendTextureData(texture, desc, fPixels.addr(), fPixels.rowByte s());
297 break; 295 break;
298 296
299 case kCompress_CompressionMode: 297 case kCompress_CompressionMode:
300 this->compressTextureData(texture, desc); 298 this->compressTextureData(texture, desc);
301 break; 299 break;
302 300
303 case kBlitter_CompressionMode: 301 case kBlitter_CompressionMode:
304 SkASSERT(fCompressedBuffer.get()); 302 SkASSERT(fCompressedBuffer.get());
305 this->sendTextureData(texture, desc, fCompressedBuffer.get(), 0); 303 this->sendTextureData(texture, desc, fCompressedBuffer.get(), 0);
306 break; 304 break;
307 } 305 }
308 } 306 }
309 307
310 /** 308 /**
311 * Convert mask generation results to a signed distance field 309 * Convert mask generation results to a signed distance field
312 */ 310 */
313 void GrSWMaskHelper::toSDF(unsigned char* sdf) { 311 void GrSWMaskHelper::toSDF(unsigned char* sdf) {
314 SkAutoLockPixels alp(fBM); 312 SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fPixels.addr() ,
315 313 fPixels.width(), fPixels.height(), fPixel s.rowBytes());
316 SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fBM.getPixels( ),
317 fBM.width(), fBM.height(), fBM.rowBytes() );
318 } 314 }
319 315
320 //////////////////////////////////////////////////////////////////////////////// 316 ////////////////////////////////////////////////////////////////////////////////
321 /** 317 /**
322 * Software rasterizes path to A8 mask (possibly using the context's matrix) 318 * Software rasterizes path to A8 mask (possibly using the context's matrix)
323 * and uploads the result to a scratch texture. Returns the resulting 319 * and uploads the result to a scratch texture. Returns the resulting
324 * texture on success; NULL on failure. 320 * texture on success; NULL on failure.
325 */ 321 */
326 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, 322 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context,
327 const SkPath& path, 323 const SkPath& path,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop )); 368 maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop ));
373 369
374 pipelineBuilder->addCoverageProcessor( 370 pipelineBuilder->addCoverageProcessor(
375 GrSimpleTextureEffect::Create(texture, 371 GrSimpleTextureEffect::Create(texture,
376 maskMatrix, 372 maskMatrix,
377 GrTextureParams::kNone_Fi lterMode, 373 GrTextureParams::kNone_Fi lterMode,
378 kDevice_GrCoordSet))->unr ef(); 374 kDevice_GrCoordSet))->unr ef();
379 375
380 target->drawBWRect(pipelineBuilder, color, SkMatrix::I(), dstRect, NULL, &in vert); 376 target->drawBWRect(pipelineBuilder, color, SkMatrix::I(), dstRect, NULL, &in vert);
381 } 377 }
OLDNEW
« no previous file with comments | « src/gpu/GrSWMaskHelper.h ('k') | src/utils/SkTextureCompressor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698