| 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 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 CHECK_SHOULD_DRAW(draw); | 1457 CHECK_SHOULD_DRAW(draw); |
| 1458 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_Cachi
ngHint); | 1458 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_Cachi
ngHint); |
| 1459 bool alphaOnly = kAlpha_8_SkColorType == cacher->info().colorType(); | 1459 bool alphaOnly = kAlpha_8_SkColorType == cacher->info().colorType(); |
| 1460 this->drawTextureProducer(&maker, alphaOnly, src, &dst, constraint, *dra
w.fMatrix, | 1460 this->drawTextureProducer(&maker, alphaOnly, src, &dst, constraint, *dra
w.fMatrix, |
| 1461 fClip, paint); | 1461 fClip, paint); |
| 1462 } else if (as_IB(image)->getROPixels(&bm)) { | 1462 } else if (as_IB(image)->getROPixels(&bm)) { |
| 1463 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); | 1463 this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |
| 1464 } | 1464 } |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 static bool wrap_as_bm(GrContext* ctx, const SkImage* image, SkBitmap* bm) { | 1467 void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
er, bool alphaOnly, |
| 1468 // TODO: It is wrong to assume these texture params here. | 1468 const SkIRect& center, const SkRect& dst, con
st SkPaint& paint) { |
| 1469 SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, GrTextureParams:
:ClampNoFilter())); | 1469 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawProducerNine", fContext); |
| 1470 if (tex) { | |
| 1471 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa
que(), bm); | |
| 1472 return true; | |
| 1473 } else { | |
| 1474 return as_IB(image)->getROPixels(bm); | |
| 1475 } | |
| 1476 } | |
| 1477 | |
| 1478 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, | |
| 1479 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { | |
| 1480 // TODO write native implementation | |
| 1481 SkBitmap bitmap; | |
| 1482 if (!wrap_as_bm(this->context(), image, &bitmap)) { | |
| 1483 return; | |
| 1484 } | |
| 1485 return this->drawBitmapNine(draw, bitmap, center, dst, paint); | |
| 1486 } | |
| 1487 | |
| 1488 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con
st SkIRect& center, | |
| 1489 const SkRect& dst, const SkPaint& paint) { | |
| 1490 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawBitmapNine", fContext); | |
| 1491 | 1470 |
| 1492 CHECK_FOR_ANNOTATION(paint); | 1471 CHECK_FOR_ANNOTATION(paint); |
| 1493 CHECK_SHOULD_DRAW(draw); | 1472 CHECK_SHOULD_DRAW(draw); |
| 1494 | 1473 |
| 1495 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() || | 1474 bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() || |
| 1496 fRenderTarget->isUnifiedMultisampled(); | 1475 fRenderTarget->isUnifiedMultisampled(); |
| 1497 bool doBicubic; | 1476 bool doBicubic; |
| 1498 GrTextureParams::FilterMode textureFilterMode = | 1477 GrTextureParams::FilterMode textureFilterMode = |
| 1499 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMat
rix, SkMatrix::I(), | 1478 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), |
| 1500 &doBicubic); | 1479 &doBicubic); |
| 1501 | |
| 1502 // TODO handle bilerp(vie texture domains), MSAA(via snapping) | |
| 1503 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { | 1480 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { |
| 1504 SkNinePatchIter iter(bitmap.width(), bitmap.height(), center, dst); | 1481 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; |
| 1505 | 1482 |
| 1506 SkRect srcR, dstR; | 1483 SkRect srcR, dstR; |
| 1507 while (iter.next(&srcR, &dstR)) { | 1484 while (iter.next(&srcR, &dstR)) { |
| 1508 this->drawBitmapRect(draw, bitmap, &srcR, dstR, paint, | 1485 this->drawTextureProducer(producer, alphaOnly, &srcR, &dstR, |
| 1509 SkCanvas::kStrict_SrcRectConstraint); | 1486 SkCanvas::kStrict_SrcRectConstraint, *dra
w.fMatrix, fClip, |
| 1487 paint); |
| 1510 } | 1488 } |
| 1511 return; | 1489 return; |
| 1512 } | 1490 } |
| 1513 | 1491 |
| 1514 GrTextureParams params = GrTextureParams::ClampNoFilter(); | 1492 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; |
| 1515 | 1493 SkAutoTUnref<const GrFragmentProcessor> fp( |
| 1516 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(this->context(), bi
tmap, params)); | 1494 producer->createFragmentProcessor(SkMatrix::I(), |
| 1517 if (nullptr == texture) { | 1495 SkRect::MakeIWH(producer->width(), pro
ducer->height()), |
| 1496 GrTextureProducer::kNo_FilterConstrain
t, true, |
| 1497 &kMode)); |
| 1498 GrPaint grPaint; |
| 1499 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp, |
| 1500 alphaOnly, &grPaint)) { |
| 1518 return; | 1501 return; |
| 1519 } | 1502 } |
| 1520 | 1503 |
| 1521 SkMatrix texMatrix; | 1504 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, producer->width()
, |
| 1522 texMatrix.setIDiv(texture->width(), texture->height()); | 1505 producer->height(), center, dst); |
| 1506 } |
| 1523 | 1507 |
| 1524 SkAutoTUnref<const GrFragmentProcessor> fp(GrSimpleTextureEffect::Create(tex
ture, texMatrix, | 1508 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |
| 1525 par
ams)); | 1509 const SkIRect& center, const SkRect& dst, const
SkPaint& paint) { |
| 1510 if (GrTexture* tex = as_IB(image)->peekTexture()) { |
| 1511 bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config()); |
| 1512 GrImageTextureAdjuster adjuster(as_IB(image)); |
| 1513 this->drawProducerNine(draw, &adjuster, alphaOnly, center, dst, paint); |
| 1514 } else { |
| 1515 SkBitmap bm; |
| 1516 if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { |
| 1517 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C
achingHint); |
| 1518 bool alphaOnly = kAlpha_8_SkColorType == cacher->info().colorType(); |
| 1519 this->drawProducerNine(draw, &maker, alphaOnly, center, dst, paint); |
| 1520 } else if (as_IB(image)->getROPixels(&bm)) { |
| 1521 this->drawBitmapNine(draw, bm, center, dst, paint); |
| 1522 } |
| 1523 } |
| 1524 } |
| 1526 | 1525 |
| 1527 GrPaint grPaint; | 1526 void SkGpuDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, con
st SkIRect& center, |
| 1528 if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp, | 1527 const SkRect& dst, const SkPaint& paint) { |
| 1529 kAlpha_8_SkColorType == bitmap.colorType(),
&grPaint)) { | 1528 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); |
| 1530 return; | 1529 if (bitmap.getTexture()) { |
| 1530 GrBitmapTextureAdjuster adjuster(&bitmap); |
| 1531 this->drawProducerNine(draw, &adjuster, alphaOnly, center, dst, paint); |
| 1532 } else { |
| 1533 GrBitmapTextureMaker maker(fContext, bitmap); |
| 1534 this->drawProducerNine(draw, &maker, alphaOnly, center, dst, paint); |
| 1531 } | 1535 } |
| 1532 | |
| 1533 fDrawContext->drawImageNine(fClip, grPaint, *draw.fMatrix, bitmap.width(), b
itmap.height(), | |
| 1534 center, dst); | |
| 1535 } | 1536 } |
| 1536 | 1537 |
| 1537 /////////////////////////////////////////////////////////////////////////////// | 1538 /////////////////////////////////////////////////////////////////////////////// |
| 1538 | 1539 |
| 1539 // must be in SkCanvas::VertexMode order | 1540 // must be in SkCanvas::VertexMode order |
| 1540 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1541 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1541 kTriangles_GrPrimitiveType, | 1542 kTriangles_GrPrimitiveType, |
| 1542 kTriangleStrip_GrPrimitiveType, | 1543 kTriangleStrip_GrPrimitiveType, |
| 1543 kTriangleFan_GrPrimitiveType, | 1544 kTriangleFan_GrPrimitiveType, |
| 1544 }; | 1545 }; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1877 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1878 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1878 } | 1879 } |
| 1879 | 1880 |
| 1880 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1881 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1881 // We always return a transient cache, so it is freed after each | 1882 // We always return a transient cache, so it is freed after each |
| 1882 // filter traversal. | 1883 // filter traversal. |
| 1883 return SkGpuDevice::NewImageFilterCache(); | 1884 return SkGpuDevice::NewImageFilterCache(); |
| 1884 } | 1885 } |
| 1885 | 1886 |
| 1886 #endif | 1887 #endif |
| OLD | NEW |