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

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

Issue 326223002: Add an LATC compressor to the A8 masks, and hide it behind an ifdef. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 #include "GrDrawState.h" 10 #include "GrDrawState.h"
10 #include "GrDrawTargetCaps.h" 11 #include "GrDrawTargetCaps.h"
11 #include "GrGpu.h" 12 #include "GrGpu.h"
12 13
13 #include "SkStrokeRec.h" 14 #include "SkStrokeRec.h"
14 15
16 #if GR_COMPRESS_ALPHA_MASK
robertphillips 2014/06/10 22:19:46 no extra space here
krajcevski 2014/06/10 22:28:46 Done.
17 # include "SkData.h"
18 # include "SkTextureCompressor.h"
19 #endif
15 // TODO: try to remove this #include 20 // TODO: try to remove this #include
16 #include "GrContext.h" 21 #include "GrContext.h"
17 22
18 namespace { 23 namespace {
24
19 /* 25 /*
20 * Convert a boolean operation into a transfer mode code 26 * Convert a boolean operation into a transfer mode code
21 */ 27 */
22 SkXfermode::Mode op_to_mode(SkRegion::Op op) { 28 SkXfermode::Mode op_to_mode(SkRegion::Op op) {
23 29
24 static const SkXfermode::Mode modeMap[] = { 30 static const SkXfermode::Mode modeMap[] = {
25 SkXfermode::kDstOut_Mode, // kDifference_Op 31 SkXfermode::kDstOut_Mode, // kDifference_Op
26 SkXfermode::kModulate_Mode, // kIntersect_Op 32 SkXfermode::kModulate_Mode, // kIntersect_Op
27 SkXfermode::kSrcOver_Mode, // kUnion_Op 33 SkXfermode::kSrcOver_Mode, // kUnion_Op
28 SkXfermode::kXor_Mode, // kXOR_Op 34 SkXfermode::kXor_Mode, // kXOR_Op
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) { 126 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) {
121 GrTextureDesc desc; 127 GrTextureDesc desc;
122 desc.fWidth = fBM.width(); 128 desc.fWidth = fBM.width();
123 desc.fHeight = fBM.height(); 129 desc.fHeight = fBM.height();
124 desc.fConfig = kAlpha_8_GrPixelConfig; 130 desc.fConfig = kAlpha_8_GrPixelConfig;
125 131
126 texture->set(fContext, desc); 132 texture->set(fContext, desc);
127 return NULL != texture->texture(); 133 return NULL != texture->texture();
128 } 134 }
129 135
136 GrTexture* GrSWMaskHelper::toLATCTexture(GrContext* ctx) {
137 #if GR_COMPRESS_ALPHA_MASK
138 // Encode the BM into LATC data:
robertphillips 2014/06/10 22:19:46 Can just use fBM - don't need this-> in this case.
krajcevski 2014/06/10 22:28:46 Done.
139 SkAutoLockPixels alp(this->fBM);
140 SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format;
141 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(this->f BM, format));
142 if (NULL == latcData) {
143 return NULL;
144 }
145
146 GrTextureDesc desc;
147 desc.fWidth = this->fBM.width();
148 desc.fHeight = this->fBM.height();
149 desc.fConfig = kLATC_GrPixelConfig;
150 return ctx->getGpu()->createTexture(desc, latcData->bytes(), 0);
151 #else
152 return NULL;
153 #endif
154 }
155
130 /** 156 /**
131 * Move the result of the software mask generation back to the gpu 157 * Move the result of the software mask generation back to the gpu
132 */ 158 */
133 void GrSWMaskHelper::toTexture(GrTexture *texture) { 159 void GrSWMaskHelper::toTexture(GrTexture *texture) {
134 SkAutoLockPixels alp(fBM); 160 SkAutoLockPixels alp(fBM);
135 161
136 // If we aren't reusing scratch textures we don't need to flush before 162 // If we aren't reusing scratch textures we don't need to flush before
137 // writing since no one else will be using 'texture' 163 // writing since no one else will be using 'texture'
138 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); 164 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures();
139 165
(...skipping 11 matching lines...) Expand all
151 * Software rasterizes path to A8 mask (possibly using the context's matrix) 177 * Software rasterizes path to A8 mask (possibly using the context's matrix)
152 * and uploads the result to a scratch texture. Returns the resulting 178 * and uploads the result to a scratch texture. Returns the resulting
153 * texture on success; NULL on failure. 179 * texture on success; NULL on failure.
154 */ 180 */
155 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, 181 GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context,
156 const SkPath& path, 182 const SkPath& path,
157 const SkStrokeRec& stroke, 183 const SkStrokeRec& stroke,
158 const SkIRect& resultBounds, 184 const SkIRect& resultBounds,
159 bool antiAlias, 185 bool antiAlias,
160 SkMatrix* matrix) { 186 SkMatrix* matrix) {
161 GrAutoScratchTexture ast;
162
163 GrSWMaskHelper helper(context); 187 GrSWMaskHelper helper(context);
164 188
165 if (!helper.init(resultBounds, matrix)) { 189 if (!helper.init(resultBounds, matrix)) {
166 return NULL; 190 return NULL;
167 } 191 }
168 192
169 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF); 193 helper.draw(path, stroke, SkRegion::kReplace_Op, antiAlias, 0xFF);
170 194
robertphillips 2014/06/10 22:19:46 Given the flag usage in toLATCTexture we probably
krajcevski 2014/06/10 22:28:46 Done.
195 #if GR_COMPRESS_ALPHA_MASK
196 // Can we create an LATC texture?
197 GrTexture *latc = helper.toLATCTexture(context);
198 if (NULL != latc) {
199 return latc;
200 }
201 #endif
202
203 // Looks like we have to send a full A8 texture.
204 GrAutoScratchTexture ast;
171 if (!helper.getTexture(&ast)) { 205 if (!helper.getTexture(&ast)) {
172 return NULL; 206 return NULL;
173 } 207 }
174 208
175 helper.toTexture(ast.texture()); 209 helper.toTexture(ast.texture());
176 210
177 return ast.detach(); 211 return ast.detach();
178 } 212 }
179 213
180 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture, 214 void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
(...skipping 22 matching lines...) Expand all
203 maskMatrix.preConcat(drawState->getViewMatrix()); 237 maskMatrix.preConcat(drawState->getViewMatrix());
204 238
205 drawState->addCoverageEffect( 239 drawState->addCoverageEffect(
206 GrSimpleTextureEffect::Create(texture, 240 GrSimpleTextureEffect::Create(texture,
207 maskMatrix, 241 maskMatrix,
208 GrTextureParams::kNone_Fi lterMode, 242 GrTextureParams::kNone_Fi lterMode,
209 kPosition_GrCoordSet))->u nref(); 243 kPosition_GrCoordSet))->u nref();
210 244
211 target->drawSimpleRect(dstRect); 245 target->drawSimpleRect(dstRect);
212 } 246 }
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