| OLD | NEW |
| 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" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 191 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
| 192 | 192 |
| 193 fRenderTarget = SkRef(rt); | 193 fRenderTarget = SkRef(rt); |
| 194 | 194 |
| 195 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 195 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 196 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); | 196 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); |
| 197 SkPixelRef* pr = new SkGrPixelRef(info, rt); | 197 SkPixelRef* pr = new SkGrPixelRef(info, rt); |
| 198 fLegacyBitmap.setInfo(info); | 198 fLegacyBitmap.setInfo(info); |
| 199 fLegacyBitmap.setPixelRef(pr)->unref(); | 199 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 200 | 200 |
| 201 fDrawContext.reset(fContext->drawContext(&this->surfaceProps())); | 201 fDrawContext.reset(fContext->drawContext(rt, &this->surfaceProps())); |
| 202 } | 202 } |
| 203 | 203 |
| 204 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, | 204 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, |
| 205 const SkImageInfo& origInfo, int
sampleCount) { | 205 const SkImageInfo& origInfo, int
sampleCount) { |
| 206 if (kUnknown_SkColorType == origInfo.colorType() || | 206 if (kUnknown_SkColorType == origInfo.colorType() || |
| 207 origInfo.width() < 0 || origInfo.height() < 0) { | 207 origInfo.width() < 0 || origInfo.height() < 0) { |
| 208 return nullptr; | 208 return nullptr; |
| 209 } | 209 } |
| 210 | 210 |
| 211 if (!context) { | 211 if (!context) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 GrRenderTarget* SkGpuDevice::accessRenderTarget() { | 330 GrRenderTarget* SkGpuDevice::accessRenderTarget() { |
| 331 DO_DEFERRED_CLEAR(); | 331 DO_DEFERRED_CLEAR(); |
| 332 return fRenderTarget; | 332 return fRenderTarget; |
| 333 } | 333 } |
| 334 | 334 |
| 335 void SkGpuDevice::clearAll() { | 335 void SkGpuDevice::clearAll() { |
| 336 GrColor color = 0; | 336 GrColor color = 0; |
| 337 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); | 337 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); |
| 338 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 338 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
| 339 fDrawContext->clear(fRenderTarget, &rect, color, true); | 339 fDrawContext->clear(&rect, color, true); |
| 340 fNeedClear = false; | 340 fNeedClear = false; |
| 341 } | 341 } |
| 342 | 342 |
| 343 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { | 343 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { |
| 344 // Caller must have accessed the render target, because it knows the rt must
be replaced. | 344 // Caller must have accessed the render target, because it knows the rt must
be replaced. |
| 345 SkASSERT(!fNeedClear); | 345 SkASSERT(!fNeedClear); |
| 346 | 346 |
| 347 SkSurface::Budgeted budgeted = | 347 SkSurface::Budgeted budgeted = |
| 348 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d | 348 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d |
| 349 : SkSurface::kNo_Budgeted
; | 349 : SkSurface::kNo_Budgeted
; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 368 fRenderTarget = newRT.detach(); | 368 fRenderTarget = newRT.detach(); |
| 369 | 369 |
| 370 #ifdef SK_DEBUG | 370 #ifdef SK_DEBUG |
| 371 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : | 371 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : |
| 372 kPremul_SkAlp
haType); | 372 kPremul_SkAlp
haType); |
| 373 SkASSERT(info == fLegacyBitmap.info()); | 373 SkASSERT(info == fLegacyBitmap.info()); |
| 374 #endif | 374 #endif |
| 375 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); | 375 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); |
| 376 fLegacyBitmap.setPixelRef(pr)->unref(); | 376 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 377 | 377 |
| 378 fDrawContext.reset(fRenderTarget->getContext()->drawContext(&this->surfacePr
ops())); | 378 fDrawContext.reset(fRenderTarget->getContext()->drawContext(fRenderTarget, |
| 379 &this->surfacePr
ops())); |
| 379 } | 380 } |
| 380 | 381 |
| 381 /////////////////////////////////////////////////////////////////////////////// | 382 /////////////////////////////////////////////////////////////////////////////// |
| 382 | 383 |
| 383 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 384 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
| 384 CHECK_SHOULD_DRAW(draw); | 385 CHECK_SHOULD_DRAW(draw); |
| 385 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); | 386 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); |
| 386 | 387 |
| 387 GrPaint grPaint; | 388 GrPaint grPaint; |
| 388 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 389 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
| 389 return; | 390 return; |
| 390 } | 391 } |
| 391 | 392 |
| 392 fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix); | 393 fDrawContext->drawPaint(fClip, grPaint, *draw.fMatrix); |
| 393 } | 394 } |
| 394 | 395 |
| 395 // must be in SkCanvas::PointMode order | 396 // must be in SkCanvas::PointMode order |
| 396 static const GrPrimitiveType gPointMode2PrimtiveType[] = { | 397 static const GrPrimitiveType gPointMode2PrimtiveType[] = { |
| 397 kPoints_GrPrimitiveType, | 398 kPoints_GrPrimitiveType, |
| 398 kLines_GrPrimitiveType, | 399 kLines_GrPrimitiveType, |
| 399 kLineStrip_GrPrimitiveType | 400 kLineStrip_GrPrimitiveType |
| 400 }; | 401 }; |
| 401 | 402 |
| 402 // suppress antialiasing on axis-aligned integer-coordinate lines | 403 // suppress antialiasing on axis-aligned integer-coordinate lines |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { | 435 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { |
| 435 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); | 436 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
| 436 GrPaint grPaint; | 437 GrPaint grPaint; |
| 437 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint))
{ | 438 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint))
{ |
| 438 return; | 439 return; |
| 439 } | 440 } |
| 440 SkPath path; | 441 SkPath path; |
| 441 path.setIsVolatile(true); | 442 path.setIsVolatile(true); |
| 442 path.moveTo(pts[0]); | 443 path.moveTo(pts[0]); |
| 443 path.lineTo(pts[1]); | 444 path.lineTo(pts[1]); |
| 444 fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, pat
h, strokeInfo); | 445 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, strokeInfo); |
| 445 return; | 446 return; |
| 446 } | 447 } |
| 447 | 448 |
| 448 // we only handle non-antialiased hairlines and paints without path effects
or mask filters, | 449 // we only handle non-antialiased hairlines and paints without path effects
or mask filters, |
| 449 // else we let the SkDraw call our drawPath() | 450 // else we let the SkDraw call our drawPath() |
| 450 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || | 451 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || |
| 451 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { | 452 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { |
| 452 draw.drawPoints(mode, count, pts, paint, true); | 453 draw.drawPoints(mode, count, pts, paint, true); |
| 453 return; | 454 return; |
| 454 } | 455 } |
| 455 | 456 |
| 456 GrPaint grPaint; | 457 GrPaint grPaint; |
| 457 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 458 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
| 458 return; | 459 return; |
| 459 } | 460 } |
| 460 | 461 |
| 461 fDrawContext->drawVertices(fRenderTarget, | 462 fDrawContext->drawVertices(fClip, |
| 462 fClip, | |
| 463 grPaint, | 463 grPaint, |
| 464 *draw.fMatrix, | 464 *draw.fMatrix, |
| 465 gPointMode2PrimtiveType[mode], | 465 gPointMode2PrimtiveType[mode], |
| 466 SkToS32(count), | 466 SkToS32(count), |
| 467 (SkPoint*)pts, | 467 (SkPoint*)pts, |
| 468 nullptr, | 468 nullptr, |
| 469 nullptr, | 469 nullptr, |
| 470 nullptr, | 470 nullptr, |
| 471 0); | 471 0); |
| 472 } | 472 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 path.addRect(rect); | 514 path.addRect(rect); |
| 515 this->drawPath(draw, path, paint, nullptr, true); | 515 this->drawPath(draw, path, paint, nullptr, true); |
| 516 return; | 516 return; |
| 517 } | 517 } |
| 518 | 518 |
| 519 GrPaint grPaint; | 519 GrPaint grPaint; |
| 520 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 520 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
| 521 return; | 521 return; |
| 522 } | 522 } |
| 523 | 523 |
| 524 fDrawContext->drawRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect, &
strokeInfo); | 524 fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &strokeInfo); |
| 525 } | 525 } |
| 526 | 526 |
| 527 /////////////////////////////////////////////////////////////////////////////// | 527 /////////////////////////////////////////////////////////////////////////////// |
| 528 | 528 |
| 529 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 529 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
| 530 const SkPaint& paint) { | 530 const SkPaint& paint) { |
| 531 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext); | 531 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext); |
| 532 CHECK_FOR_ANNOTATION(paint); | 532 CHECK_FOR_ANNOTATION(paint); |
| 533 CHECK_SHOULD_DRAW(draw); | 533 CHECK_SHOULD_DRAW(draw); |
| 534 | 534 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 550 *draw.fMatrix, | 550 *draw.fMatrix, |
| 551 &maskRect)) { | 551 &maskRect)) { |
| 552 SkIRect finalIRect; | 552 SkIRect finalIRect; |
| 553 maskRect.roundOut(&finalIRect); | 553 maskRect.roundOut(&finalIRect); |
| 554 if (draw.fClip->quickReject(finalIRect)) { | 554 if (draw.fClip->quickReject(finalIRect)) { |
| 555 // clipped out | 555 // clipped out |
| 556 return; | 556 return; |
| 557 } | 557 } |
| 558 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext
->textureProvider(), | 558 if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext
->textureProvider(), |
| 559 fDrawCon
text, | 559 fDrawCon
text, |
| 560 fRenderT
arget, | |
| 561 &grPaint
, | 560 &grPaint
, |
| 562 fClip, | 561 fClip, |
| 563 *draw.fM
atrix, | 562 *draw.fM
atrix, |
| 564 strokeIn
fo, | 563 strokeIn
fo, |
| 565 devRRect
)) { | 564 devRRect
)) { |
| 566 return; | 565 return; |
| 567 } | 566 } |
| 568 } | 567 } |
| 569 | 568 |
| 570 } | 569 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 585 | 584 |
| 586 | 585 |
| 587 if (usePath) { | 586 if (usePath) { |
| 588 SkPath path; | 587 SkPath path; |
| 589 path.setIsVolatile(true); | 588 path.setIsVolatile(true); |
| 590 path.addRRect(rect); | 589 path.addRRect(rect); |
| 591 this->drawPath(draw, path, paint, nullptr, true); | 590 this->drawPath(draw, path, paint, nullptr, true); |
| 592 return; | 591 return; |
| 593 } | 592 } |
| 594 | 593 |
| 595 fDrawContext->drawRRect(fRenderTarget, fClip, grPaint, *draw.fMatrix, rect,
strokeInfo); | 594 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); |
| 596 } | 595 } |
| 597 | 596 |
| 598 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 597 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
| 599 const SkRRect& inner, const SkPaint& paint) { | 598 const SkRRect& inner, const SkPaint& paint) { |
| 600 SkStrokeRec stroke(paint); | 599 SkStrokeRec stroke(paint); |
| 601 if (stroke.isFillStyle()) { | 600 if (stroke.isFillStyle()) { |
| 602 | 601 |
| 603 CHECK_FOR_ANNOTATION(paint); | 602 CHECK_FOR_ANNOTATION(paint); |
| 604 CHECK_SHOULD_DRAW(draw); | 603 CHECK_SHOULD_DRAW(draw); |
| 605 | 604 |
| 606 GrPaint grPaint; | 605 GrPaint grPaint; |
| 607 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint))
{ | 606 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint))
{ |
| 608 return; | 607 return; |
| 609 } | 608 } |
| 610 | 609 |
| 611 if (nullptr == paint.getMaskFilter() && nullptr == paint.getPathEffect()
) { | 610 if (nullptr == paint.getMaskFilter() && nullptr == paint.getPathEffect()
) { |
| 612 fDrawContext->drawDRRect(fRenderTarget, fClip, grPaint, *draw.fMatri
x, outer, inner); | 611 fDrawContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner
); |
| 613 return; | 612 return; |
| 614 } | 613 } |
| 615 } | 614 } |
| 616 | 615 |
| 617 SkPath path; | 616 SkPath path; |
| 618 path.setIsVolatile(true); | 617 path.setIsVolatile(true); |
| 619 path.addRRect(outer); | 618 path.addRRect(outer); |
| 620 path.addRRect(inner); | 619 path.addRRect(inner); |
| 621 path.setFillType(SkPath::kEvenOdd_FillType); | 620 path.setFillType(SkPath::kEvenOdd_FillType); |
| 622 | 621 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 653 path.addOval(oval); | 652 path.addOval(oval); |
| 654 this->drawPath(draw, path, paint, nullptr, true); | 653 this->drawPath(draw, path, paint, nullptr, true); |
| 655 return; | 654 return; |
| 656 } | 655 } |
| 657 | 656 |
| 658 GrPaint grPaint; | 657 GrPaint grPaint; |
| 659 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 658 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
| 660 return; | 659 return; |
| 661 } | 660 } |
| 662 | 661 |
| 663 fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, s
trokeInfo); | 662 fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, strokeInfo); |
| 664 } | 663 } |
| 665 | 664 |
| 666 #include "SkMaskFilter.h" | 665 #include "SkMaskFilter.h" |
| 667 | 666 |
| 668 /////////////////////////////////////////////////////////////////////////////// | 667 /////////////////////////////////////////////////////////////////////////////// |
| 669 | 668 |
| 670 static SkBitmap wrap_texture(GrTexture* texture, int width, int height) { | 669 static SkBitmap wrap_texture(GrTexture* texture, int width, int height) { |
| 671 SkBitmap result; | 670 SkBitmap result; |
| 672 result.setInfo(SkImageInfo::MakeN32Premul(width, height)); | 671 result.setInfo(SkImageInfo::MakeN32Premul(width, height)); |
| 673 result.setPixelRef(new SkGrPixelRef(result.info(), texture))->unref(); | 672 result.setPixelRef(new SkGrPixelRef(result.info(), texture))->unref(); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 return; | 1025 return; |
| 1027 } | 1026 } |
| 1028 matrix.preConcat(dstRectToSrcRect); | 1027 matrix.preConcat(dstRectToSrcRect); |
| 1029 | 1028 |
| 1030 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill(grPaint.get
Color(), | 1029 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill(grPaint.get
Color(), |
| 1031 viewMatrix, | 1030 viewMatrix, |
| 1032 matrix, | 1031 matrix, |
| 1033 dstRect, | 1032 dstRect, |
| 1034 devRect)); | 1033 devRect)); |
| 1035 | 1034 |
| 1036 drawContext->drawBatch(renderTarget, clip, grPaint, batch); | 1035 drawContext->drawBatch(clip, grPaint, batch); |
| 1037 } | 1036 } |
| 1038 | 1037 |
| 1039 static bool can_ignore_strict_subset_constraint(const SkBitmap& bitmap, const Sk
Rect& subset) { | 1038 static bool can_ignore_strict_subset_constraint(const SkBitmap& bitmap, const Sk
Rect& subset) { |
| 1040 GrTexture* tex = bitmap.getTexture(); | 1039 GrTexture* tex = bitmap.getTexture(); |
| 1041 int width = tex ? tex->width() : bitmap.width(); | 1040 int width = tex ? tex->width() : bitmap.width(); |
| 1042 int height = tex ? tex->height() : bitmap.height(); | 1041 int height = tex ? tex->height() : bitmap.height(); |
| 1043 return subset.contains(SkRect::MakeIWH(width, height)); | 1042 return subset.contains(SkRect::MakeIWH(width, height)); |
| 1044 } | 1043 } |
| 1045 | 1044 |
| 1046 void SkGpuDevice::drawBitmapCommon(const SkDraw& draw, | 1045 void SkGpuDevice::drawBitmapCommon(const SkDraw& draw, |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | 1373 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); |
| 1375 } | 1374 } |
| 1376 | 1375 |
| 1377 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { | 1376 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { |
| 1378 return; | 1377 return; |
| 1379 } | 1378 } |
| 1380 | 1379 |
| 1381 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { | 1380 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { |
| 1382 // We don't have local coords in this case and have previously set the t
ransform | 1381 // We don't have local coords in this case and have previously set the t
ransform |
| 1383 // matrices directly on the texture processor. | 1382 // matrices directly on the texture processor. |
| 1384 fDrawContext->drawRect(fRenderTarget, fClip, grPaint, viewMatrix, dstRec
t); | 1383 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); |
| 1385 } else { | 1384 } else { |
| 1386 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMat
rix, dstRect, | 1385 fDrawContext->drawNonAARectToRect(fClip, grPaint, viewMatrix, dstRect, p
aintRect); |
| 1387 paintRect); | |
| 1388 } | 1386 } |
| 1389 } | 1387 } |
| 1390 | 1388 |
| 1391 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, | 1389 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, |
| 1392 int width, int height, | 1390 int width, int height, |
| 1393 const SkImageFilter* filter, | 1391 const SkImageFilter* filter, |
| 1394 const SkImageFilter::Context& ctx, | 1392 const SkImageFilter::Context& ctx, |
| 1395 SkBitmap* result, SkIPoint* offset) { | 1393 SkBitmap* result, SkIPoint* offset) { |
| 1396 SkASSERT(filter); | 1394 SkASSERT(filter); |
| 1397 | 1395 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 GrSimpleTextureEffect::Create(texture, SkMatrix::I())); | 1457 GrSimpleTextureEffect::Create(texture, SkMatrix::I())); |
| 1460 if (alphaOnly) { | 1458 if (alphaOnly) { |
| 1461 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | 1459 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); |
| 1462 } else { | 1460 } else { |
| 1463 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | 1461 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); |
| 1464 } | 1462 } |
| 1465 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { | 1463 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, &grPaint)) { |
| 1466 return; | 1464 return; |
| 1467 } | 1465 } |
| 1468 | 1466 |
| 1469 fDrawContext->drawNonAARectToRect(fRenderTarget, | 1467 fDrawContext->drawNonAARectToRect(fClip, |
| 1470 fClip, | |
| 1471 grPaint, | 1468 grPaint, |
| 1472 SkMatrix::I(), | 1469 SkMatrix::I(), |
| 1473 SkRect::MakeXYWH(SkIntToScalar(left), | 1470 SkRect::MakeXYWH(SkIntToScalar(left), |
| 1474 SkIntToScalar(top), | 1471 SkIntToScalar(top), |
| 1475 SkIntToScalar(w), | 1472 SkIntToScalar(w), |
| 1476 SkIntToScalar(h)), | 1473 SkIntToScalar(h)), |
| 1477 SkRect::MakeXYWH(0, | 1474 SkRect::MakeXYWH(0, |
| 1478 0, | 1475 0, |
| 1479 SK_Scalar1 * w / texture-
>width(), | 1476 SK_Scalar1 * w / texture-
>width(), |
| 1480 SK_Scalar1 * h / texture-
>height())); | 1477 SK_Scalar1 * h / texture-
>height())); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), | 1587 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
| 1591 SkIntToScalar(y), | 1588 SkIntToScalar(y), |
| 1592 SkIntToScalar(w), | 1589 SkIntToScalar(w), |
| 1593 SkIntToScalar(h)); | 1590 SkIntToScalar(h)); |
| 1594 | 1591 |
| 1595 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate | 1592 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate |
| 1596 // scratch texture). | 1593 // scratch texture). |
| 1597 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), | 1594 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), |
| 1598 SK_Scalar1 * h / devTex->height()); | 1595 SK_Scalar1 * h / devTex->height()); |
| 1599 | 1596 |
| 1600 fDrawContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, SkMatrix::I
(), dstRect, | 1597 fDrawContext->drawNonAARectToRect(fClip, grPaint, SkMatrix::I(), dstRect, sr
cRect); |
| 1601 srcRect); | |
| 1602 } | 1598 } |
| 1603 | 1599 |
| 1604 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { | 1600 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { |
| 1605 return filter->canFilterImageGPU(); | 1601 return filter->canFilterImageGPU(); |
| 1606 } | 1602 } |
| 1607 | 1603 |
| 1608 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, | 1604 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, |
| 1609 const SkImageFilter::Context& ctx, | 1605 const SkImageFilter::Context& ctx, |
| 1610 SkBitmap* result, SkIPoint* offset) { | 1606 SkBitmap* result, SkIPoint* offset) { |
| 1611 // want explicitly our impl, so guard against a subclass of us overriding it | 1607 // want explicitly our impl, so guard against a subclass of us overriding it |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 int i = 0; | 1738 int i = 0; |
| 1743 while (vertProc(&state)) { | 1739 while (vertProc(&state)) { |
| 1744 lineIndices[i] = state.f0; | 1740 lineIndices[i] = state.f0; |
| 1745 lineIndices[i + 1] = state.f1; | 1741 lineIndices[i + 1] = state.f1; |
| 1746 lineIndices[i + 2] = state.f1; | 1742 lineIndices[i + 2] = state.f1; |
| 1747 lineIndices[i + 3] = state.f2; | 1743 lineIndices[i + 3] = state.f2; |
| 1748 lineIndices[i + 4] = state.f2; | 1744 lineIndices[i + 4] = state.f2; |
| 1749 lineIndices[i + 5] = state.f0; | 1745 lineIndices[i + 5] = state.f0; |
| 1750 i += 6; | 1746 i += 6; |
| 1751 } | 1747 } |
| 1752 fDrawContext->drawVertices(fRenderTarget, | 1748 fDrawContext->drawVertices(fClip, |
| 1753 fClip, | |
| 1754 grPaint, | 1749 grPaint, |
| 1755 *draw.fMatrix, | 1750 *draw.fMatrix, |
| 1756 kLines_GrPrimitiveType, | 1751 kLines_GrPrimitiveType, |
| 1757 vertexCount, | 1752 vertexCount, |
| 1758 vertices, | 1753 vertices, |
| 1759 texs, | 1754 texs, |
| 1760 colors, | 1755 colors, |
| 1761 lineIndices.get(), | 1756 lineIndices.get(), |
| 1762 indexCount); | 1757 indexCount); |
| 1763 return; | 1758 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 return; | 1801 return; |
| 1807 } | 1802 } |
| 1808 } else { | 1803 } else { |
| 1809 // No colors and no shaders. Just draw with the paint color. | 1804 // No colors and no shaders. Just draw with the paint color. |
| 1810 if (!SkPaintToGrPaintNoShader(this->context(), paint, &grPaint)) { | 1805 if (!SkPaintToGrPaintNoShader(this->context(), paint, &grPaint)) { |
| 1811 return; | 1806 return; |
| 1812 } | 1807 } |
| 1813 } | 1808 } |
| 1814 } | 1809 } |
| 1815 | 1810 |
| 1816 fDrawContext->drawVertices(fRenderTarget, | 1811 fDrawContext->drawVertices(fClip, |
| 1817 fClip, | |
| 1818 grPaint, | 1812 grPaint, |
| 1819 *draw.fMatrix, | 1813 *draw.fMatrix, |
| 1820 primType, | 1814 primType, |
| 1821 vertexCount, | 1815 vertexCount, |
| 1822 vertices, | 1816 vertices, |
| 1823 texs, | 1817 texs, |
| 1824 colors, | 1818 colors, |
| 1825 indices, | 1819 indices, |
| 1826 indexCount); | 1820 indexCount); |
| 1827 } | 1821 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1848 &grPaint)) { | 1842 &grPaint)) { |
| 1849 return; | 1843 return; |
| 1850 } | 1844 } |
| 1851 } else { | 1845 } else { |
| 1852 if (!SkPaintToGrPaint(this->context(), p, *draw.fMatrix, &grPaint)) { | 1846 if (!SkPaintToGrPaint(this->context(), p, *draw.fMatrix, &grPaint)) { |
| 1853 return; | 1847 return; |
| 1854 } | 1848 } |
| 1855 } | 1849 } |
| 1856 | 1850 |
| 1857 SkDEBUGCODE(this->validate();) | 1851 SkDEBUGCODE(this->validate();) |
| 1858 fDrawContext->drawAtlas(fRenderTarget, fClip, grPaint, *draw.fMatrix, | 1852 fDrawContext->drawAtlas(fClip, grPaint, *draw.fMatrix, count, xform, texRect
, colors); |
| 1859 count, xform, texRect, colors); | |
| 1860 } | 1853 } |
| 1861 | 1854 |
| 1862 /////////////////////////////////////////////////////////////////////////////// | 1855 /////////////////////////////////////////////////////////////////////////////// |
| 1863 | 1856 |
| 1864 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1857 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
| 1865 size_t byteLength, SkScalar x, SkScalar y, | 1858 size_t byteLength, SkScalar x, SkScalar y, |
| 1866 const SkPaint& paint) { | 1859 const SkPaint& paint) { |
| 1867 CHECK_SHOULD_DRAW(draw); | 1860 CHECK_SHOULD_DRAW(draw); |
| 1868 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1861 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
| 1869 | 1862 |
| 1870 GrPaint grPaint; | 1863 GrPaint grPaint; |
| 1871 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 1864 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
| 1872 return; | 1865 return; |
| 1873 } | 1866 } |
| 1874 | 1867 |
| 1875 SkDEBUGCODE(this->validate();) | 1868 SkDEBUGCODE(this->validate();) |
| 1876 | 1869 |
| 1877 fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, | 1870 fDrawContext->drawText(fClip, grPaint, paint, *draw.fMatrix, |
| 1878 (const char *)text, byteLength, x, y, draw.fClip->get
Bounds()); | 1871 (const char *)text, byteLength, x, y, draw.fClip->get
Bounds()); |
| 1879 } | 1872 } |
| 1880 | 1873 |
| 1881 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
ength, | 1874 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
ength, |
| 1882 const SkScalar pos[], int scalarsPerPos, | 1875 const SkScalar pos[], int scalarsPerPos, |
| 1883 const SkPoint& offset, const SkPaint& paint) { | 1876 const SkPoint& offset, const SkPaint& paint) { |
| 1884 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); | 1877 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); |
| 1885 CHECK_SHOULD_DRAW(draw); | 1878 CHECK_SHOULD_DRAW(draw); |
| 1886 | 1879 |
| 1887 GrPaint grPaint; | 1880 GrPaint grPaint; |
| 1888 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 1881 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
| 1889 return; | 1882 return; |
| 1890 } | 1883 } |
| 1891 | 1884 |
| 1892 SkDEBUGCODE(this->validate();) | 1885 SkDEBUGCODE(this->validate();) |
| 1893 | 1886 |
| 1894 fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri
x, | 1887 fDrawContext->drawPosText(fClip, grPaint, paint, *draw.fMatrix, |
| 1895 (const char *)text, byteLength, pos, scalarsPerPos
, offset, | 1888 (const char *)text, byteLength, pos, scalarsPerPos
, offset, |
| 1896 draw.fClip->getBounds()); | 1889 draw.fClip->getBounds()); |
| 1897 } | 1890 } |
| 1898 | 1891 |
| 1899 void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca
lar x, SkScalar y, | 1892 void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca
lar x, SkScalar y, |
| 1900 const SkPaint& paint, SkDrawFilter* drawFilter) { | 1893 const SkPaint& paint, SkDrawFilter* drawFilter) { |
| 1901 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawTextBlob", fContext); | 1894 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawTextBlob", fContext); |
| 1902 CHECK_SHOULD_DRAW(draw); | 1895 CHECK_SHOULD_DRAW(draw); |
| 1903 | 1896 |
| 1904 SkDEBUGCODE(this->validate();) | 1897 SkDEBUGCODE(this->validate();) |
| 1905 | 1898 |
| 1906 fDrawContext->drawTextBlob(fRenderTarget, fClip, paint, *draw.fMatrix, | 1899 fDrawContext->drawTextBlob(fClip, paint, *draw.fMatrix, |
| 1907 blob, x, y, drawFilter, draw.fClip->getBounds()); | 1900 blob, x, y, drawFilter, draw.fClip->getBounds()); |
| 1908 } | 1901 } |
| 1909 | 1902 |
| 1910 /////////////////////////////////////////////////////////////////////////////// | 1903 /////////////////////////////////////////////////////////////////////////////// |
| 1911 | 1904 |
| 1912 bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const { | 1905 bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const { |
| 1913 return GrTextContext::ShouldDisableLCD(paint); | 1906 return GrTextContext::ShouldDisableLCD(paint); |
| 1914 } | 1907 } |
| 1915 | 1908 |
| 1916 void SkGpuDevice::flush() { | 1909 void SkGpuDevice::flush() { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2026 #endif | 2019 #endif |
| 2027 } | 2020 } |
| 2028 | 2021 |
| 2029 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2022 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2030 // We always return a transient cache, so it is freed after each | 2023 // We always return a transient cache, so it is freed after each |
| 2031 // filter traversal. | 2024 // filter traversal. |
| 2032 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2025 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2033 } | 2026 } |
| 2034 | 2027 |
| 2035 #endif | 2028 #endif |
| OLD | NEW |