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 std::unique_ptr<SkLatticeIter> iter( | 1412 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width()
, |
1413 new SkLatticeIter(producer->width(), producer->height(), center, dst
)); | 1413 producer->height(), center, dst); |
1414 fDrawContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->widt
h(), | |
1415 producer->height(), std::move(iter), dst); | |
1416 } | 1414 } |
1417 | 1415 |
1418 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, | 1416 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |
1419 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { | 1417 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { |
1420 ASSERT_SINGLE_OWNER | 1418 ASSERT_SINGLE_OWNER |
1421 uint32_t pinnedUniqueID; | 1419 uint32_t pinnedUniqueID; |
1422 if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID))
{ | 1420 if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID))
{ |
1423 CHECK_SHOULD_DRAW(draw); | 1421 CHECK_SHOULD_DRAW(draw); |
1424 GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(
), pinnedUniqueID, | 1422 GrTextureAdjuster adjuster(tex.get(), image->alphaType(), image->bounds(
), pinnedUniqueID, |
1425 as_IB(image)->onImageInfo().colorSpace()); | 1423 as_IB(image)->onImageInfo().colorSpace()); |
1426 this->drawProducerNine(draw, &adjuster, center, dst, paint); | 1424 this->drawProducerNine(draw, &adjuster, center, dst, paint); |
1427 } else { | 1425 } else { |
1428 SkBitmap bm; | 1426 SkBitmap bm; |
1429 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { | 1427 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
1430 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C
achingHint); | 1428 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C
achingHint); |
1431 this->drawProducerNine(draw, &maker, center, dst, paint); | 1429 this->drawProducerNine(draw, &maker, center, dst, paint); |
1432 } else if (as_IB(image)->getROPixels(&bm)) { | 1430 } else if (as_IB(image)->getROPixels(&bm)) { |
1433 this->drawBitmapNine(draw, bm, center, dst, paint); | 1431 this->drawBitmapNine(draw, bm, center, dst, paint); |
1434 } | 1432 } |
1435 } | 1433 } |
1436 } | 1434 } |
1437 | 1435 |
1438 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con
st SkIRect& center, | 1436 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con
st SkIRect& center, |
1439 const SkRect& dst, const SkPaint& paint) { | 1437 const SkRect& dst, const SkPaint& paint) { |
1440 ASSERT_SINGLE_OWNER | 1438 ASSERT_SINGLE_OWNER |
1441 GrBitmapTextureMaker maker(fContext, bitmap); | 1439 GrBitmapTextureMaker maker(fContext, bitmap); |
1442 this->drawProducerNine(draw, &maker, center, dst, paint); | 1440 this->drawProducerNine(draw, &maker, center, dst, paint); |
1443 } | 1441 } |
1444 | 1442 |
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 | |
1500 /////////////////////////////////////////////////////////////////////////////// | 1443 /////////////////////////////////////////////////////////////////////////////// |
1501 | 1444 |
1502 // must be in SkCanvas::VertexMode order | 1445 // must be in SkCanvas::VertexMode order |
1503 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1446 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
1504 kTriangles_GrPrimitiveType, | 1447 kTriangles_GrPrimitiveType, |
1505 kTriangleStrip_GrPrimitiveType, | 1448 kTriangleStrip_GrPrimitiveType, |
1506 kTriangleFan_GrPrimitiveType, | 1449 kTriangleFan_GrPrimitiveType, |
1507 }; | 1450 }; |
1508 | 1451 |
1509 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1452 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 } | 1719 } |
1777 | 1720 |
1778 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1721 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1779 ASSERT_SINGLE_OWNER | 1722 ASSERT_SINGLE_OWNER |
1780 // We always return a transient cache, so it is freed after each | 1723 // We always return a transient cache, so it is freed after each |
1781 // filter traversal. | 1724 // filter traversal. |
1782 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1725 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1783 } | 1726 } |
1784 | 1727 |
1785 #endif | 1728 #endif |
OLD | NEW |