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

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

Issue 1348583002: Make skpaint->grpaint flow work for composing draws (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove unused inheriteds to satisfy clang Created 5 years, 2 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/GrTextContext.cpp ('k') | src/gpu/SkGr.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 2011 Google Inc. 2 * Copyright 2011 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 "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "GrBlurUtils.h" 10 #include "GrBlurUtils.h"
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "GrDrawContext.h" 12 #include "GrDrawContext.h"
13 #include "GrFontScaler.h" 13 #include "GrFontScaler.h"
14 #include "GrGpu.h" 14 #include "GrGpu.h"
15 #include "GrGpuResourcePriv.h" 15 #include "GrGpuResourcePriv.h"
16 #include "GrLayerHoister.h" 16 #include "GrLayerHoister.h"
17 #include "GrRecordReplaceDraw.h" 17 #include "GrRecordReplaceDraw.h"
18 #include "GrStrokeInfo.h" 18 #include "GrStrokeInfo.h"
19 #include "GrTextContext.h" 19 #include "GrTextContext.h"
20 #include "GrTracing.h" 20 #include "GrTracing.h"
21 #include "SkCanvasPriv.h" 21 #include "SkCanvasPriv.h"
22 #include "SkDrawProcs.h" 22 #include "SkDrawProcs.h"
23 #include "SkErrorInternals.h" 23 #include "SkErrorInternals.h"
24 #include "SkGlyphCache.h" 24 #include "SkGlyphCache.h"
25 #include "SkGrTexturePixelRef.h" 25 #include "SkGrTexturePixelRef.h"
26 #include "SkGrPriv.h"
26 #include "SkImage_Base.h" 27 #include "SkImage_Base.h"
27 #include "SkImageFilter.h" 28 #include "SkImageFilter.h"
28 #include "SkLayerInfo.h" 29 #include "SkLayerInfo.h"
29 #include "SkMaskFilter.h" 30 #include "SkMaskFilter.h"
30 #include "SkPathEffect.h" 31 #include "SkPathEffect.h"
31 #include "SkPicture.h" 32 #include "SkPicture.h"
32 #include "SkPictureData.h" 33 #include "SkPictureData.h"
33 #include "SkRRect.h" 34 #include "SkRRect.h"
34 #include "SkRecord.h" 35 #include "SkRecord.h"
35 #include "SkStroke.h" 36 #include "SkStroke.h"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 fDrawContext.reset(fRenderTarget->getContext()->drawContext(&this->surfacePr ops())); 377 fDrawContext.reset(fRenderTarget->getContext()->drawContext(&this->surfacePr ops()));
377 } 378 }
378 379
379 /////////////////////////////////////////////////////////////////////////////// 380 ///////////////////////////////////////////////////////////////////////////////
380 381
381 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 382 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
382 CHECK_SHOULD_DRAW(draw); 383 CHECK_SHOULD_DRAW(draw);
383 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); 384 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext);
384 385
385 GrPaint grPaint; 386 GrPaint grPaint;
386 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { 387 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
387 return; 388 return;
388 } 389 }
389 390
390 fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix); 391 fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix);
391 } 392 }
392 393
393 // must be in SkCanvas::PointMode order 394 // must be in SkCanvas::PointMode order
394 static const GrPrimitiveType gPointMode2PrimtiveType[] = { 395 static const GrPrimitiveType gPointMode2PrimtiveType[] = {
395 kPoints_GrPrimitiveType, 396 kPoints_GrPrimitiveType,
396 kLines_GrPrimitiveType, 397 kLines_GrPrimitiveType,
(...skipping 28 matching lines...) Expand all
425 CHECK_SHOULD_DRAW(draw); 426 CHECK_SHOULD_DRAW(draw);
426 427
427 SkScalar width = paint.getStrokeWidth(); 428 SkScalar width = paint.getStrokeWidth();
428 if (width < 0) { 429 if (width < 0) {
429 return; 430 return;
430 } 431 }
431 432
432 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod e) { 433 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod e) {
433 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); 434 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style);
434 GrPaint grPaint; 435 GrPaint grPaint;
435 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPai nt)) { 436 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
436 return; 437 return;
437 } 438 }
438 SkPath path; 439 SkPath path;
439 path.setIsVolatile(true); 440 path.setIsVolatile(true);
440 path.moveTo(pts[0]); 441 path.moveTo(pts[0]);
441 path.lineTo(pts[1]); 442 path.lineTo(pts[1]);
442 fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, pat h, strokeInfo); 443 fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, pat h, strokeInfo);
443 return; 444 return;
444 } 445 }
445 446
446 // we only handle non-antialiased hairlines and paints without path effects or mask filters, 447 // we only handle non-antialiased hairlines and paints without path effects or mask filters,
447 // else we let the SkDraw call our drawPath() 448 // else we let the SkDraw call our drawPath()
448 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || 449 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() ||
449 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { 450 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) {
450 draw.drawPoints(mode, count, pts, paint, true); 451 draw.drawPoints(mode, count, pts, paint, true);
451 return; 452 return;
452 } 453 }
453 454
454 GrPaint grPaint; 455 GrPaint grPaint;
455 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { 456 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
456 return; 457 return;
457 } 458 }
458 459
459 fDrawContext->drawVertices(fRenderTarget, 460 fDrawContext->drawVertices(fRenderTarget,
460 fClip, 461 fClip,
461 grPaint, 462 grPaint,
462 *draw.fMatrix, 463 *draw.fMatrix,
463 gPointMode2PrimtiveType[mode], 464 gPointMode2PrimtiveType[mode],
464 SkToS32(count), 465 SkToS32(count),
465 (SkPoint*)pts, 466 (SkPoint*)pts,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 509
509 if (usePath) { 510 if (usePath) {
510 SkPath path; 511 SkPath path;
511 path.setIsVolatile(true); 512 path.setIsVolatile(true);
512 path.addRect(rect); 513 path.addRect(rect);
513 this->drawPath(draw, path, paint, nullptr, true); 514 this->drawPath(draw, path, paint, nullptr, true);
514 return; 515 return;
515 } 516 }
516 517
517 GrPaint grPaint; 518 GrPaint grPaint;
518 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { 519 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
519 return; 520 return;
520 } 521 }
521 522
522 fDrawContext->drawRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, & strokeInfo); 523 fDrawContext->drawRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, & strokeInfo);
523 } 524 }
524 525
525 /////////////////////////////////////////////////////////////////////////////// 526 ///////////////////////////////////////////////////////////////////////////////
526 527
527 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, 528 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
528 const SkPaint& paint) { 529 const SkPaint& paint) {
529 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext); 530 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext);
530 CHECK_FOR_ANNOTATION(paint); 531 CHECK_FOR_ANNOTATION(paint);
531 CHECK_SHOULD_DRAW(draw); 532 CHECK_SHOULD_DRAW(draw);
532 533
533 GrPaint grPaint; 534 GrPaint grPaint;
534 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { 535 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
535 return; 536 return;
536 } 537 }
537 538
538 GrStrokeInfo strokeInfo(paint); 539 GrStrokeInfo strokeInfo(paint);
539 if (paint.getMaskFilter()) { 540 if (paint.getMaskFilter()) {
540 // try to hit the fast path for drawing filtered round rects 541 // try to hit the fast path for drawing filtered round rects
541 542
542 SkRRect devRRect; 543 SkRRect devRRect;
543 if (rect.transform(*draw.fMatrix, &devRRect)) { 544 if (rect.transform(*draw.fMatrix, &devRRect)) {
544 if (devRRect.allCornersCircular()) { 545 if (devRRect.allCornersCircular()) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 596
596 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, 597 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
597 const SkRRect& inner, const SkPaint& paint) { 598 const SkRRect& inner, const SkPaint& paint) {
598 SkStrokeRec stroke(paint); 599 SkStrokeRec stroke(paint);
599 if (stroke.isFillStyle()) { 600 if (stroke.isFillStyle()) {
600 601
601 CHECK_FOR_ANNOTATION(paint); 602 CHECK_FOR_ANNOTATION(paint);
602 CHECK_SHOULD_DRAW(draw); 603 CHECK_SHOULD_DRAW(draw);
603 604
604 GrPaint grPaint; 605 GrPaint grPaint;
605 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPai nt)) { 606 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
606 return; 607 return;
607 } 608 }
608 609
609 if (nullptr == paint.getMaskFilter() && nullptr == paint.getPathEffect() ) { 610 if (nullptr == paint.getMaskFilter() && nullptr == paint.getPathEffect() ) {
610 fDrawContext->drawDRRect(fRenderTarget, fClip, grPaint, *draw.fMatri x, outer, inner); 611 fDrawContext->drawDRRect(fRenderTarget, fClip, grPaint, *draw.fMatri x, outer, inner);
611 return; 612 return;
612 } 613 }
613 } 614 }
614 615
615 SkPath path; 616 SkPath path;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 648
648 if (usePath) { 649 if (usePath) {
649 SkPath path; 650 SkPath path;
650 path.setIsVolatile(true); 651 path.setIsVolatile(true);
651 path.addOval(oval); 652 path.addOval(oval);
652 this->drawPath(draw, path, paint, nullptr, true); 653 this->drawPath(draw, path, paint, nullptr, true);
653 return; 654 return;
654 } 655 }
655 656
656 GrPaint grPaint; 657 GrPaint grPaint;
657 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { 658 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
658 return; 659 return;
659 } 660 }
660 661
661 fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, s trokeInfo); 662 fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, s trokeInfo);
662 } 663 }
663 664
664 #include "SkMaskFilter.h" 665 #include "SkMaskFilter.h"
665 666
666 /////////////////////////////////////////////////////////////////////////////// 667 ///////////////////////////////////////////////////////////////////////////////
667 668
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 // Setup texture to wrap bitmap 983 // Setup texture to wrap bitmap
983 GrTextureParams params(tm, textureFilterMode); 984 GrTextureParams params(tm, textureFilterMode);
984 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr , &params)); 985 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr , &params));
985 986
986 if (!texture) { 987 if (!texture) {
987 SkErrorInternals::SetError(kInternalError_SkError, 988 SkErrorInternals::SetError(kInternalError_SkError,
988 "Couldn't convert bitmap to texture."); 989 "Couldn't convert bitmap to texture.");
989 return; 990 return;
990 } 991 }
991 992
992 // Setup paint
993 GrColor paintColor = (kAlpha_8_SkColorType == bitmapPtr->colorType()) ?
994 SkColor2GrColor(paint.getColor()) :
995 SkColor2GrColorJustAlpha(paint.getColor());
996 993
997 GrPaint grPaint; 994 GrPaint grPaint;
998 995
999 // Create and insert texture effect 996 // Create and insert texture effect
1000 SkAutoTUnref<const GrFragmentProcessor> fp; 997 SkAutoTUnref<const GrFragmentProcessor> fp;
1001 if (doBicubic) { 998 if (doBicubic) {
1002 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text ure, 999 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text ure,
1003 SkMatrix::I(), 1000 SkMatrix::I(),
1004 tm)); 1001 tm));
1005 } else { 1002 } else {
1006 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager() , texture, 1003 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager() , texture,
1007 SkMatrix::I(), params)); 1004 SkMatrix::I(), params));
1008 } 1005 }
1009 1006
1010 // The bitmap read has to be first 1007 if (kAlpha_8_SkColorType == bitmapPtr->colorType()) {
1011 grPaint.addColorFragmentProcessor(fp); 1008 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
1012 if (!SkPaint2GrPaintNoShader(context, paint, SkColor2GrColor(paint.getColor( )), false, 1009 } else {
1013 &grPaint)) { 1010 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
1011 }
1012
1013 if (!SkPaintToGrPaintReplaceShader(context, paint, fp, &grPaint)) {
1014 return; 1014 return;
1015 } 1015 }
1016 1016
1017 grPaint.setColor(paintColor);
1018
1019 // Setup dst rect and final matrix 1017 // Setup dst rect and final matrix
1020 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight}; 1018 SkRect dstRect = {0, 0, dstSize.fWidth, dstSize.fHeight};
1021 1019
1022 SkRect devRect; 1020 SkRect devRect;
1023 viewMatrix.mapRect(&devRect, dstRect); 1021 viewMatrix.mapRect(&devRect, dstRect);
1024 1022
1025 SkMatrix matrix; 1023 SkMatrix matrix;
1026 matrix.setIDiv(bitmapPtr->width(), bitmapPtr->height()); 1024 matrix.setIDiv(bitmapPtr->width(), bitmapPtr->height());
1027 1025
1028 SkMatrix dstRectToSrcRect; 1026 SkMatrix dstRectToSrcRect;
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv), 1302 paintRect.setLTRB(SkScalarMul(srcRect.fLeft, wInv),
1305 SkScalarMul(srcRect.fTop, hInv), 1303 SkScalarMul(srcRect.fTop, hInv),
1306 SkScalarMul(srcRect.fRight, wInv), 1304 SkScalarMul(srcRect.fRight, wInv),
1307 SkScalarMul(srcRect.fBottom, hInv)); 1305 SkScalarMul(srcRect.fBottom, hInv));
1308 1306
1309 SkRect textureDomain = SkRect::MakeEmpty(); 1307 SkRect textureDomain = SkRect::MakeEmpty();
1310 1308
1311 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring 1309 // Construct a GrPaint by setting the bitmap texture as the first effect and then configuring
1312 // the rest from the SkPaint. 1310 // the rest from the SkPaint.
1313 GrPaint grPaint; 1311 GrPaint grPaint;
1314 SkAutoTUnref<GrFragmentProcessor> fp; 1312 SkAutoTUnref<const GrFragmentProcessor> fp;
1315 1313
1316 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint )) { 1314 if (needsTextureDomain && (SkCanvas::kStrict_SrcRectConstraint == constraint )) {
1317 // Use a constrained texture domain to avoid color bleeding 1315 // Use a constrained texture domain to avoid color bleeding
1318 SkScalar left, top, right, bottom; 1316 SkScalar left, top, right, bottom;
1319 if (srcRect.width() > SK_Scalar1) { 1317 if (srcRect.width() > SK_Scalar1) {
1320 SkScalar border = SK_ScalarHalf / texture->width(); 1318 SkScalar border = SK_ScalarHalf / texture->width();
1321 left = paintRect.left() + border; 1319 left = paintRect.left() + border;
1322 right = paintRect.right() - border; 1320 right = paintRect.right() - border;
1323 } else { 1321 } else {
1324 left = right = SkScalarHalf(paintRect.left() + paintRect.right()); 1322 left = right = SkScalarHalf(paintRect.left() + paintRect.right());
(...skipping 20 matching lines...) Expand all
1345 } else if (bicubic) { 1343 } else if (bicubic) {
1346 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode()); 1344 SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode());
1347 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil eModeY() }; 1345 SkShader::TileMode tileModes[2] = { params.getTileModeX(), params.getTil eModeY() };
1348 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text ure, SkMatrix::I(), 1346 fp.reset(GrBicubicEffect::Create(grPaint.getProcessorDataManager(), text ure, SkMatrix::I(),
1349 tileModes)); 1347 tileModes));
1350 } else { 1348 } else {
1351 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager() , texture, 1349 fp.reset(GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager() , texture,
1352 SkMatrix::I(), params)); 1350 SkMatrix::I(), params));
1353 } 1351 }
1354 1352
1355 grPaint.addColorFragmentProcessor(fp); 1353 if (kAlpha_8_SkColorType == bitmap.colorType()) {
1356 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); 1354 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
1357 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor() ) : 1355 } else {
1358 SkColor2GrColor(paint.getColor()); 1356 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
1359 if (!SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grP aint)) { 1357 }
1358
1359 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) {
1360 return; 1360 return;
1361 } 1361 }
1362 1362
1363 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect, 1363 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRect,
1364 paintRect); 1364 paintRect);
1365 } 1365 }
1366 1366
1367 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, 1367 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
1368 int width, int height, 1368 int width, int height,
1369 const SkImageFilter* filter, 1369 const SkImageFilter* filter,
(...skipping 24 matching lines...) Expand all
1394 int w = bitmap.width(); 1394 int w = bitmap.width();
1395 int h = bitmap.height(); 1395 int h = bitmap.height();
1396 1396
1397 GrTexture* texture; 1397 GrTexture* texture;
1398 // draw sprite uses the default texture params 1398 // draw sprite uses the default texture params
1399 AutoBitmapTexture abt(fContext, bitmap, nullptr, &texture); 1399 AutoBitmapTexture abt(fContext, bitmap, nullptr, &texture);
1400 if (!texture) { 1400 if (!texture) {
1401 return; 1401 return;
1402 } 1402 }
1403 1403
1404 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType();
1405
1404 SkImageFilter* filter = paint.getImageFilter(); 1406 SkImageFilter* filter = paint.getImageFilter();
1405 // This bitmap will own the filtered result as a texture. 1407 // This bitmap will own the filtered result as a texture.
1406 SkBitmap filteredBitmap; 1408 SkBitmap filteredBitmap;
1407 1409
1408 if (filter) { 1410 if (filter) {
1409 SkIPoint offset = SkIPoint::Make(0, 0); 1411 SkIPoint offset = SkIPoint::Make(0, 0);
1410 SkMatrix matrix(*draw.fMatrix); 1412 SkMatrix matrix(*draw.fMatrix);
1411 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); 1413 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
1412 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); 1414 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
1413 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); 1415 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
1414 // This cache is transient, and is freed (along with all its contained 1416 // This cache is transient, and is freed (along with all its contained
1415 // textures) when it goes out of scope. 1417 // textures) when it goes out of scope.
1416 SkImageFilter::Context ctx(matrix, clipBounds, cache); 1418 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1417 if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredB itmap, 1419 if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredB itmap,
1418 &offset)) { 1420 &offset)) {
1419 texture = (GrTexture*) filteredBitmap.getTexture(); 1421 texture = (GrTexture*) filteredBitmap.getTexture();
1420 w = filteredBitmap.width(); 1422 w = filteredBitmap.width();
1421 h = filteredBitmap.height(); 1423 h = filteredBitmap.height();
1422 left += offset.x(); 1424 left += offset.x();
1423 top += offset.y(); 1425 top += offset.y();
1424 } else { 1426 } else {
1425 return; 1427 return;
1426 } 1428 }
1429 SkASSERT(!GrPixelConfigIsAlphaOnly(texture->config()));
1430 alphaOnly = false;
1427 } 1431 }
1428 1432
1429 GrPaint grPaint; 1433 GrPaint grPaint;
1430 grPaint.addColorTextureProcessor(texture, SkMatrix::I()); 1434 SkAutoTUnref<const GrFragmentProcessor> fp(
1431 1435 GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager(), texture , SkMatrix::I()));
1432 if (!SkPaint2GrPaintNoShader(this->context(), paint, 1436 if (alphaOnly) {
1433 SkColor2GrColorJustAlpha(paint.getColor()), fal se, &grPaint)) { 1437 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
1438 } else {
1439 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
1440 }
1441 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) {
1434 return; 1442 return;
1435 } 1443 }
1436 1444
1437 fDrawContext->drawNonAARectToRect(fRenderTarget, 1445 fDrawContext->drawNonAARectToRect(fRenderTarget,
1438 fClip, 1446 fClip,
1439 grPaint, 1447 grPaint,
1440 SkMatrix::I(), 1448 SkMatrix::I(),
1441 SkRect::MakeXYWH(SkIntToScalar(left), 1449 SkRect::MakeXYWH(SkIntToScalar(left),
1442 SkIntToScalar(top), 1450 SkIntToScalar(top),
1443 SkIntToScalar(w), 1451 SkIntToScalar(w),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 w = filteredBitmap.width(); 1543 w = filteredBitmap.width();
1536 h = filteredBitmap.height(); 1544 h = filteredBitmap.height();
1537 x += offset.fX; 1545 x += offset.fX;
1538 y += offset.fY; 1546 y += offset.fY;
1539 } else { 1547 } else {
1540 return; 1548 return;
1541 } 1549 }
1542 } 1550 }
1543 1551
1544 GrPaint grPaint; 1552 GrPaint grPaint;
1545 grPaint.addColorTextureProcessor(devTex, SkMatrix::I()); 1553 SkAutoTUnref<const GrFragmentProcessor> fp(
1554 GrSimpleTextureEffect::Create(grPaint.getProcessorDataManager(), devTex, SkMatrix::I()));
1555 if (GrPixelConfigIsAlphaOnly(devTex->config())) {
1556 // Can this happen?
1557 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
1558 } else {
1559 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
1560 }
1546 1561
1547 if (!SkPaint2GrPaintNoShader(this->context(), paint, 1562 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) {
1548 SkColor2GrColorJustAlpha(paint.getColor()), fal se, &grPaint)) {
1549 return; 1563 return;
1550 } 1564 }
1551 1565
1552 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), 1566 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x),
1553 SkIntToScalar(y), 1567 SkIntToScalar(y),
1554 SkIntToScalar(w), 1568 SkIntToScalar(w),
1555 SkIntToScalar(h)); 1569 SkIntToScalar(h));
1556 1570
1557 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate 1571 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate
1558 // scratch texture). 1572 // scratch texture).
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 1673
1660 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, 1674 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
1661 int vertexCount, const SkPoint vertices[], 1675 int vertexCount, const SkPoint vertices[],
1662 const SkPoint texs[], const SkColor colors[], 1676 const SkPoint texs[], const SkColor colors[],
1663 SkXfermode* xmode, 1677 SkXfermode* xmode,
1664 const uint16_t indices[], int indexCount, 1678 const uint16_t indices[], int indexCount,
1665 const SkPaint& paint) { 1679 const SkPaint& paint) {
1666 CHECK_SHOULD_DRAW(draw); 1680 CHECK_SHOULD_DRAW(draw);
1667 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext); 1681 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext);
1668 1682
1669 const uint16_t* outIndices;
1670 SkAutoTDeleteArray<uint16_t> outAlloc(nullptr);
1671 GrPrimitiveType primType;
1672 GrPaint grPaint;
1673
1674 // If both textures and vertex-colors are nullptr, strokes hairlines with th e paint's color. 1683 // If both textures and vertex-colors are nullptr, strokes hairlines with th e paint's color.
1675 if ((nullptr == texs || nullptr == paint.getShader()) && nullptr == colors) { 1684 if ((nullptr == texs || nullptr == paint.getShader()) && nullptr == colors) {
1676 1685
1677 texs = nullptr; 1686 texs = nullptr;
1678 1687
1679 SkPaint copy(paint); 1688 SkPaint copy(paint);
1680 copy.setStyle(SkPaint::kStroke_Style); 1689 copy.setStyle(SkPaint::kStroke_Style);
1681 copy.setStrokeWidth(0); 1690 copy.setStrokeWidth(0);
1682 1691
1692 GrPaint grPaint;
1683 // we ignore the shader if texs is null. 1693 // we ignore the shader if texs is null.
1684 if (!SkPaint2GrPaintNoShader(this->context(), copy, 1694 if (!SkPaintToGrPaintNoShader(this->context(), copy, &grPaint)) {
1685 SkColor2GrColor(copy.getColor()), nullptr = = colors, &grPaint)) {
1686 return; 1695 return;
1687 } 1696 }
1688 1697
1689 primType = kLines_GrPrimitiveType;
1690 int triangleCount = 0; 1698 int triangleCount = 0;
1691 int n = (nullptr == indices) ? vertexCount : indexCount; 1699 int n = (nullptr == indices) ? vertexCount : indexCount;
1692 switch (vmode) { 1700 switch (vmode) {
1693 case SkCanvas::kTriangles_VertexMode: 1701 case SkCanvas::kTriangles_VertexMode:
1694 triangleCount = n / 3; 1702 triangleCount = n / 3;
1695 break; 1703 break;
1696 case SkCanvas::kTriangleStrip_VertexMode: 1704 case SkCanvas::kTriangleStrip_VertexMode:
1697 case SkCanvas::kTriangleFan_VertexMode: 1705 case SkCanvas::kTriangleFan_VertexMode:
1698 triangleCount = n - 2; 1706 triangleCount = n - 2;
1699 break; 1707 break;
1700 } 1708 }
1701 1709
1702 VertState state(vertexCount, indices, indexCount); 1710 VertState state(vertexCount, indices, indexCount);
1703 VertState::Proc vertProc = state.chooseProc(vmode); 1711 VertState::Proc vertProc = state.chooseProc(vmode);
1704 1712
1705 //number of indices for lines per triangle with kLines 1713 //number of indices for lines per triangle with kLines
1706 indexCount = triangleCount * 6; 1714 indexCount = triangleCount * 6;
1707 1715
1708 outAlloc.reset(new uint16_t[indexCount]); 1716 SkAutoTDeleteArray<uint16_t> lineIndices(new uint16_t[indexCount]);
1709 outIndices = outAlloc.get();
1710 uint16_t* auxIndices = outAlloc.get();
1711 int i = 0; 1717 int i = 0;
1712 while (vertProc(&state)) { 1718 while (vertProc(&state)) {
1713 auxIndices[i] = state.f0; 1719 lineIndices[i] = state.f0;
1714 auxIndices[i + 1] = state.f1; 1720 lineIndices[i + 1] = state.f1;
1715 auxIndices[i + 2] = state.f1; 1721 lineIndices[i + 2] = state.f1;
1716 auxIndices[i + 3] = state.f2; 1722 lineIndices[i + 3] = state.f2;
1717 auxIndices[i + 4] = state.f2; 1723 lineIndices[i + 4] = state.f2;
1718 auxIndices[i + 5] = state.f0; 1724 lineIndices[i + 5] = state.f0;
1719 i += 6; 1725 i += 6;
1720 } 1726 }
1721 } else { 1727 fDrawContext->drawVertices(fRenderTarget,
1722 outIndices = indices; 1728 fClip,
1723 primType = gVertexMode2PrimitiveType[vmode]; 1729 grPaint,
1724 1730 *draw.fMatrix,
1725 if (nullptr == texs || nullptr == paint.getShader()) { 1731 kLines_GrPrimitiveType,
1726 if (!SkPaint2GrPaintNoShader(this->context(), paint, 1732 vertexCount,
1727 SkColor2GrColor(paint.getColor()), 1733 vertices,
1728 nullptr == colors, &grPaint)) { 1734 texs,
1729 return; 1735 colors,
1730 } 1736 lineIndices.get(),
1731 } else { 1737 indexCount);
1732 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, 1738 return;
1733 nullptr == colors, &grPaint)) {
1734 return;
1735 }
1736 }
1737 } 1739 }
1738 1740
1739 #if 0 1741 GrPrimitiveType primType = gVertexMode2PrimitiveType[vmode];
1740 if (xmode && texs && colors) {
1741 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) {
1742 SkDebugf("Unsupported vertex-color/texture xfer mode.\n");
1743 return;
1744 }
1745 }
1746 #endif
1747 1742
1748 SkAutoSTMalloc<128, GrColor> convertedColors(0); 1743 SkAutoSTMalloc<128, GrColor> convertedColors(0);
1749 if (colors) { 1744 if (colors) {
1750 // need to convert byte order and from non-PM to PM 1745 // need to convert byte order and from non-PM to PM
1751 convertedColors.reset(vertexCount); 1746 convertedColors.reset(vertexCount);
1752 SkColor color; 1747 SkColor color;
1753 for (int i = 0; i < vertexCount; ++i) { 1748 for (int i = 0; i < vertexCount; ++i) {
1754 color = colors[i]; 1749 color = colors[i];
1755 if (paint.getAlpha() != 255) { 1750 if (paint.getAlpha() != 255) {
1756 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); 1751 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha()));
1757 } 1752 }
1758 convertedColors[i] = SkColor2GrColor(color); 1753 /// TODO: Perform the premul after interpolating
1754 convertedColors[i] = SkColorToPremulGrColor(color);
1759 } 1755 }
1760 colors = convertedColors.get(); 1756 colors = convertedColors.get();
1761 } 1757 }
1758 GrPaint grPaint;
1759 if (texs && colors && paint.getShader()) {
1760 // When there are texs and colors the shader and colors are combined usi ng xmode. A null
1761 // xmode is defined to mean modulate.
1762 SkXfermode::Mode colorMode;
1763 if (xmode) {
1764 if (!xmode->asMode(&colorMode)) {
1765 return;
1766 }
1767 } else {
1768 colorMode = SkXfermode::kModulate_Mode;
1769 }
1770 if (!SkPaintToGrPaintWithXfermode(this->context(), paint, *draw.fMatrix, colorMode, false,
1771 &grPaint)) {
1772 return;
1773 }
1774 } else if (!texs) {
1775 // Defined to ignore the shader unless texs is provided.
1776 if (!SkPaintToGrPaintNoShader(this->context(), paint, &grPaint)) {
1777 return;
1778 }
1779 } else if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint )) {
1780 return;
1781 }
1782
1762 fDrawContext->drawVertices(fRenderTarget, 1783 fDrawContext->drawVertices(fRenderTarget,
1763 fClip, 1784 fClip,
1764 grPaint, 1785 grPaint,
1765 *draw.fMatrix, 1786 *draw.fMatrix,
1766 primType, 1787 primType,
1767 vertexCount, 1788 vertexCount,
1768 vertices, 1789 vertices,
1769 texs, 1790 texs,
1770 colors, 1791 colors,
1771 outIndices, 1792 indices,
1772 indexCount); 1793 indexCount);
1773 } 1794 }
1774 1795
1775 /////////////////////////////////////////////////////////////////////////////// 1796 ///////////////////////////////////////////////////////////////////////////////
1776 1797
1777 void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS Xform xform[], 1798 void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS Xform xform[],
1778 const SkRect texRect[], const SkColor colors[], int count, 1799 const SkRect texRect[], const SkColor colors[], int count,
1779 SkXfermode::Mode mode, const SkPaint& paint) { 1800 SkXfermode::Mode mode, const SkPaint& paint) {
1780 if (paint.isAntiAlias()) { 1801 if (paint.isAntiAlias()) {
1781 this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, m ode, paint); 1802 this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, m ode, paint);
1782 return; 1803 return;
1783 } 1804 }
1784 1805
1785 CHECK_SHOULD_DRAW(draw); 1806 CHECK_SHOULD_DRAW(draw);
1786 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); 1807 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
1787 1808
1788 SkPaint p(paint); 1809 SkPaint p(paint);
1789 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode))->unref(); 1810 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode))->unref();
1790 1811
1791 GrPaint grPaint; 1812 GrPaint grPaint;
1792 if (!SkPaint2GrPaint(this->context(), p, *draw.fMatrix, !colors, &grPaint)) {
1793 return;
1794 }
1795
1796 SkDEBUGCODE(this->validate();)
1797
1798 #if 0
1799 if (colors) { 1813 if (colors) {
1800 if (SkXfermode::kModulate_Mode != mode) { 1814 if (!SkPaintToGrPaintWithXfermode(this->context(), p, *draw.fMatrix, mod e, true,
1801 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); 1815 &grPaint)) {
1816 return;
1817 }
1818 } else {
1819 if (!SkPaintToGrPaint(this->context(), p, *draw.fMatrix, &grPaint)) {
1802 return; 1820 return;
1803 } 1821 }
1804 } 1822 }
1805 #endif 1823
1806 1824 SkDEBUGCODE(this->validate();)
1807 fDrawContext->drawAtlas(fRenderTarget, fClip, grPaint, *draw.fMatrix, 1825 fDrawContext->drawAtlas(fRenderTarget, fClip, grPaint, *draw.fMatrix,
1808 count, xform, texRect, colors); 1826 count, xform, texRect, colors);
1809 } 1827 }
1810 1828
1811 /////////////////////////////////////////////////////////////////////////////// 1829 ///////////////////////////////////////////////////////////////////////////////
1812 1830
1813 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, 1831 void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
1814 size_t byteLength, SkScalar x, SkScalar y, 1832 size_t byteLength, SkScalar x, SkScalar y,
1815 const SkPaint& paint) { 1833 const SkPaint& paint) {
1816 CHECK_SHOULD_DRAW(draw); 1834 CHECK_SHOULD_DRAW(draw);
1817 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); 1835 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
1818 1836
1819 GrPaint grPaint; 1837 GrPaint grPaint;
1820 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { 1838 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
1821 return; 1839 return;
1822 } 1840 }
1823 1841
1824 SkDEBUGCODE(this->validate();) 1842 SkDEBUGCODE(this->validate();)
1825 1843
1826 fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, 1844 fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix,
1827 (const char *)text, byteLength, x, y, draw.fClip->get Bounds()); 1845 (const char *)text, byteLength, x, y, draw.fClip->get Bounds());
1828 } 1846 }
1829 1847
1830 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL ength, 1848 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL ength,
1831 const SkScalar pos[], int scalarsPerPos, 1849 const SkScalar pos[], int scalarsPerPos,
1832 const SkPoint& offset, const SkPaint& paint) { 1850 const SkPoint& offset, const SkPaint& paint) {
1833 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); 1851 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext);
1834 CHECK_SHOULD_DRAW(draw); 1852 CHECK_SHOULD_DRAW(draw);
1835 1853
1836 GrPaint grPaint; 1854 GrPaint grPaint;
1837 if (!SkPaint2GrPaint(this->context(), paint, *draw.fMatrix, true, &grPaint)) { 1855 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
1838 return; 1856 return;
1839 } 1857 }
1840 1858
1841 SkDEBUGCODE(this->validate();) 1859 SkDEBUGCODE(this->validate();)
1842 1860
1843 fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri x, 1861 fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri x,
1844 (const char *)text, byteLength, pos, scalarsPerPos , offset, 1862 (const char *)text, byteLength, pos, scalarsPerPos , offset,
1845 draw.fClip->getBounds()); 1863 draw.fClip->getBounds());
1846 } 1864 }
1847 1865
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 #endif 1993 #endif
1976 } 1994 }
1977 1995
1978 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1996 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1979 // We always return a transient cache, so it is freed after each 1997 // We always return a transient cache, so it is freed after each
1980 // filter traversal. 1998 // filter traversal.
1981 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1999 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1982 } 2000 }
1983 2001
1984 #endif 2002 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrTextContext.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698