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 "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 /////////////////////////////////////////////////////////////////////////////// | 567 /////////////////////////////////////////////////////////////////////////////// |
568 | 568 |
569 // helpers for applying mask filters | 569 // helpers for applying mask filters |
570 namespace { | 570 namespace { |
571 | 571 |
572 // Draw a mask using the supplied paint. Since the coverage/geometry | 572 // Draw a mask using the supplied paint. Since the coverage/geometry |
573 // is already burnt into the mask this boils down to a rect draw. | 573 // is already burnt into the mask this boils down to a rect draw. |
574 // Return true if the mask was successfully drawn. | 574 // Return true if the mask was successfully drawn. |
575 bool draw_mask(GrContext* context, const SkMatrix& viewMatrix, const SkRect& mas
kRect, | 575 bool draw_mask(GrContext* context, const SkMatrix& viewMatrix, const SkRect& mas
kRect, |
576 GrPaint* grp, GrTexture* mask) { | 576 GrPaint* grp, GrTexture* mask) { |
577 if (!grp->localCoordChangeInverse(viewMatrix)) { | |
578 return false; | |
579 } | |
580 | |
581 SkMatrix matrix; | 577 SkMatrix matrix; |
582 matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop); | 578 matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop); |
583 matrix.postIDiv(mask->width(), mask->height()); | 579 matrix.postIDiv(mask->width(), mask->height()); |
584 | 580 |
585 grp->addCoverageProcessor(GrSimpleTextureEffect::Create(mask, matrix))->unre
f(); | 581 grp->addCoverageProcessor(GrSimpleTextureEffect::Create(mask, matrix, |
586 context->drawRect(*grp, SkMatrix::I(), maskRect); | 582 kDevice_GrCoordSet))
->unref(); |
| 583 |
| 584 SkMatrix inverse; |
| 585 if (!viewMatrix.invert(&inverse)) { |
| 586 return false; |
| 587 } |
| 588 context->drawNonAARectWithLocalMatrix(*grp, SkMatrix::I(), maskRect, inverse
); |
587 return true; | 589 return true; |
588 } | 590 } |
589 | 591 |
590 bool draw_with_mask_filter(GrContext* context, const SkMatrix& viewMatrix, const
SkPath& devPath, | 592 bool draw_with_mask_filter(GrContext* context, const SkMatrix& viewMatrix, const
SkPath& devPath, |
591 SkMaskFilter* filter, const SkRegion& clip, | 593 SkMaskFilter* filter, const SkRegion& clip, |
592 GrPaint* grp, SkPaint::Style style) { | 594 GrPaint* grp, SkPaint::Style style) { |
593 SkMask srcM, dstM; | 595 SkMask srcM, dstM; |
594 | 596 |
595 if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &viewMatrix, &sr
cM, | 597 if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &viewMatrix, &sr
cM, |
596 SkMask::kComputeBoundsAndRenderImage_CreateMode, sty
le)) { | 598 SkMask::kComputeBoundsAndRenderImage_CreateMode, sty
le)) { |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 | 1376 |
1375 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring | 1377 // Construct a GrPaint by setting the bitmap texture as the first effect and
then configuring |
1376 // the rest from the SkPaint. | 1378 // the rest from the SkPaint. |
1377 GrPaint grPaint; | 1379 GrPaint grPaint; |
1378 grPaint.addColorProcessor(fp); | 1380 grPaint.addColorProcessor(fp); |
1379 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); | 1381 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); |
1380 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()
) : | 1382 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()
) : |
1381 SkColor2GrColor(paint.getColor()); | 1383 SkColor2GrColor(paint.getColor()); |
1382 SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint)
; | 1384 SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint)
; |
1383 | 1385 |
1384 fContext->drawRectToRect(grPaint, viewMatrix, dstRect, paintRect); | 1386 fContext->drawNonAARectToRect(grPaint, viewMatrix, dstRect, paintRect); |
1385 } | 1387 } |
1386 | 1388 |
1387 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, | 1389 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, |
1388 const SkImageFilter* filter, | 1390 const SkImageFilter* filter, |
1389 const SkImageFilter::Context& ctx, | 1391 const SkImageFilter::Context& ctx, |
1390 SkBitmap* result, SkIPoint* offset) { | 1392 SkBitmap* result, SkIPoint* offset) { |
1391 SkASSERT(filter); | 1393 SkASSERT(filter); |
1392 | 1394 |
1393 // FIXME: plumb actual surface props such that we don't have to lie about th
e flags here | 1395 // FIXME: plumb actual surface props such that we don't have to lie about th
e flags here |
1394 // (https://code.google.com/p/skia/issues/detail?id=3148). | 1396 // (https://code.google.com/p/skia/issues/detail?id=3148). |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 return; | 1447 return; |
1446 } | 1448 } |
1447 } | 1449 } |
1448 | 1450 |
1449 GrPaint grPaint; | 1451 GrPaint grPaint; |
1450 grPaint.addColorTextureProcessor(texture, SkMatrix::I()); | 1452 grPaint.addColorTextureProcessor(texture, SkMatrix::I()); |
1451 | 1453 |
1452 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(pai
nt.getColor()), | 1454 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(pai
nt.getColor()), |
1453 false, &grPaint); | 1455 false, &grPaint); |
1454 | 1456 |
1455 fContext->drawRectToRect(grPaint, | 1457 fContext->drawNonAARectToRect(grPaint, |
1456 SkMatrix::I(), | 1458 SkMatrix::I(), |
1457 SkRect::MakeXYWH(SkIntToScalar(left), | 1459 SkRect::MakeXYWH(SkIntToScalar(left), |
1458 SkIntToScalar(top), | 1460 SkIntToScalar(top), |
1459 SkIntToScalar(w), | 1461 SkIntToScalar(w), |
1460 SkIntToScalar(h)), | 1462 SkIntToScalar(h)), |
1461 SkRect::MakeXYWH(0, | 1463 SkRect::MakeXYWH(0, |
1462 0, | 1464 0, |
1463 SK_Scalar1 * w / texture->width(), | 1465 SK_Scalar1 * w / texture->wid
th(), |
1464 SK_Scalar1 * h / texture->height()
)); | 1466 SK_Scalar1 * h / texture->hei
ght())); |
1465 } | 1467 } |
1466 | 1468 |
1467 void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap, | 1469 void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap, |
1468 const SkRect* src, const SkRect& dst, | 1470 const SkRect* src, const SkRect& dst, |
1469 const SkPaint& paint, | 1471 const SkPaint& paint, |
1470 SkCanvas::DrawBitmapRectFlags flags) { | 1472 SkCanvas::DrawBitmapRectFlags flags) { |
1471 SkMatrix matrix; | 1473 SkMatrix matrix; |
1472 SkRect bitmapBounds, tmpSrc; | 1474 SkRect bitmapBounds, tmpSrc; |
1473 | 1475 |
1474 bitmapBounds.set(0, 0, | 1476 bitmapBounds.set(0, 0, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), | 1569 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), |
1568 SkIntToScalar(y), | 1570 SkIntToScalar(y), |
1569 SkIntToScalar(w), | 1571 SkIntToScalar(w), |
1570 SkIntToScalar(h)); | 1572 SkIntToScalar(h)); |
1571 | 1573 |
1572 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate | 1574 // The device being drawn may not fill up its texture (e.g. saveLayer uses a
pproximate |
1573 // scratch texture). | 1575 // scratch texture). |
1574 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), | 1576 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), |
1575 SK_Scalar1 * h / devTex->height()); | 1577 SK_Scalar1 * h / devTex->height()); |
1576 | 1578 |
1577 fContext->drawRectToRect(grPaint, SkMatrix::I(), dstRect, srcRect); | 1579 fContext->drawNonAARectToRect(grPaint, SkMatrix::I(), dstRect, srcRect); |
1578 } | 1580 } |
1579 | 1581 |
1580 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { | 1582 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { |
1581 return filter->canFilterImageGPU(); | 1583 return filter->canFilterImageGPU(); |
1582 } | 1584 } |
1583 | 1585 |
1584 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, | 1586 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, |
1585 const SkImageFilter::Context& ctx, | 1587 const SkImageFilter::Context& ctx, |
1586 SkBitmap* result, SkIPoint* offset) { | 1588 SkBitmap* result, SkIPoint* offset) { |
1587 // want explicitly our impl, so guard against a subclass of us overriding it | 1589 // want explicitly our impl, so guard against a subclass of us overriding it |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 #endif | 1885 #endif |
1884 } | 1886 } |
1885 | 1887 |
1886 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1888 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1887 // We always return a transient cache, so it is freed after each | 1889 // We always return a transient cache, so it is freed after each |
1888 // filter traversal. | 1890 // filter traversal. |
1889 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1891 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1890 } | 1892 } |
1891 | 1893 |
1892 #endif | 1894 #endif |
OLD | NEW |