Chromium Code Reviews| 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" |
| 11 #include "GrDrawTargetCaps.h" | 11 #include "GrDrawTargetCaps.h" |
| 12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
| 13 | 13 |
| 14 #include "SkData.h" | 14 #include "SkData.h" |
| 15 #include "SkStrokeRec.h" | 15 #include "SkStrokeRec.h" |
| 16 #include "SkTextureCompressor.h" | |
| 17 | 16 |
| 18 // TODO: try to remove this #include | 17 // TODO: try to remove this #include |
| 19 #include "GrContext.h" | 18 #include "GrContext.h" |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 /* | 22 /* |
| 24 * Convert a boolean operation into a transfer mode code | 23 * Convert a boolean operation into a transfer mode code |
| 25 */ | 24 */ |
| 26 SkXfermode::Mode op_to_mode(SkRegion::Op op) { | 25 SkXfermode::Mode op_to_mode(SkRegion::Op op) { |
| 27 | 26 |
| 28 static const SkXfermode::Mode modeMap[] = { | 27 static const SkXfermode::Mode modeMap[] = { |
| 29 SkXfermode::kDstOut_Mode, // kDifference_Op | 28 SkXfermode::kDstOut_Mode, // kDifference_Op |
| 30 SkXfermode::kModulate_Mode, // kIntersect_Op | 29 SkXfermode::kModulate_Mode, // kIntersect_Op |
| 31 SkXfermode::kSrcOver_Mode, // kUnion_Op | 30 SkXfermode::kSrcOver_Mode, // kUnion_Op |
| 32 SkXfermode::kXor_Mode, // kXOR_Op | 31 SkXfermode::kXor_Mode, // kXOR_Op |
| 33 SkXfermode::kClear_Mode, // kReverseDifference_Op | 32 SkXfermode::kClear_Mode, // kReverseDifference_Op |
| 34 SkXfermode::kSrc_Mode, // kReplace_Op | 33 SkXfermode::kSrc_Mode, // kReplace_Op |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 return modeMap[op]; | 36 return modeMap[op]; |
| 38 } | 37 } |
| 39 | 38 |
|
robertphillips
2014/07/29 16:16:03
static ?
krajcevski
2014/07/29 17:49:50
Done.
| |
| 39 GrPixelConfig fmt_to_config(SkTextureCompressor::Format fmt) { | |
| 40 static const GrPixelConfig configMap[] = { | |
| 41 kLATC_GrPixelConfig, // kLATC_Format, | |
| 42 kR11_EAC_GrPixelConfig, // kR11_EAC_Format, | |
| 43 kASTC_12x12_GrPixelConfig // kASTC_12x12_Format, | |
| 44 }; | |
| 45 | |
|
robertphillips
2014/07/29 16:16:03
Seems like there should be some static asserts her
krajcevski
2014/07/29 17:49:51
Done.
| |
| 46 return configMap[fmt]; | |
| 47 } | |
| 48 | |
| 40 } | 49 } |
| 41 | 50 |
| 42 /** | 51 /** |
| 43 * Draw a single rect element of the clip stack into the accumulation bitmap | 52 * Draw a single rect element of the clip stack into the accumulation bitmap |
| 44 */ | 53 */ |
| 45 void GrSWMaskHelper::draw(const SkRect& rect, SkRegion::Op op, | 54 void GrSWMaskHelper::draw(const SkRect& rect, SkRegion::Op op, |
| 46 bool antiAlias, uint8_t alpha) { | 55 bool antiAlias, uint8_t alpha) { |
| 47 SkPaint paint; | 56 SkPaint paint; |
| 48 | 57 |
| 49 SkXfermode* mode = SkXfermode::Create(op_to_mode(op)); | 58 SkXfermode* mode = SkXfermode::Create(op_to_mode(op)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 fMatrix = *matrix; | 104 fMatrix = *matrix; |
| 96 } else { | 105 } else { |
| 97 fMatrix.setIdentity(); | 106 fMatrix.setIdentity(); |
| 98 } | 107 } |
| 99 | 108 |
| 100 // Now translate so the bound's UL corner is at the origin | 109 // Now translate so the bound's UL corner is at the origin |
| 101 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, | 110 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, |
| 102 -resultBounds.fTop * SK_Scalar1); | 111 -resultBounds.fTop * SK_Scalar1); |
| 103 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), | 112 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), |
| 104 resultBounds.height()); | 113 resultBounds.height()); |
| 114 | |
| 105 #if GR_COMPRESS_ALPHA_MASK | 115 #if GR_COMPRESS_ALPHA_MASK |
| 116 fCompressedFormat = SkTextureCompressor::kR11_EAC_Format; | |
| 117 | |
| 106 // Make sure that the width is a multiple of 16 so that we can use | 118 // Make sure that the width is a multiple of 16 so that we can use |
| 107 // specialized SIMD instructions that compress 4 blocks at a time. | 119 // specialized SIMD instructions that compress 4 blocks at a time. |
| 108 const int cmpWidth = (bounds.fRight + 15) & ~15; | 120 int dimX, dimY; |
| 109 const int cmpHeight = (bounds.fBottom + 3) & ~3; | 121 SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY); |
| 122 const int cmpWidth = dimX * ((bounds.fRight + (dimX - 1)) / dimX); | |
| 123 const int cmpHeight = dimY * ((bounds.fRight + (dimY - 1)) / dimY); | |
| 110 #else | 124 #else |
| 111 const int cmpWidth = bounds.fRight; | 125 const int cmpWidth = bounds.fRight; |
| 112 const int cmpHeight = bounds.fBottom; | 126 const int cmpHeight = bounds.fBottom; |
| 113 #endif | 127 #endif |
| 114 | 128 |
| 115 if (!fBM.allocPixels(SkImageInfo::MakeA8(cmpWidth, cmpHeight))) { | 129 if (!fBM.allocPixels(SkImageInfo::MakeA8(cmpWidth, cmpHeight))) { |
| 116 return false; | 130 return false; |
| 117 } | 131 } |
| 118 | 132 |
| 119 sk_bzero(fBM.getPixels(), fBM.getSafeSize()); | 133 sk_bzero(fBM.getPixels(), fBM.getSafeSize()); |
| 120 | 134 |
| 121 sk_bzero(&fDraw, sizeof(fDraw)); | 135 sk_bzero(&fDraw, sizeof(fDraw)); |
| 122 fRasterClip.setRect(bounds); | 136 fRasterClip.setRect(bounds); |
| 123 fDraw.fRC = &fRasterClip; | 137 fDraw.fRC = &fRasterClip; |
| 124 fDraw.fClip = &fRasterClip.bwRgn(); | 138 fDraw.fClip = &fRasterClip.bwRgn(); |
| 125 fDraw.fMatrix = &fMatrix; | 139 fDraw.fMatrix = &fMatrix; |
| 126 fDraw.fBitmap = &fBM; | 140 fDraw.fBitmap = &fBM; |
| 127 return true; | 141 return true; |
| 128 } | 142 } |
| 129 | 143 |
| 130 /** | 144 /** |
| 131 * Get a texture (from the texture cache) of the correct size & format. | 145 * Get a texture (from the texture cache) of the correct size & format. |
| 132 * Return true on success; false on failure. | 146 * Return true on success; false on failure. |
| 133 */ | 147 */ |
| 134 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) { | 148 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) { |
| 135 GrTextureDesc desc; | 149 GrTextureDesc desc; |
| 136 desc.fWidth = fBM.width(); | 150 desc.fWidth = fBM.width(); |
| 137 desc.fHeight = fBM.height(); | 151 desc.fHeight = fBM.height(); |
| 138 desc.fConfig = kAlpha_8_GrPixelConfig; | |
| 139 | 152 |
| 140 #if GR_COMPRESS_ALPHA_MASK | 153 #if GR_COMPRESS_ALPHA_MASK |
| 141 static const int kCompressedBlockSize = 4; | |
| 142 static const GrPixelConfig kCompressedConfig = kR11_EAC_GrPixelConfig; | |
| 143 | 154 |
|
robertphillips
2014/07/29 16:16:03
#ifdef SK_DEBUG
krajcevski
2014/07/29 17:49:51
Done.
| |
| 144 if (desc.fWidth % kCompressedBlockSize == 0 && | 155 #ifndef NDEBUG |
| 145 desc.fHeight % kCompressedBlockSize == 0) { | 156 int dimX, dimY; |
| 146 desc.fConfig = kCompressedConfig; | 157 SkTextureCompressor::GetBlockDimensions(fCompressedFormat, &dimX, &dimY); |
| 147 } | 158 SkASSERT((desc.fWidth % dimX) == 0); |
| 159 SkASSERT((desc.fHeight % dimY) == 0); | |
| 160 #endif | |
| 161 | |
| 162 desc.fConfig = fmt_to_config(fCompressedFormat); | |
| 148 | 163 |
| 149 // If this config isn't supported then we should fall back to A8 | 164 // If this config isn't supported then we should fall back to A8 |
| 150 if (!(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig))) { | 165 if (!(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig))) { |
| 151 desc.fConfig = kAlpha_8_GrPixelConfig; | 166 desc.fConfig = kAlpha_8_GrPixelConfig; |
| 152 } | 167 } |
| 168 #else | |
| 169 desc.fConfig = kAlpha_8_GrPixelConfig; | |
| 153 #endif | 170 #endif |
| 154 | 171 |
| 155 texture->set(fContext, desc); | 172 texture->set(fContext, desc); |
| 156 return NULL != texture->texture(); | 173 return NULL != texture->texture(); |
| 157 } | 174 } |
| 158 | 175 |
| 159 void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de sc, | 176 void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de sc, |
| 160 const void *data, int rowbytes) { | 177 const void *data, int rowbytes) { |
| 161 // If we aren't reusing scratch textures we don't need to flush before | 178 // If we aren't reusing scratch textures we don't need to flush before |
| 162 // writing since no one else will be using 'texture' | 179 // writing since no one else will be using 'texture' |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 maskMatrix.preConcat(drawState->getViewMatrix()); | 289 maskMatrix.preConcat(drawState->getViewMatrix()); |
| 273 | 290 |
| 274 drawState->addCoverageEffect( | 291 drawState->addCoverageEffect( |
| 275 GrSimpleTextureEffect::Create(texture, | 292 GrSimpleTextureEffect::Create(texture, |
| 276 maskMatrix, | 293 maskMatrix, |
| 277 GrTextureParams::kNone_Fi lterMode, | 294 GrTextureParams::kNone_Fi lterMode, |
| 278 kPosition_GrCoordSet))->u nref(); | 295 kPosition_GrCoordSet))->u nref(); |
| 279 | 296 |
| 280 target->drawSimpleRect(dstRect); | 297 target->drawSimpleRect(dstRect); |
| 281 } | 298 } |
| OLD | NEW |