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

Side by Side Diff: src/core/SkDraw.cpp

Issue 173893002: use colortype instead of config (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/core/SkScaledImageCache.cpp » ('j') | 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkDraw.h" 8 #include "SkDraw.h"
9 #include "SkBlitter.h" 9 #include "SkBlitter.h"
10 #include "SkBounder.h" 10 #include "SkBounder.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // SkDebugf("--- D_Clear_BitmapXferProc\n"); 193 // SkDebugf("--- D_Clear_BitmapXferProc\n");
194 return D_Clear_BitmapXferProc; // ignore data 194 return D_Clear_BitmapXferProc; // ignore data
195 case SkXfermode::kDst_Mode: 195 case SkXfermode::kDst_Mode:
196 // SkDebugf("--- D_Dst_BitmapXferProc\n"); 196 // SkDebugf("--- D_Dst_BitmapXferProc\n");
197 return D_Dst_BitmapXferProc; // ignore data 197 return D_Dst_BitmapXferProc; // ignore data
198 case SkXfermode::kSrc_Mode: { 198 case SkXfermode::kSrc_Mode: {
199 /* 199 /*
200 should I worry about dithering for the lower depths? 200 should I worry about dithering for the lower depths?
201 */ 201 */
202 SkPMColor pmc = SkPreMultiplyColor(color); 202 SkPMColor pmc = SkPreMultiplyColor(color);
203 switch (bitmap.config()) { 203 switch (bitmap.colorType()) {
204 case SkBitmap::kARGB_8888_Config: 204 case kPMColor_SkColorType:
205 if (data) { 205 if (data) {
206 *data = pmc; 206 *data = pmc;
207 } 207 }
208 // SkDebugf("--- D32_Src_BitmapXferProc\n"); 208 // SkDebugf("--- D32_Src_BitmapXferProc\n");
209 return D32_Src_BitmapXferProc; 209 return D32_Src_BitmapXferProc;
210 case SkBitmap::kRGB_565_Config: 210 case kRGB_565_SkColorType:
211 if (data) { 211 if (data) {
212 *data = SkPixel32ToPixel16(pmc); 212 *data = SkPixel32ToPixel16(pmc);
213 } 213 }
214 // SkDebugf("--- D16_Src_BitmapXferProc\n"); 214 // SkDebugf("--- D16_Src_BitmapXferProc\n");
215 return D16_Src_BitmapXferProc; 215 return D16_Src_BitmapXferProc;
216 case SkBitmap::kA8_Config: 216 case kAlpha_8_SkColorType:
217 if (data) { 217 if (data) {
218 *data = SkGetPackedA32(pmc); 218 *data = SkGetPackedA32(pmc);
219 } 219 }
220 // SkDebugf("--- DA8_Src_BitmapXferProc\n"); 220 // SkDebugf("--- DA8_Src_BitmapXferProc\n");
221 return DA8_Src_BitmapXferProc; 221 return DA8_Src_BitmapXferProc;
222 default: 222 default:
223 break; 223 break;
224 } 224 }
225 break; 225 break;
226 } 226 }
227 default: 227 default:
228 break; 228 break;
229 } 229 }
230 return NULL; 230 return NULL;
231 } 231 }
232 232
233 static void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect, 233 static void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect,
234 BitmapXferProc proc, uint32_t procData) { 234 BitmapXferProc proc, uint32_t procData) {
235 int shiftPerPixel; 235 int shiftPerPixel;
236 switch (bitmap.config()) { 236 switch (bitmap.colorType()) {
237 case SkBitmap::kARGB_8888_Config: 237 case kPMColor_SkColorType:
238 shiftPerPixel = 2; 238 shiftPerPixel = 2;
239 break; 239 break;
240 case SkBitmap::kRGB_565_Config: 240 case kRGB_565_SkColorType:
241 shiftPerPixel = 1; 241 shiftPerPixel = 1;
242 break; 242 break;
243 case SkBitmap::kA8_Config: 243 case kAlpha_8_SkColorType:
244 shiftPerPixel = 0; 244 shiftPerPixel = 0;
245 break; 245 break;
246 default: 246 default:
247 SkDEBUGFAIL("Can't use xferproc on this config"); 247 SkDEBUGFAIL("Can't use xferproc on this config");
248 return; 248 return;
249 } 249 }
250 250
251 uint8_t* pixels = (uint8_t*)bitmap.getPixels(); 251 uint8_t* pixels = (uint8_t*)bitmap.getPixels();
252 SkASSERT(pixels); 252 SkASSERT(pixels);
253 const size_t rowBytes = bitmap.rowBytes(); 253 const size_t rowBytes = bitmap.rowBytes();
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 proc = gAAProcs[fMode]; 519 proc = gAAProcs[fMode];
520 } else if (fPaint->getStrokeCap() != SkPaint::kRound_Cap) { 520 } else if (fPaint->getStrokeCap() != SkPaint::kRound_Cap) {
521 SkASSERT(SkCanvas::kPoints_PointMode == fMode); 521 SkASSERT(SkCanvas::kPoints_PointMode == fMode);
522 proc = aa_square_proc; 522 proc = aa_square_proc;
523 } 523 }
524 } else { // BW 524 } else { // BW
525 if (fRadius <= SK_FixedHalf) { // small radii and hairline 525 if (fRadius <= SK_FixedHalf) { // small radii and hairline
526 if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) { 526 if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) {
527 uint32_t value; 527 uint32_t value;
528 const SkBitmap* bm = blitter->justAnOpaqueColor(&value); 528 const SkBitmap* bm = blitter->justAnOpaqueColor(&value);
529 if (bm && SkBitmap::kRGB_565_Config == bm->config()) { 529 if (bm && kRGB_565_SkColorType == bm->colorType()) {
530 proc = bw_pt_rect_16_hair_proc; 530 proc = bw_pt_rect_16_hair_proc;
531 } else if (bm && SkBitmap::kARGB_8888_Config == bm->config()) { 531 } else if (bm && kPMColor_SkColorType == bm->colorType()) {
532 proc = bw_pt_rect_32_hair_proc; 532 proc = bw_pt_rect_32_hair_proc;
533 } else { 533 } else {
534 proc = bw_pt_rect_hair_proc; 534 proc = bw_pt_rect_hair_proc;
535 } 535 }
536 } else { 536 } else {
537 static Proc gBWProcs[] = { 537 static Proc gBWProcs[] = {
538 bw_pt_hair_proc, bw_line_hair_proc, bw_poly_hair_proc 538 bw_pt_hair_proc, bw_line_hair_proc, bw_poly_hair_proc
539 }; 539 };
540 proc = gBWProcs[fMode]; 540 proc = gBWProcs[fMode];
541 } 541 }
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 go ahead and treat it as if it were, so that subsequent code can go fast. 1169 go ahead and treat it as if it were, so that subsequent code can go fast.
1170 */ 1170 */
1171 static bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) { 1171 static bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) {
1172 unsigned bits = 0; // TODO: find a way to allow the caller to tell us to 1172 unsigned bits = 0; // TODO: find a way to allow the caller to tell us to
1173 // respect filtering. 1173 // respect filtering.
1174 return SkTreatAsSprite(matrix, bitmap.width(), bitmap.height(), bits); 1174 return SkTreatAsSprite(matrix, bitmap.width(), bitmap.height(), bits);
1175 } 1175 }
1176 1176
1177 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, 1177 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap,
1178 const SkPaint& paint) const { 1178 const SkPaint& paint) const {
1179 SkASSERT(bitmap.config() == SkBitmap::kA8_Config); 1179 SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType);
1180 1180
1181 if (just_translate(*fMatrix, bitmap)) { 1181 if (just_translate(*fMatrix, bitmap)) {
1182 int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); 1182 int ix = SkScalarRoundToInt(fMatrix->getTranslateX());
1183 int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); 1183 int iy = SkScalarRoundToInt(fMatrix->getTranslateY());
1184 1184
1185 SkAutoLockPixels alp(bitmap); 1185 SkAutoLockPixels alp(bitmap);
1186 if (!bitmap.readyToDraw()) { 1186 if (!bitmap.readyToDraw()) {
1187 return; 1187 return;
1188 } 1188 }
1189 1189
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 clip.quickContains(x, y, x + bitmap.width(), y + bitmap.height()); 1277 clip.quickContains(x, y, x + bitmap.width(), y + bitmap.height());
1278 } 1278 }
1279 1279
1280 void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, 1280 void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
1281 const SkPaint& origPaint) const { 1281 const SkPaint& origPaint) const {
1282 SkDEBUGCODE(this->validate();) 1282 SkDEBUGCODE(this->validate();)
1283 1283
1284 // nothing to draw 1284 // nothing to draw
1285 if (fRC->isEmpty() || 1285 if (fRC->isEmpty() ||
1286 bitmap.width() == 0 || bitmap.height() == 0 || 1286 bitmap.width() == 0 || bitmap.height() == 0 ||
1287 bitmap.config() == SkBitmap::kNo_Config) { 1287 bitmap.colorType() == kUnknown_SkColorType) {
1288 return; 1288 return;
1289 } 1289 }
1290 1290
1291 SkPaint paint(origPaint); 1291 SkPaint paint(origPaint);
1292 paint.setStyle(SkPaint::kFill_Style); 1292 paint.setStyle(SkPaint::kFill_Style);
1293 1293
1294 SkMatrix matrix; 1294 SkMatrix matrix;
1295 if (!matrix.setConcat(*fMatrix, prematrix)) { 1295 if (!matrix.setConcat(*fMatrix, prematrix)) {
1296 return; 1296 return;
1297 } 1297 }
1298 1298
1299 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) { 1299 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) {
1300 return; 1300 return;
1301 } 1301 }
1302 1302
1303 if (fBounder && just_translate(matrix, bitmap)) { 1303 if (fBounder && just_translate(matrix, bitmap)) {
1304 SkIRect ir; 1304 SkIRect ir;
1305 int32_t ix = SkScalarRoundToInt(matrix.getTranslateX()); 1305 int32_t ix = SkScalarRoundToInt(matrix.getTranslateX());
1306 int32_t iy = SkScalarRoundToInt(matrix.getTranslateY()); 1306 int32_t iy = SkScalarRoundToInt(matrix.getTranslateY());
1307 ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 1307 ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height());
1308 if (!fBounder->doIRect(ir)) { 1308 if (!fBounder->doIRect(ir)) {
1309 return; 1309 return;
1310 } 1310 }
1311 } 1311 }
1312 1312
1313 if (bitmap.config() != SkBitmap::kA8_Config && 1313 if (bitmap.colorType() != kAlpha_8_SkColorType &&
1314 just_translate(matrix, bitmap)) { 1314 just_translate(matrix, bitmap)) {
1315 // 1315 //
1316 // It is safe to call lock pixels now, since we know the matrix is 1316 // It is safe to call lock pixels now, since we know the matrix is
1317 // (more or less) identity. 1317 // (more or less) identity.
1318 // 1318 //
1319 SkAutoLockPixels alp(bitmap); 1319 SkAutoLockPixels alp(bitmap);
1320 if (!bitmap.readyToDraw()) { 1320 if (!bitmap.readyToDraw()) {
1321 return; 1321 return;
1322 } 1322 }
1323 int ix = SkScalarRoundToInt(matrix.getTranslateX()); 1323 int ix = SkScalarRoundToInt(matrix.getTranslateX());
(...skipping 12 matching lines...) Expand all
1336 return; 1336 return;
1337 } 1337 }
1338 } 1338 }
1339 } 1339 }
1340 1340
1341 // now make a temp draw on the stack, and use it 1341 // now make a temp draw on the stack, and use it
1342 // 1342 //
1343 SkDraw draw(*this); 1343 SkDraw draw(*this);
1344 draw.fMatrix = &matrix; 1344 draw.fMatrix = &matrix;
1345 1345
1346 if (bitmap.config() == SkBitmap::kA8_Config) { 1346 if (bitmap.colorType() == kAlpha_8_SkColorType) {
1347 draw.drawBitmapAsMask(bitmap, paint); 1347 draw.drawBitmapAsMask(bitmap, paint);
1348 } else { 1348 } else {
1349 SkAutoBitmapShaderInstall install(bitmap, paint); 1349 SkAutoBitmapShaderInstall install(bitmap, paint);
1350 1350
1351 SkRect r; 1351 SkRect r;
1352 r.set(0, 0, SkIntToScalar(bitmap.width()), 1352 r.set(0, 0, SkIntToScalar(bitmap.width()),
1353 SkIntToScalar(bitmap.height())); 1353 SkIntToScalar(bitmap.height()));
1354 // is this ok if paint has a rasterizer? 1354 // is this ok if paint has a rasterizer?
1355 draw.drawRect(r, install.paintWithShader()); 1355 draw.drawRect(r, install.paintWithShader());
1356 } 1356 }
1357 } 1357 }
1358 1358
1359 void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, 1359 void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y,
1360 const SkPaint& origPaint) const { 1360 const SkPaint& origPaint) const {
1361 SkDEBUGCODE(this->validate();) 1361 SkDEBUGCODE(this->validate();)
1362 1362
1363 // nothing to draw 1363 // nothing to draw
1364 if (fRC->isEmpty() || 1364 if (fRC->isEmpty() ||
1365 bitmap.width() == 0 || bitmap.height() == 0 || 1365 bitmap.width() == 0 || bitmap.height() == 0 ||
1366 bitmap.config() == SkBitmap::kNo_Config) { 1366 bitmap.colorType() == kUnknown_SkColorType) {
1367 return; 1367 return;
1368 } 1368 }
1369 1369
1370 SkIRect bounds; 1370 SkIRect bounds;
1371 bounds.set(x, y, x + bitmap.width(), y + bitmap.height()); 1371 bounds.set(x, y, x + bitmap.width(), y + bitmap.height());
1372 1372
1373 if (fRC->quickReject(bounds)) { 1373 if (fRC->quickReject(bounds)) {
1374 return; // nothing to draw 1374 return; // nothing to draw
1375 } 1375 }
1376 1376
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2820 mask->fImage = SkMask::AllocImage(size); 2820 mask->fImage = SkMask::AllocImage(size);
2821 memset(mask->fImage, 0, mask->computeImageSize()); 2821 memset(mask->fImage, 0, mask->computeImageSize());
2822 } 2822 }
2823 2823
2824 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2824 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2825 draw_into_mask(*mask, devPath, style); 2825 draw_into_mask(*mask, devPath, style);
2826 } 2826 }
2827 2827
2828 return true; 2828 return true;
2829 } 2829 }
OLDNEW
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698