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 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 SkRect::MakeIWH(producer->width(), pro
ducer->height()), | 1402 SkRect::MakeIWH(producer->width(), pro
ducer->height()), |
1403 GrTextureProducer::kNo_FilterConstrain
t, true, | 1403 GrTextureProducer::kNo_FilterConstrain
t, true, |
1404 &kMode, fDrawContext->getColorSpace(), | 1404 &kMode, fDrawContext->getColorSpace(), |
1405 fDrawContext->sourceGammaTreatment()))
; | 1405 fDrawContext->sourceGammaTreatment()))
; |
1406 GrPaint grPaint; | 1406 GrPaint grPaint; |
1407 if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint,
*draw.fMatrix, | 1407 if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint,
*draw.fMatrix, |
1408 std::move(fp), producer->isAlphaOnly(), &gr
Paint)) { | 1408 std::move(fp), producer->isAlphaOnly(), &gr
Paint)) { |
1409 return; | 1409 return; |
1410 } | 1410 } |
1411 | 1411 |
1412 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width()
, | 1412 std::unique_ptr<SkLatticeIter> iter( |
1413 producer->height(), center, dst); | 1413 new SkLatticeIter(producer->width(), producer->height(), center, dst
)); |
| 1414 fDrawContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->widt
h(), |
| 1415 producer->height(), std::move(iter), dst); |
1414 } | 1416 } |
1415 | 1417 |
1416 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, | 1418 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |
1417 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { | 1419 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { |
1418 ASSERT_SINGLE_OWNER | 1420 ASSERT_SINGLE_OWNER |
1419 uint32_t pinnedUniqueID; | 1421 uint32_t pinnedUniqueID; |
1420 if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID))
{ | 1422 if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID))
{ |
1421 CHECK_SHOULD_DRAW(draw); | 1423 CHECK_SHOULD_DRAW(draw); |
1422 GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(
), pinnedUniqueID, | 1424 GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(
), pinnedUniqueID, |
1423 as_IB(image)->onImageInfo().colorSpace()); | 1425 as_IB(image)->onImageInfo().colorSpace()); |
1424 this->drawProducerNine(draw, &adjuster, center, dst, paint); | 1426 this->drawProducerNine(draw, &adjuster, center, dst, paint); |
1425 } else { | 1427 } else { |
1426 SkBitmap bm; | 1428 SkBitmap bm; |
1427 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { | 1429 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
1428 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C
achingHint); | 1430 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C
achingHint); |
1429 this->drawProducerNine(draw, &maker, center, dst, paint); | 1431 this->drawProducerNine(draw, &maker, center, dst, paint); |
1430 } else if (as_IB(image)->getROPixels(&bm)) { | 1432 } else if (as_IB(image)->getROPixels(&bm)) { |
1431 this->drawBitmapNine(draw, bm, center, dst, paint); | 1433 this->drawBitmapNine(draw, bm, center, dst, paint); |
1432 } | 1434 } |
1433 } | 1435 } |
1434 } | 1436 } |
1435 | 1437 |
1436 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con
st SkIRect& center, | 1438 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con
st SkIRect& center, |
1437 const SkRect& dst, const SkPaint& paint) { | 1439 const SkRect& dst, const SkPaint& paint) { |
1438 ASSERT_SINGLE_OWNER | 1440 ASSERT_SINGLE_OWNER |
1439 GrBitmapTextureMaker maker(fContext, bitmap); | 1441 GrBitmapTextureMaker maker(fContext, bitmap); |
1440 this->drawProducerNine(draw, &maker, center, dst, paint); | 1442 this->drawProducerNine(draw, &maker, center, dst, paint); |
1441 } | 1443 } |
1442 | 1444 |
| 1445 void SkGpuDevice::drawProducerLattice(const SkDraw& draw, GrTextureProducer* pro
ducer, |
| 1446 const SkCanvas::Lattice& lattice, const Sk
Rect& dst, |
| 1447 const SkPaint& paint) { |
| 1448 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerLattice", fContex
t); |
| 1449 |
| 1450 CHECK_SHOULD_DRAW(draw); |
| 1451 |
| 1452 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; |
| 1453 sk_sp<GrFragmentProcessor> fp( |
| 1454 producer->createFragmentProcessor(SkMatrix::I(), |
| 1455 SkRect::MakeIWH(producer->width(), pro
ducer->height()), |
| 1456 GrTextureProducer::kNo_FilterConstrain
t, true, |
| 1457 &kMode, fDrawContext->getColorSpace(), |
| 1458 fDrawContext->sourceGammaTreatment()))
; |
| 1459 GrPaint grPaint; |
| 1460 if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint,
*draw.fMatrix, |
| 1461 std::move(fp), producer->isAlphaOnly(), &gr
Paint)) { |
| 1462 return; |
| 1463 } |
| 1464 |
| 1465 std::unique_ptr<SkLatticeIter> iter( |
| 1466 new SkLatticeIter(producer->width(), producer->height(), lattice, ds
t)); |
| 1467 fDrawContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->widt
h(), |
| 1468 producer->height(), std::move(iter), dst); |
| 1469 } |
| 1470 |
| 1471 void SkGpuDevice::drawImageLattice(const SkDraw& draw, const SkImage* image, |
| 1472 const SkCanvas::Lattice& lattice, const SkRec
t& dst, |
| 1473 const SkPaint& paint) { |
| 1474 ASSERT_SINGLE_OWNER |
| 1475 uint32_t pinnedUniqueID; |
| 1476 if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID))
{ |
| 1477 CHECK_SHOULD_DRAW(draw); |
| 1478 GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(
), pinnedUniqueID, |
| 1479 as_IB(image)->onImageInfo().colorSpace()); |
| 1480 this->drawProducerLattice(draw, &adjuster, lattice, dst, paint); |
| 1481 } else { |
| 1482 SkBitmap bm; |
| 1483 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
| 1484 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C
achingHint); |
| 1485 this->drawProducerLattice(draw, &maker, lattice, dst, paint); |
| 1486 } else if (as_IB(image)->getROPixels(&bm)) { |
| 1487 this->drawBitmapLattice(draw, bm, lattice, dst, paint); |
| 1488 } |
| 1489 } |
| 1490 } |
| 1491 |
| 1492 void SkGpuDevice::drawBitmapLattice(const SkDraw& draw, const SkBitmap& bitmap, |
| 1493 const SkCanvas::Lattice& lattice, const SkRe
ct& dst, |
| 1494 const SkPaint& paint) { |
| 1495 ASSERT_SINGLE_OWNER |
| 1496 GrBitmapTextureMaker maker(fContext, bitmap); |
| 1497 this->drawProducerLattice(draw, &maker, lattice, dst, paint); |
| 1498 } |
| 1499 |
1443 /////////////////////////////////////////////////////////////////////////////// | 1500 /////////////////////////////////////////////////////////////////////////////// |
1444 | 1501 |
1445 // must be in SkCanvas::VertexMode order | 1502 // must be in SkCanvas::VertexMode order |
1446 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1503 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
1447 kTriangles_GrPrimitiveType, | 1504 kTriangles_GrPrimitiveType, |
1448 kTriangleStrip_GrPrimitiveType, | 1505 kTriangleStrip_GrPrimitiveType, |
1449 kTriangleFan_GrPrimitiveType, | 1506 kTriangleFan_GrPrimitiveType, |
1450 }; | 1507 }; |
1451 | 1508 |
1452 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1509 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 } | 1776 } |
1720 | 1777 |
1721 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1778 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1722 ASSERT_SINGLE_OWNER | 1779 ASSERT_SINGLE_OWNER |
1723 // We always return a transient cache, so it is freed after each | 1780 // We always return a transient cache, so it is freed after each |
1724 // filter traversal. | 1781 // filter traversal. |
1725 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1782 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1726 } | 1783 } |
1727 | 1784 |
1728 #endif | 1785 #endif |
OLD | NEW |