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 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1245 } | 1245 } |
1246 | 1246 |
1247 SkIRect srcRect = SkIRect::MakeXYWH(bitmap.pixelRefOrigin().fX, | 1247 SkIRect srcRect = SkIRect::MakeXYWH(bitmap.pixelRefOrigin().fX, |
1248 bitmap.pixelRefOrigin().fY, | 1248 bitmap.pixelRefOrigin().fY, |
1249 bitmap.width(), | 1249 bitmap.width(), |
1250 bitmap.height()); | 1250 bitmap.height()); |
1251 | 1251 |
1252 sk_sp<SkSpecialImage> srcImg(SkSpecialImage::MakeFromGpu(srcRect, | 1252 sk_sp<SkSpecialImage> srcImg(SkSpecialImage::MakeFromGpu(srcRect, |
1253 bitmap.getGeneratio nID(), | 1253 bitmap.getGeneratio nID(), |
1254 std::move(texture), | 1254 std::move(texture), |
1255 &fDrawContext->surf aceProps())); | 1255 &this->surfaceProps ())); |
1256 | 1256 |
1257 this->drawSpecial(draw, srcImg.get(), left, top, paint); | 1257 this->drawSpecial(draw, srcImg.get(), left, top, paint); |
1258 } | 1258 } |
1259 | 1259 |
1260 | 1260 |
1261 void SkGpuDevice::drawSpecial(const SkDraw& draw, | 1261 void SkGpuDevice::drawSpecial(const SkDraw& draw, |
1262 SkSpecialImage* special1, | 1262 SkSpecialImage* special1, |
1263 int left, int top, | 1263 int left, int top, |
1264 const SkPaint& paint) { | 1264 const SkPaint& paint) { |
1265 ASSERT_SINGLE_OWNER | |
1266 CHECK_SHOULD_DRAW(draw); | |
1267 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSpecial", fContext); | |
1265 | 1268 |
1266 SkIPoint offset = { 0, 0 }; | 1269 SkIPoint offset = { 0, 0 }; |
1267 | 1270 |
1268 sk_sp<SkSpecialImage> result; | 1271 sk_sp<SkSpecialImage> result; |
1269 if (paint.getImageFilter()) { | 1272 if (paint.getImageFilter()) { |
1270 result = this->filterTexture(draw, special1, left, top, | 1273 result = this->filterTexture(draw, special1, left, top, |
1271 &offset, | 1274 &offset, |
1272 paint.getImageFilter()); | 1275 paint.getImageFilter()); |
1273 if (!result) { | 1276 if (!result) { |
1274 return; | 1277 return; |
1275 } | 1278 } |
1276 } else { | 1279 } else { |
1277 result = sk_ref_sp(special1); | 1280 result = sk_ref_sp(special1); |
1278 } | 1281 } |
1279 | 1282 |
1280 SkASSERT(result->isTextureBacked()); | 1283 SkASSERT(result->isTextureBacked()); |
1281 sk_sp<GrTexture> texture = result->asTextureRef(fContext); | 1284 sk_sp<GrTexture> texture = result->asTextureRef(fContext); |
1282 | 1285 |
1283 SkPaint tmpUnfiltered(paint); | 1286 SkPaint tmpUnfiltered(paint); |
1284 tmpUnfiltered.setImageFilter(nullptr); | 1287 tmpUnfiltered.setImageFilter(nullptr); |
1285 | 1288 |
1286 bool alphaOnly = kAlpha_8_GrPixelConfig == texture->config(); | |
1287 | |
1288 GrPaint grPaint; | 1289 GrPaint grPaint; |
1289 sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), SkM atrix::I())); | 1290 sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), SkM atrix::I())); |
1290 if (alphaOnly) { | 1291 if (GrPixelConfigIsAlphaOnly(texture->config())) { |
1291 fp = GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(fp)); | 1292 fp = GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(fp)); |
1292 } else { | 1293 } else { |
1293 fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); | 1294 fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); |
1294 } | 1295 } |
1295 if (!SkPaintToGrPaintReplaceShader(this->context(), tmpUnfiltered, std::move (fp), | 1296 if (!SkPaintToGrPaintReplaceShader(this->context(), tmpUnfiltered, std::move (fp), |
1296 this->surfaceProps().isGammaCorrect(), &g rPaint)) { | 1297 this->surfaceProps().isGammaCorrect(), &g rPaint)) { |
1297 return; | 1298 return; |
1298 } | 1299 } |
1299 | 1300 |
1300 const SkIRect& subset = result->subset(); | 1301 const SkIRect& subset = result->subset(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1391 maxTileSizeForFilter, &tileSize, &clippedSrcR ect)) { | 1392 maxTileSizeForFilter, &tileSize, &clippedSrcR ect)) { |
1392 this->drawTiledBitmap(bitmap, viewMatrix, *src, clippedSrcRect, para ms, paint, | 1393 this->drawTiledBitmap(bitmap, viewMatrix, *src, clippedSrcRect, para ms, paint, |
1393 constraint, tileSize, doBicubic); | 1394 constraint, tileSize, doBicubic); |
1394 return; | 1395 return; |
1395 } | 1396 } |
1396 } | 1397 } |
1397 GrBitmapTextureMaker maker(fContext, bitmap); | 1398 GrBitmapTextureMaker maker(fContext, bitmap); |
1398 this->drawTextureProducer(&maker, src, dst, constraint, *draw.fMatrix, fClip , paint); | 1399 this->drawTextureProducer(&maker, src, dst, constraint, *draw.fMatrix, fClip , paint); |
1399 } | 1400 } |
1400 | 1401 |
1402 sk_sp<SkSpecialImage> SkGpuDevice::asSpecial() { | |
1403 sk_sp<GrTexture> texture(this->accessDrawContext()->asTexture()); | |
1404 if (!texture) { | |
1405 return nullptr; | |
bsalomon
2016/07/15 14:53:31
Should we attempt a copy surface in this case?
robertphillips
2016/07/15 14:59:40
Definitely, that is in the next CL.
| |
1406 } | |
1407 | |
1408 const SkImageInfo ii = this->imageInfo(); | |
1409 const SkIRect srcRect = SkIRect::MakeWH(ii.width(), ii.height()); | |
1410 | |
1411 return SkSpecialImage::MakeFromGpu(srcRect, | |
1412 kNeedNewImageUniqueID_SpecialImage, | |
1413 std::move(texture), | |
1414 &this->surfaceProps()); | |
1415 } | |
1416 | |
1401 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, | 1417 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
1402 int x, int y, const SkPaint& paint) { | 1418 int left, int top, const SkPaint& paint) { |
1403 ASSERT_SINGLE_OWNER | 1419 ASSERT_SINGLE_OWNER |
1404 // clear of the source device must occur before CHECK_SHOULD_DRAW | 1420 // clear of the source device must occur before CHECK_SHOULD_DRAW |
1405 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext); | 1421 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext); |
1406 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); | |
1407 | 1422 |
1408 // drawDevice is defined to be in device coords. | 1423 // drawDevice is defined to be in device coords. |
1409 CHECK_SHOULD_DRAW(draw); | 1424 CHECK_SHOULD_DRAW(draw); |
1410 | 1425 |
1411 sk_sp<GrTexture> devTex(dev->accessDrawContext()->asTexture()); | 1426 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
1412 if (!devTex) { | 1427 sk_sp<SkSpecialImage> srcImg(dev->asSpecial()); |
1428 if (!srcImg) { | |
1413 return; | 1429 return; |
1414 } | 1430 } |
1415 | 1431 |
1416 const SkImageInfo ii = dev->imageInfo(); | 1432 this->drawSpecial(draw, srcImg.get(), left, top, paint); |
1417 int w = ii.width(); | |
1418 int h = ii.height(); | |
1419 | |
1420 SkASSERT(!paint.getImageFilter()); | |
1421 | |
1422 GrPaint grPaint; | |
1423 sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(devTex.get(), SkMa trix::I())); | |
1424 if (GrPixelConfigIsAlphaOnly(devTex->config())) { | |
1425 // Can this happen? | |
1426 fp = GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(fp)); | |
1427 } else { | |
1428 fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); | |
1429 } | |
1430 | |
1431 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, std::move(fp), | |
1432 this->surfaceProps().isGammaCorrect(), &g rPaint)) { | |
1433 return; | |
1434 } | |
1435 | |
1436 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), | |
1437 SkIntToScalar(y), | |
1438 SkIntToScalar(w), | |
1439 SkIntToScalar(h)); | |
1440 | |
1441 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate | |
1442 // scratch texture). | |
1443 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), | |
1444 SK_Scalar1 * h / devTex->height()); | |
1445 | |
1446 fDrawContext->fillRectToRect(fClip, grPaint, SkMatrix::I(), dstRect, srcRect ); | |
1447 } | 1433 } |
1448 | 1434 |
1449 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, | 1435 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, |
1450 const SkPaint& paint) { | 1436 const SkPaint& paint) { |
1451 ASSERT_SINGLE_OWNER | 1437 ASSERT_SINGLE_OWNER |
1452 SkMatrix viewMatrix = *draw.fMatrix; | 1438 SkMatrix viewMatrix = *draw.fMatrix; |
1453 viewMatrix.preTranslate(x, y); | 1439 viewMatrix.preTranslate(x, y); |
1454 if (as_IB(image)->peekTexture()) { | 1440 if (as_IB(image)->peekTexture()) { |
1455 CHECK_SHOULD_DRAW(draw); | 1441 CHECK_SHOULD_DRAW(draw); |
1456 GrImageTextureAdjuster adjuster(as_IB(image)); | 1442 GrImageTextureAdjuster adjuster(as_IB(image)); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1862 } | 1848 } |
1863 | 1849 |
1864 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1850 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1865 ASSERT_SINGLE_OWNER | 1851 ASSERT_SINGLE_OWNER |
1866 // We always return a transient cache, so it is freed after each | 1852 // We always return a transient cache, so it is freed after each |
1867 // filter traversal. | 1853 // filter traversal. |
1868 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1854 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1869 } | 1855 } |
1870 | 1856 |
1871 #endif | 1857 #endif |
OLD | NEW |