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

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

Issue 398603004: Generalize mask helper a bit for compression (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove #def Created 6 years, 5 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
« src/gpu/GrSWMaskHelper.h ('K') | « 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
10 #include "GrDrawState.h" 10 #include "GrDrawState.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 fMatrix = *matrix; 95 fMatrix = *matrix;
96 } else { 96 } else {
97 fMatrix.setIdentity(); 97 fMatrix.setIdentity();
98 } 98 }
99 99
100 // Now translate so the bound's UL corner is at the origin 100 // Now translate so the bound's UL corner is at the origin
101 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1, 101 fMatrix.postTranslate(-resultBounds.fLeft * SK_Scalar1,
102 -resultBounds.fTop * SK_Scalar1); 102 -resultBounds.fTop * SK_Scalar1);
103 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(), 103 SkIRect bounds = SkIRect::MakeWH(resultBounds.width(),
104 resultBounds.height()); 104 resultBounds.height());
105 #if GR_COMPRESS_ALPHA_MASK
106 // 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.
108 const int cmpWidth = (bounds.fRight + 15) & ~15;
109 const int cmpHeight = (bounds.fBottom + 3) & ~3;
110 #else
111 const int cmpWidth = bounds.fRight;
112 const int cmpHeight = bounds.fBottom;
113 #endif
105 114
106 if (!fBM.allocPixels(SkImageInfo::MakeA8(bounds.fRight, bounds.fBottom))) { 115 if (!fBM.allocPixels(SkImageInfo::MakeA8(cmpWidth, cmpHeight))) {
107 return false; 116 return false;
108 } 117 }
118
109 sk_bzero(fBM.getPixels(), fBM.getSafeSize()); 119 sk_bzero(fBM.getPixels(), fBM.getSafeSize());
110 120
111 sk_bzero(&fDraw, sizeof(fDraw)); 121 sk_bzero(&fDraw, sizeof(fDraw));
112 fRasterClip.setRect(bounds); 122 fRasterClip.setRect(bounds);
113 fDraw.fRC = &fRasterClip; 123 fDraw.fRC = &fRasterClip;
114 fDraw.fClip = &fRasterClip.bwRgn(); 124 fDraw.fClip = &fRasterClip.bwRgn();
115 fDraw.fMatrix = &fMatrix; 125 fDraw.fMatrix = &fMatrix;
116 fDraw.fBitmap = &fBM; 126 fDraw.fBitmap = &fBM;
117 return true; 127 return true;
118 } 128 }
119 129
120 /** 130 /**
121 * Get a texture (from the texture cache) of the correct size & format. 131 * Get a texture (from the texture cache) of the correct size & format.
122 * Return true on success; false on failure. 132 * Return true on success; false on failure.
123 */ 133 */
robertphillips 2014/07/16 12:13:23 Move these two into getTexture (to limit their sco
krajcevski 2014/07/16 13:43:02 Done.
134 static const int kCompressedBlockSize = 4;
135 static const GrPixelConfig kCompressedConfig = kR11_EAC_GrPixelConfig;
124 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) { 136 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* texture) {
125 GrTextureDesc desc; 137 GrTextureDesc desc;
126 desc.fWidth = fBM.width(); 138 desc.fWidth = fBM.width();
127 desc.fHeight = fBM.height(); 139 desc.fHeight = fBM.height();
140 desc.fConfig = kAlpha_8_GrPixelConfig;
128 141
129 #if GR_COMPRESS_ALPHA_MASK 142 #if GR_COMPRESS_ALPHA_MASK
130 static const int kLATCBlockSize = 4; 143 if (desc.fWidth % kCompressedBlockSize == 0 &&
131 if (desc.fWidth % kLATCBlockSize == 0 && desc.fHeight % kLATCBlockSize == 0) { 144 desc.fHeight % kCompressedBlockSize == 0) {
132 desc.fConfig = kLATC_GrPixelConfig; 145 desc.fConfig = kCompressedConfig;
133 } else {
134 #endif
135 desc.fConfig = kAlpha_8_GrPixelConfig;
136 #if GR_COMPRESS_ALPHA_MASK
137 } 146 }
138 #endif 147 #endif
139 148
robertphillips 2014/07/16 12:13:23 Move this into the GR_COMPRESS_ALPHA_MASK block ?
krajcevski 2014/07/16 13:43:02 Hrm, it doesn't need to be. The passed config shou
149 // If this config isn't supported then we should fall back to A8
150 if (!(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig))) {
151 desc.fConfig = kAlpha_8_GrPixelConfig;
152 }
153
140 texture->set(fContext, desc); 154 texture->set(fContext, desc);
141 return NULL != texture->texture(); 155 return NULL != texture->texture();
142 } 156 }
143 157
144 void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de sc, 158 void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrTextureDesc& de sc,
145 const void *data, int rowbytes) { 159 const void *data, int rowbytes) {
146 // If we aren't reusing scratch textures we don't need to flush before 160 // If we aren't reusing scratch textures we don't need to flush before
147 // writing since no one else will be using 'texture' 161 // writing since no one else will be using 'texture'
148 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures(); 162 bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures();
149 163
150 // Since we're uploading to it, and it's compressed, 'texture' shouldn't 164 // Since we're uploading to it, and it's compressed, 'texture' shouldn't
151 // have a render target. 165 // have a render target.
152 SkASSERT(NULL == texture->asRenderTarget()); 166 SkASSERT(NULL == texture->asRenderTarget());
153 167
154 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, 168 texture->writePixels(0, 0, desc.fWidth, desc.fHeight,
155 desc.fConfig, data, rowbytes, 169 desc.fConfig, data, rowbytes,
156 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag); 170 reuseScratch ? 0 : GrContext::kDontFlush_PixelOpsFlag);
157 } 171 }
158 172
173 void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrTextureDesc & desc) {
robertphillips 2014/07/16 12:13:23 // SkASSERT(GrPixelConfigIsCompressed(desc.fConfig
krajcevski 2014/07/16 13:43:02 Done.
174 SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format;
robertphillips 2014/07/16 12:13:23 // Compress to the format required by 'texture' ?
krajcevski 2014/07/16 13:43:02 Done.
175 switch(desc.fConfig) {
176 case kLATC_GrPixelConfig:
177 format = SkTextureCompressor::kLATC_Format;
178 break;
179 case kR11_EAC_GrPixelConfig:
180 format = SkTextureCompressor::kR11_EAC_Format;
181 break;
182 default:
183 SkFAIL("Unrecognized texture compression format.");
184 break;
185 }
186
187 SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fBM, for mat));
188 SkASSERT(NULL != cmpData);
189
190 this->sendTextureData(texture, desc, cmpData->data(), 0);
191 }
192
159 /** 193 /**
160 * Move the result of the software mask generation back to the gpu 194 * Move the result of the software mask generation back to the gpu
161 */ 195 */
162 void GrSWMaskHelper::toTexture(GrTexture *texture) { 196 void GrSWMaskHelper::toTexture(GrTexture *texture) {
163 SkAutoLockPixels alp(fBM); 197 SkAutoLockPixels alp(fBM);
164 198
165 GrTextureDesc desc; 199 GrTextureDesc desc;
166 desc.fWidth = fBM.width(); 200 desc.fWidth = fBM.width();
167 desc.fHeight = fBM.height(); 201 desc.fHeight = fBM.height();
168 desc.fConfig = texture->config(); 202 desc.fConfig = texture->config();
169 203
170 // First see if we should compress this texture before uploading. 204 // First see if we should compress this texture before uploading.
171 if (texture->config() == kLATC_GrPixelConfig) { 205 if (GrPixelConfigIsCompressed(texture->config())) {
172 SkTextureCompressor::Format format = SkTextureCompressor::kLATC_Format; 206 this->compressTextureData(texture, desc);
173 SkAutoDataUnref latcData(SkTextureCompressor::CompressBitmapToFormat(fBM , format));
174 SkASSERT(NULL != latcData);
175
176 this->sendTextureData(texture, desc, latcData->data(), 0);
177 } else { 207 } else {
178 // Looks like we have to send a full A8 texture. 208 // Looks like we have to send a full A8 texture.
179 this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes()); 209 this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes());
180 } 210 }
181 } 211 }
182 212
183 //////////////////////////////////////////////////////////////////////////////// 213 ////////////////////////////////////////////////////////////////////////////////
184 /** 214 /**
185 * Software rasterizes path to A8 mask (possibly using the context's matrix) 215 * Software rasterizes path to A8 mask (possibly using the context's matrix)
186 * and uploads the result to a scratch texture. Returns the resulting 216 * and uploads the result to a scratch texture. Returns the resulting
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 maskMatrix.preConcat(drawState->getViewMatrix()); 266 maskMatrix.preConcat(drawState->getViewMatrix());
237 267
238 drawState->addCoverageEffect( 268 drawState->addCoverageEffect(
239 GrSimpleTextureEffect::Create(texture, 269 GrSimpleTextureEffect::Create(texture,
240 maskMatrix, 270 maskMatrix,
241 GrTextureParams::kNone_Fi lterMode, 271 GrTextureParams::kNone_Fi lterMode,
242 kPosition_GrCoordSet))->u nref(); 272 kPosition_GrCoordSet))->u nref();
243 273
244 target->drawSimpleRect(dstRect); 274 target->drawSimpleRect(dstRect);
245 } 275 }
OLDNEW
« src/gpu/GrSWMaskHelper.h ('K') | « src/gpu/GrSWMaskHelper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698