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" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 static const int kLATCBlockSize = 4; | |
|
robertphillips
2014/06/12 14:43:33
1 line for this?
Don't we also need to guard this
krajcevski
2014/06/12 15:13:32
Done.
| |
| 130 if (desc.fWidth % kLATCBlockSize == 0 && | |
| 131 desc.fHeight % kLATCBlockSize == 0) { | |
| 132 desc.fConfig = kLATC_GrPixelConfig; | |
| 133 } else { | |
| 134 desc.fConfig = kAlpha_8_GrPixelConfig; | |
| 135 } | |
| 129 | 136 |
| 130 texture->set(fContext, desc); | 137 texture->set(fContext, desc); |
| 131 return NULL != texture->texture(); | 138 return NULL != texture->texture(); |
| 132 } | 139 } |
| 133 | 140 |
|
robertphillips
2014/06/12 14:43:33
I don't know if it would be worth it but it looks
krajcevski
2014/06/12 15:13:32
Done.
| |
| 134 GrTexture* GrSWMaskHelper::toLATCTexture(GrContext* ctx) { | 141 void GrSWMaskHelper::toLATCTexture(GrTexture* texture) { |
| 135 // Encode the BM into LATC data: | 142 // Encode the BM into LATC data: |
| 136 SkAutoLockPixels alp(fBM); | 143 SkAutoLockPixels alp(fBM); |
| 137 SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format; | 144 SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format; |
| 138 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(fBM, fo rmat)); | 145 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(fBM, fo rmat)); |
| 139 if (NULL == latcData) { | 146 SkASSERT(NULL != latcData); |
| 140 return NULL; | |
| 141 } | |
| 142 | 147 |
| 143 GrTextureDesc desc; | 148 // If we aren't reusing scratch textures we don't need to flush before |
| 144 desc.fWidth = fBM.width(); | 149 // writing since no one else will be using 'texture' |
| 145 desc.fHeight = fBM.height(); | 150 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); |
| 146 desc.fConfig = kLATC_GrPixelConfig; | 151 |
| 147 return ctx->getGpu()->createTexture(desc, latcData->bytes(), 0); | 152 // Since we're uploading to it, and it's compressed, 'texture' shouldn't |
| 153 // have a render target. | |
| 154 SkASSERT(NULL == texture->asRenderTarget()); | |
| 155 | |
| 156 texture->writePixels(0, 0, fBM.width(), fBM.height(), | |
| 157 kLATC_GrPixelConfig, latcData->bytes(), 0, | |
| 158 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag); | |
| 148 } | 159 } |
| 149 | 160 |
| 150 /** | 161 /** |
| 151 * Move the result of the software mask generation back to the gpu | 162 * Move the result of the software mask generation back to the gpu |
| 152 */ | 163 */ |
| 153 void GrSWMaskHelper::toTexture(GrTexture *texture) { | 164 void GrSWMaskHelper::toTexture(GrTexture *texture) { |
|
robertphillips
2014/06/12 14:43:33
toLATCTexture has its own alp - move this one down
krajcevski
2014/06/12 15:13:32
Done.
| |
| 154 SkAutoLockPixels alp(fBM); | 165 SkAutoLockPixels alp(fBM); |
| 155 | 166 |
| 167 #if GR_COMPRESS_ALPHA_MASK | |
| 168 // First see if we should compress this texture before uploading. | |
| 169 if (texture->config() == kLATC_GrPixelConfig) { | |
| 170 this->toLATCTexture(texture); | |
| 171 return; | |
| 172 } | |
| 173 #endif | |
| 174 | |
| 175 // Looks like we have to send a full A8 texture. | |
| 176 | |
| 156 // If we aren't reusing scratch textures we don't need to flush before | 177 // If we aren't reusing scratch textures we don't need to flush before |
| 157 // writing since no one else will be using 'texture' | 178 // writing since no one else will be using 'texture' |
| 158 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); | 179 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); |
| 159 | 180 |
| 160 // Since we're uploading to it, 'texture' shouldn't have a render target. | 181 // Since we're uploading to it, 'texture' shouldn't have a render target. |
| 161 SkASSERT(NULL == texture->asRenderTarget()); | 182 SkASSERT(NULL == texture->asRenderTarget()); |
| 162 | 183 |
| 163 texture->writePixels(0, 0, fBM.width(), fBM.height(), | 184 texture->writePixels(0, 0, fBM.width(), fBM.height(), |
| 164 kAlpha_8_GrPixelConfig, | 185 kAlpha_8_GrPixelConfig, |
| 165 fBM.getPixels(), fBM.rowBytes(), | 186 fBM.getPixels(), fBM.rowBytes(), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 179 bool antiAlias, | 200 bool antiAlias, |
| 180 SkMatrix* matrix) { | 201 SkMatrix* matrix) { |
| 181 GrSWMaskHelper helper(context); | 202 GrSWMaskHelper helper(context); |
| 182 | 203 |
| 183 if (!helper.init(resultBounds, matrix)) { | 204 if (!helper.init(resultBounds, matrix)) { |
| 184 return NULL; | 205 return NULL; |
| 185 } | 206 } |
| 186 | 207 |
| 187 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); | 208 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); |
| 188 | 209 |
| 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; | 210 GrAutoScratchTexture ast; |
| 199 if (!helper.getTexture(&ast)) { | 211 if (!helper.getTexture(&ast)) { |
| 200 return NULL; | 212 return NULL; |
| 201 } | 213 } |
| 202 | 214 |
| 203 helper.toTexture(ast.texture()); | 215 helper.toTexture(ast.texture()); |
| 204 | 216 |
| 205 return ast.detach(); | 217 return ast.detach(); |
| 206 } | 218 } |
| 207 | 219 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 231 maskMatrix.preConcat(drawState->getViewMatrix()); | 243 maskMatrix.preConcat(drawState->getViewMatrix()); |
| 232 | 244 |
| 233 drawState->addCoverageEffect( | 245 drawState->addCoverageEffect( |
| 234 GrSimpleTextureEffect::Create(texture, | 246 GrSimpleTextureEffect::Create(texture, |
| 235 maskMatrix, | 247 maskMatrix, |
| 236 GrTextureParams::kNone_Fi lterMode, | 248 GrTextureParams::kNone_Fi lterMode, |
| 237 kPosition_GrCoordSet))->u nref(); | 249 kPosition_GrCoordSet))->u nref(); |
| 238 | 250 |
| 239 target->drawSimpleRect(dstRect); | 251 target->drawSimpleRect(dstRect); |
| 240 } | 252 } |
| OLD | NEW |