Chromium Code Reviews| 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 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1440 SkRect::MakeIWH(producer->width(), pro ducer->height()), | 1440 SkRect::MakeIWH(producer->width(), pro ducer->height()), |
| 1441 GrTextureProducer::kNo_FilterConstrain t, true, | 1441 GrTextureProducer::kNo_FilterConstrain t, true, |
| 1442 &kMode, fDrawContext->getColorSpace(), | 1442 &kMode, fDrawContext->getColorSpace(), |
| 1443 fDrawContext->sourceGammaTreatment())) ; | 1443 fDrawContext->sourceGammaTreatment())) ; |
| 1444 GrPaint grPaint; | 1444 GrPaint grPaint; |
| 1445 if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, *draw.fMatrix, | 1445 if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, *draw.fMatrix, |
| 1446 std::move(fp), producer->isAlphaOnly(), &gr Paint)) { | 1446 std::move(fp), producer->isAlphaOnly(), &gr Paint)) { |
| 1447 return; | 1447 return; |
| 1448 } | 1448 } |
| 1449 | 1449 |
| 1450 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width() , | 1450 std::unique_ptr<SkLatticeIter> iter( |
|
msarett
2016/08/18 15:16:08
Another option is to convert the |center| rect to
| |
| 1451 producer->height(), center, dst); | 1451 new SkLatticeIter(producer->width(), producer->height(), center, dst )); |
| 1452 fDrawContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->widt h(), | |
| 1453 producer->height(), std::move(iter), dst); | |
| 1452 } | 1454 } |
| 1453 | 1455 |
| 1454 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, | 1456 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |
| 1455 const SkIRect& center, const SkRect& dst, const SkPaint& paint) { | 1457 const SkIRect& center, const SkRect& dst, const SkPaint& paint) { |
| 1456 ASSERT_SINGLE_OWNER | 1458 ASSERT_SINGLE_OWNER |
| 1457 if (as_IB(image)->peekTexture()) { | 1459 if (as_IB(image)->peekTexture()) { |
| 1458 GrImageTextureAdjuster adjuster(as_IB(image)); | 1460 GrImageTextureAdjuster adjuster(as_IB(image)); |
| 1459 this->drawProducerNine(draw, &adjuster, center, dst, paint); | 1461 this->drawProducerNine(draw, &adjuster, center, dst, paint); |
| 1460 } else { | 1462 } else { |
| 1461 SkBitmap bm; | 1463 SkBitmap bm; |
| 1462 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { | 1464 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
| 1463 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C achingHint); | 1465 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C achingHint); |
| 1464 this->drawProducerNine(draw, &maker, center, dst, paint); | 1466 this->drawProducerNine(draw, &maker, center, dst, paint); |
| 1465 } else if (as_IB(image)->getROPixels(&bm)) { | 1467 } else if (as_IB(image)->getROPixels(&bm)) { |
| 1466 this->drawBitmapNine(draw, bm, center, dst, paint); | 1468 this->drawBitmapNine(draw, bm, center, dst, paint); |
| 1467 } | 1469 } |
| 1468 } | 1470 } |
| 1469 } | 1471 } |
| 1470 | 1472 |
| 1471 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con st SkIRect& center, | 1473 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con st SkIRect& center, |
| 1472 const SkRect& dst, const SkPaint& paint) { | 1474 const SkRect& dst, const SkPaint& paint) { |
| 1473 ASSERT_SINGLE_OWNER | 1475 ASSERT_SINGLE_OWNER |
| 1474 GrBitmapTextureMaker maker(fContext, bitmap); | 1476 GrBitmapTextureMaker maker(fContext, bitmap); |
| 1475 this->drawProducerNine(draw, &maker, center, dst, paint); | 1477 this->drawProducerNine(draw, &maker, center, dst, paint); |
| 1476 } | 1478 } |
| 1477 | 1479 |
| 1480 void SkGpuDevice::drawProducerLattice(const SkDraw& draw, GrTextureProducer* pro ducer, | |
| 1481 const SkCanvas::Lattice& lattice, const Sk Rect& dst, | |
| 1482 const SkPaint& paint) { | |
| 1483 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerLattice", fContex t); | |
| 1484 | |
| 1485 CHECK_SHOULD_DRAW(draw); | |
| 1486 | |
| 1487 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt erMode; | |
| 1488 sk_sp<GrFragmentProcessor> fp( | |
| 1489 producer->createFragmentProcessor(SkMatrix::I(), | |
| 1490 SkRect::MakeIWH(producer->width(), pro ducer->height()), | |
| 1491 GrTextureProducer::kNo_FilterConstrain t, true, | |
| 1492 &kMode, fDrawContext->getColorSpace(), | |
| 1493 fDrawContext->sourceGammaTreatment())) ; | |
| 1494 GrPaint grPaint; | |
| 1495 if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, *draw.fMatrix, | |
| 1496 std::move(fp), producer->isAlphaOnly(), &gr Paint)) { | |
| 1497 return; | |
| 1498 } | |
| 1499 | |
| 1500 std::unique_ptr<SkLatticeIter> iter( | |
| 1501 new SkLatticeIter(producer->width(), producer->height(), lattice, ds t)); | |
| 1502 fDrawContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->widt h(), | |
| 1503 producer->height(), std::move(iter), dst); | |
| 1504 } | |
| 1505 | |
| 1506 void SkGpuDevice::drawImageLattice(const SkDraw& draw, const SkImage* image, | |
| 1507 const SkCanvas::Lattice& lattice, const SkRec t& dst, | |
| 1508 const SkPaint& paint) { | |
| 1509 ASSERT_SINGLE_OWNER | |
| 1510 if (as_IB(image)->peekTexture()) { | |
| 1511 GrImageTextureAdjuster adjuster(as_IB(image)); | |
| 1512 this->drawProducerLattice(draw, &adjuster, lattice, dst, paint); | |
| 1513 } else { | |
| 1514 SkBitmap bm; | |
| 1515 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { | |
| 1516 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C achingHint); | |
| 1517 this->drawProducerLattice(draw, &maker, lattice, dst, paint); | |
| 1518 } else if (as_IB(image)->getROPixels(&bm)) { | |
| 1519 this->drawBitmapLattice(draw, bm, lattice, dst, paint); | |
| 1520 } | |
| 1521 } | |
| 1522 } | |
| 1523 | |
| 1524 void SkGpuDevice::drawBitmapLattice(const SkDraw& draw, const SkBitmap& bitmap, | |
| 1525 const SkCanvas::Lattice& lattice, const SkRe ct& dst, | |
| 1526 const SkPaint& paint) { | |
| 1527 ASSERT_SINGLE_OWNER | |
| 1528 GrBitmapTextureMaker maker(fContext, bitmap); | |
| 1529 this->drawProducerLattice(draw, &maker, lattice, dst, paint); | |
| 1530 } | |
| 1531 | |
| 1478 /////////////////////////////////////////////////////////////////////////////// | 1532 /////////////////////////////////////////////////////////////////////////////// |
| 1479 | 1533 |
| 1480 // must be in SkCanvas::VertexMode order | 1534 // must be in SkCanvas::VertexMode order |
| 1481 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1535 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1482 kTriangles_GrPrimitiveType, | 1536 kTriangles_GrPrimitiveType, |
| 1483 kTriangleStrip_GrPrimitiveType, | 1537 kTriangleStrip_GrPrimitiveType, |
| 1484 kTriangleFan_GrPrimitiveType, | 1538 kTriangleFan_GrPrimitiveType, |
| 1485 }; | 1539 }; |
| 1486 | 1540 |
| 1487 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1541 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1754 } | 1808 } |
| 1755 | 1809 |
| 1756 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1810 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
| 1757 ASSERT_SINGLE_OWNER | 1811 ASSERT_SINGLE_OWNER |
| 1758 // We always return a transient cache, so it is freed after each | 1812 // We always return a transient cache, so it is freed after each |
| 1759 // filter traversal. | 1813 // filter traversal. |
| 1760 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1814 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
| 1761 } | 1815 } |
| 1762 | 1816 |
| 1763 #endif | 1817 #endif |
| OLD | NEW |