| OLD | NEW |
| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 paint.setStrokeJoin(stroke.getJoin()); | 135 paint.setStrokeJoin(stroke.getJoin()); |
| 136 paint.setStrokeCap(stroke.getCap()); | 136 paint.setStrokeCap(stroke.getCap()); |
| 137 paint.setStrokeWidth(stroke.getWidth()); | 137 paint.setStrokeWidth(stroke.getWidth()); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 paint.setAntiAlias(antiAlias); | 140 paint.setAntiAlias(antiAlias); |
| 141 | 141 |
| 142 SkTBlitterAllocator allocator; | 142 SkTBlitterAllocator allocator; |
| 143 SkBlitter* blitter = NULL; | 143 SkBlitter* blitter = NULL; |
| 144 if (kBlitter_CompressionMode == fCompressionMode) { | 144 if (kBlitter_CompressionMode == fCompressionMode) { |
| 145 SkASSERT(NULL != fCompressedBuffer.get()); | 145 SkASSERT(fCompressedBuffer.get()); |
| 146 blitter = SkTextureCompressor::CreateBlitterForFormat( | 146 blitter = SkTextureCompressor::CreateBlitterForFormat( |
| 147 fBM.width(), fBM.height(), fCompressedBuffer.get(), &allocator, fCom
pressedFormat); | 147 fBM.width(), fBM.height(), fCompressedBuffer.get(), &allocator, fCom
pressedFormat); |
| 148 } | 148 } |
| 149 | 149 |
| 150 if (SkRegion::kReplace_Op == op && 0xFF == alpha) { | 150 if (SkRegion::kReplace_Op == op && 0xFF == alpha) { |
| 151 SkASSERT(0xFF == paint.getAlpha()); | 151 SkASSERT(0xFF == paint.getAlpha()); |
| 152 fDraw.drawPathCoverage(path, paint, blitter); | 152 fDraw.drawPathCoverage(path, paint, blitter); |
| 153 } else { | 153 } else { |
| 154 paint.setXfermodeMode(op_to_mode(op)); | 154 paint.setXfermodeMode(op_to_mode(op)); |
| 155 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); | 155 paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); |
| 156 fDraw.drawPath(path, paint, blitter); | 156 fDraw.drawPath(path, paint, blitter); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool GrSWMaskHelper::init(const SkIRect& resultBounds, | 160 bool GrSWMaskHelper::init(const SkIRect& resultBounds, |
| 161 const SkMatrix* matrix, | 161 const SkMatrix* matrix, |
| 162 bool allowCompression) { | 162 bool allowCompression) { |
| 163 if (NULL != matrix) { | 163 if (matrix) { |
| 164 fMatrix = *matrix; | 164 fMatrix = *matrix; |
| 165 } else { | 165 } else { |
| 166 fMatrix.setIdentity(); | 166 fMatrix.setIdentity(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Now translate so the bound's UL corner is at the origin | 169 // Now translate so the bound's UL corner is at the origin |
| 170 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, | 170 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, |
| 171 -resultBounds.fTop * SK_Scalar1); | 171 -resultBounds.fTop * SK_Scalar1); |
| 172 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), | 172 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), |
| 173 resultBounds.height()); | 173 resultBounds.height()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY)
; | 242 SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY)
; |
| 243 SkASSERT((desc.fWidth % dimX) == 0); | 243 SkASSERT((desc.fWidth % dimX) == 0); |
| 244 SkASSERT((desc.fHeight % dimY) == 0); | 244 SkASSERT((desc.fHeight % dimY) == 0); |
| 245 #endif | 245 #endif |
| 246 | 246 |
| 247 desc.fConfig = fmt_to_config(fCompressedFormat); | 247 desc.fConfig = fmt_to_config(fCompressedFormat); |
| 248 SkASSERT(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig)); | 248 SkASSERT(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig)); |
| 249 } | 249 } |
| 250 | 250 |
| 251 texture->set(fContext, desc); | 251 texture->set(fContext, desc); |
| 252 return NULL != texture->texture(); | 252 return SkToBool(texture->texture()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de
sc, | 255 void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de
sc, |
| 256 const void *data, int rowbytes) { | 256 const void *data, int rowbytes) { |
| 257 // If we aren't reusing scratch textures we don't need to flush before | 257 // If we aren't reusing scratch textures we don't need to flush before |
| 258 // writing since no one else will be using 'texture' | 258 // writing since no one else will be using 'texture' |
| 259 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); | 259 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); |
| 260 | 260 |
| 261 // Since we're uploading to it, and it's compressed, 'texture' shouldn't | 261 // Since we're uploading to it, and it's compressed, 'texture' shouldn't |
| 262 // have a render target. | 262 // have a render target. |
| 263 SkASSERT(NULL == texture->asRenderTarget()); | 263 SkASSERT(NULL == texture->asRenderTarget()); |
| 264 | 264 |
| 265 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, | 265 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, |
| 266 desc.fConfig, data, rowbytes, | 266 desc.fConfig, data, rowbytes, |
| 267 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag); | 267 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrTextureDesc
& desc) { | 270 void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrTextureDesc
& desc) { |
| 271 | 271 |
| 272 SkASSERT(GrPixelConfigIsCompressed(desc.fConfig)); | 272 SkASSERT(GrPixelConfigIsCompressed(desc.fConfig)); |
| 273 SkASSERT(fmt_to_config(fCompressedFormat) == desc.fConfig); | 273 SkASSERT(fmt_to_config(fCompressedFormat) == desc.fConfig); |
| 274 | 274 |
| 275 SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fBM, fCo
mpressedFormat)); | 275 SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fBM, fCo
mpressedFormat)); |
| 276 SkASSERT(NULL != cmpData); | 276 SkASSERT(cmpData); |
| 277 | 277 |
| 278 this->sendTextureData(texture, desc, cmpData->data(), 0); | 278 this->sendTextureData(texture, desc, cmpData->data(), 0); |
| 279 } | 279 } |
| 280 | 280 |
| 281 /** | 281 /** |
| 282 * Move the result of the software mask generation back to the gpu | 282 * Move the result of the software mask generation back to the gpu |
| 283 */ | 283 */ |
| 284 void GrSWMaskHelper::toTexture(GrTexture *texture) { | 284 void GrSWMaskHelper::toTexture(GrTexture *texture) { |
| 285 SkAutoLockPixels alp(fBM); | 285 SkAutoLockPixels alp(fBM); |
| 286 | 286 |
| 287 GrTextureDesc desc; | 287 GrTextureDesc desc; |
| 288 desc.fWidth = fBM.width(); | 288 desc.fWidth = fBM.width(); |
| 289 desc.fHeight = fBM.height(); | 289 desc.fHeight = fBM.height(); |
| 290 desc.fConfig = texture->config(); | 290 desc.fConfig = texture->config(); |
| 291 | 291 |
| 292 // First see if we should compress this texture before uploading. | 292 // First see if we should compress this texture before uploading. |
| 293 switch (fCompressionMode) { | 293 switch (fCompressionMode) { |
| 294 case kNone_CompressionMode: | 294 case kNone_CompressionMode: |
| 295 this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes()
); | 295 this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes()
); |
| 296 break; | 296 break; |
| 297 | 297 |
| 298 case kCompress_CompressionMode: | 298 case kCompress_CompressionMode: |
| 299 this->compressTextureData(texture, desc); | 299 this->compressTextureData(texture, desc); |
| 300 break; | 300 break; |
| 301 | 301 |
| 302 case kBlitter_CompressionMode: | 302 case kBlitter_CompressionMode: |
| 303 SkASSERT(NULL != fCompressedBuffer.get()); | 303 SkASSERT(fCompressedBuffer.get()); |
| 304 this->sendTextureData(texture, desc, fCompressedBuffer.get(), 0); | 304 this->sendTextureData(texture, desc, fCompressedBuffer.get(), 0); |
| 305 break; | 305 break; |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 //////////////////////////////////////////////////////////////////////////////// | 309 //////////////////////////////////////////////////////////////////////////////// |
| 310 /** | 310 /** |
| 311 * Software rasterizes path to A8 mask (possibly using the context's matrix) | 311 * Software rasterizes path to A8 mask (possibly using the context's matrix) |
| 312 * and uploads the result to a scratch texture. Returns the resulting | 312 * and uploads the result to a scratch texture. Returns the resulting |
| 313 * texture on success; NULL on failure. | 313 * texture on success; NULL on failure. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 maskMatrix.preConcat(drawState->getViewMatrix()); | 362 maskMatrix.preConcat(drawState->getViewMatrix()); |
| 363 | 363 |
| 364 drawState->addCoverageEffect( | 364 drawState->addCoverageEffect( |
| 365 GrSimpleTextureEffect::Create(texture, | 365 GrSimpleTextureEffect::Create(texture, |
| 366 maskMatrix, | 366 maskMatrix, |
| 367 GrTextureParams::kNone_Fi
lterMode, | 367 GrTextureParams::kNone_Fi
lterMode, |
| 368 kPosition_GrCoordSet))->u
nref(); | 368 kPosition_GrCoordSet))->u
nref(); |
| 369 | 369 |
| 370 target->drawSimpleRect(dstRect); | 370 target->drawSimpleRect(dstRect); |
| 371 } | 371 } |
| OLD | NEW |