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 18 matching lines...) Expand all Loading... | |
29 #include "SkImageFilterCache.h" | 29 #include "SkImageFilterCache.h" |
30 #include "SkLayerInfo.h" | 30 #include "SkLayerInfo.h" |
31 #include "SkMaskFilter.h" | 31 #include "SkMaskFilter.h" |
32 #include "SkNinePatchIter.h" | 32 #include "SkNinePatchIter.h" |
33 #include "SkPathEffect.h" | 33 #include "SkPathEffect.h" |
34 #include "SkPicture.h" | 34 #include "SkPicture.h" |
35 #include "SkPictureData.h" | 35 #include "SkPictureData.h" |
36 #include "SkRasterClip.h" | 36 #include "SkRasterClip.h" |
37 #include "SkRRect.h" | 37 #include "SkRRect.h" |
38 #include "SkRecord.h" | 38 #include "SkRecord.h" |
39 #include "SkSpecialImage.h" | |
39 #include "SkStroke.h" | 40 #include "SkStroke.h" |
40 #include "SkSurface.h" | 41 #include "SkSurface.h" |
41 #include "SkSurface_Gpu.h" | 42 #include "SkSurface_Gpu.h" |
42 #include "SkTLazy.h" | 43 #include "SkTLazy.h" |
43 #include "SkUtils.h" | 44 #include "SkUtils.h" |
44 #include "SkVertState.h" | 45 #include "SkVertState.h" |
45 #include "SkXfermode.h" | 46 #include "SkXfermode.h" |
46 #include "batches/GrRectBatchFactory.h" | 47 #include "batches/GrRectBatchFactory.h" |
47 #include "effects/GrBicubicEffect.h" | 48 #include "effects/GrBicubicEffect.h" |
48 #include "effects/GrDashingEffect.h" | 49 #include "effects/GrDashingEffect.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 | 230 |
230 GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps( )); | 231 GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps( )); |
231 | 232 |
232 return context->newDrawContext(SkBackingFit::kExact, // Why ex act? | 233 return context->newDrawContext(SkBackingFit::kExact, // Why ex act? |
233 origInfo.width(), origInfo.height(), | 234 origInfo.width(), origInfo.height(), |
234 config, sampleCount, | 235 config, sampleCount, |
235 kDefault_GrSurfaceOrigin, surfaceProps, budge ted); | 236 kDefault_GrSurfaceOrigin, surfaceProps, budge ted); |
236 | 237 |
237 } | 238 } |
238 | 239 |
239 // This method ensures that we always have a texture-backed "bitmap" when we fin ally | 240 sk_sp<GrTexture> SkGpuDevice::filterTexture(const SkDraw& draw, |
240 // call through to the base impl so that the image filtering code will take the | 241 sk_sp<GrTexture> texture, |
241 // gpu-specific paths. This mirrors SkCanvas::internalDrawDevice (the other | 242 uint32_t generationID, |
242 // use of SkImageFilter::filterImage) in that the source and dest will have | 243 const SkIRect& srcSubset, |
243 // homogenous backing (e.g., raster or gpu). | 244 int left, int top, |
245 SkIRect* subset, SkIPoint* offset, | |
246 const SkImageFilter* filter) { | |
247 SkASSERT(filter); | |
248 | |
249 SkMatrix matrix = *draw.fMatrix; | |
250 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); | |
251 const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-left, -top); | |
252 SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache()); | |
253 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); | |
254 | |
255 sk_sp<SkSpecialImage> srcImg(SkSpecialImage::MakeFromGpu(srcSubset, | |
256 generationID, | |
257 std::move(texture), | |
258 &fDrawContext->surf aceProps())); | |
259 if (!srcImg) { | |
260 return nullptr; // something disastrous happened | |
261 } | |
262 | |
263 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, offse t)); | |
264 if (!resultImg) { | |
265 return nullptr; | |
266 } | |
267 | |
268 *subset = resultImg->subset(); | |
269 return srcImg->asTextureRef(fContext); | |
270 } | |
271 | |
272 | |
244 void SkGpuDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitma p, | 273 void SkGpuDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitma p, |
245 int x, int y, const SkPaint& paint) { | 274 int left, int top, const SkPaint& paint) { |
246 ASSERT_SINGLE_OWNER | 275 ASSERT_SINGLE_OWNER |
276 CHECK_SHOULD_DRAW(draw); | |
247 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSpriteWithFilter", fConte xt); | 277 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSpriteWithFilter", fConte xt); |
248 | 278 |
249 if (fContext->abandoned()) { | 279 SkASSERT(paint.getImageFilter()); |
250 return; | 280 this->drawSprite(draw, bitmap, left, top, paint); |
251 } | |
252 | |
253 if (bitmap.getTexture()) { | |
254 INHERITED::drawSpriteWithFilter(draw, bitmap, x, y, paint); | |
255 return; | |
256 } | |
257 | |
258 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); | |
259 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { | |
260 return; | |
261 } | |
262 | |
263 GrTexture* texture; | |
264 // draw sprite neither filters nor tiles. | |
265 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), | |
266 SkSourceGammaTreatment::kRespect, &texture); | |
267 if (!texture) { | |
268 return; | |
269 } | |
270 | |
271 SkBitmap newBitmap; | |
272 | |
273 GrWrapTextureInBitmap(texture, texture->width(), texture->height(), | |
274 bitmap.isOpaque(), &newBitmap); | |
275 | |
276 INHERITED::drawSpriteWithFilter(draw, newBitmap, x, y, paint); | |
277 } | 281 } |
278 | 282 |
279 /////////////////////////////////////////////////////////////////////////////// | 283 /////////////////////////////////////////////////////////////////////////////// |
280 | 284 |
281 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes, | 285 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes, |
282 int x, int y) { | 286 int x, int y) { |
283 ASSERT_SINGLE_OWNER | 287 ASSERT_SINGLE_OWNER |
284 | 288 |
285 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p ixels | 289 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p ixels |
286 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps()) ; | 290 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps()) ; |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 // matrices directly on the texture processor. | 1233 // matrices directly on the texture processor. |
1230 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); | 1234 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); |
1231 } else { | 1235 } else { |
1232 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintR ect); | 1236 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintR ect); |
1233 } | 1237 } |
1234 } | 1238 } |
1235 | 1239 |
1236 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, | 1240 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
1237 int left, int top, const SkPaint& paint) { | 1241 int left, int top, const SkPaint& paint) { |
1238 ASSERT_SINGLE_OWNER | 1242 ASSERT_SINGLE_OWNER |
1239 // drawSprite is defined to be in device coords. | |
1240 CHECK_SHOULD_DRAW(draw); | 1243 CHECK_SHOULD_DRAW(draw); |
1244 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawSprite", fContext); | |
1241 | 1245 |
1242 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); | 1246 if (fContext->abandoned()) { |
1243 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { | |
1244 return; | 1247 return; |
1245 } | 1248 } |
1246 | 1249 |
1247 int offX = bitmap.pixelRefOrigin().fX; | 1250 sk_sp<GrTexture> texture = sk_ref_sp(bitmap.getTexture()); |
bsalomon
2016/07/14 17:19:33
I think I'm missing something. Once there is no Sk
| |
1248 int offY = bitmap.pixelRefOrigin().fY; | 1251 if (!texture) { |
1249 int w = bitmap.width(); | 1252 SkAutoLockPixels alp(bitmap, true); |
1250 int h = bitmap.height(); | 1253 if (!bitmap.readyToDraw()) { |
1254 return; | |
1255 } | |
1251 | 1256 |
1252 GrTexture* texture; | 1257 // draw sprite neither filters nor tiles. |
1253 // draw sprite neither filters nor tiles. | 1258 texture.reset(GrRefCachedBitmapTexture(fContext, bitmap, |
1254 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), | 1259 GrTextureParams::ClampNoFilter(), |
1255 SkSourceGammaTreatment::kRespect, &texture); | 1260 SkSourceGammaTreatment::kRespect) ); |
1256 if (!texture) { | 1261 if (!texture) { |
1257 return; | 1262 return; |
1263 } | |
1258 } | 1264 } |
1259 | 1265 |
1260 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); | 1266 SkIRect srcRect = SkIRect::MakeXYWH(bitmap.pixelRefOrigin().fX, |
1267 bitmap.pixelRefOrigin().fY, | |
1268 bitmap.width(), | |
1269 bitmap.height()); | |
1261 | 1270 |
1262 SkASSERT(!paint.getImageFilter()); | 1271 this->internalDrawSprite(draw, std::move(texture), bitmap.getGenerationID(), |
1272 srcRect, left, top, paint); | |
1273 } | |
1274 | |
1275 | |
1276 void SkGpuDevice::internalDrawSprite(const SkDraw& draw, | |
1277 sk_sp<GrTexture> texture, | |
1278 uint32_t generationID, | |
1279 const SkIRect& srcRect, | |
1280 int left, int top, | |
1281 const SkPaint& paint) { | |
1282 | |
1283 SkIRect subset = srcRect; | |
1284 SkIPoint offset = { 0, 0 }; | |
1285 | |
1286 if (paint.getImageFilter()) { | |
1287 texture = this->filterTexture(draw, std::move(texture), generationID, sr cRect, left, top, | |
1288 &subset, &offset, | |
1289 paint.getImageFilter()); | |
1290 if (!texture) { | |
1291 return; | |
1292 } | |
1293 } | |
1294 | |
1295 SkPaint tmpUnfiltered(paint); | |
1296 tmpUnfiltered.setImageFilter(nullptr); | |
1297 | |
1298 bool alphaOnly = kAlpha_8_GrPixelConfig == texture->config(); | |
1263 | 1299 |
1264 GrPaint grPaint; | 1300 GrPaint grPaint; |
1265 sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture, SkMatrix: :I())); | 1301 sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), SkM atrix::I())); |
1266 if (alphaOnly) { | 1302 if (alphaOnly) { |
1267 fp = GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(fp)); | 1303 fp = GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(fp)); |
1268 } else { | 1304 } else { |
1269 fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); | 1305 fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); |
1270 } | 1306 } |
1271 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, std::move(fp), | 1307 if (!SkPaintToGrPaintReplaceShader(this->context(), tmpUnfiltered, std::move (fp), |
1272 this->surfaceProps().isGammaCorrect(), &g rPaint)) { | 1308 this->surfaceProps().isGammaCorrect(), &g rPaint)) { |
1273 return; | 1309 return; |
1274 } | 1310 } |
1275 | 1311 |
1276 fDrawContext->fillRectToRect(fClip, | 1312 fDrawContext->fillRectToRect(fClip, |
1277 grPaint, | 1313 grPaint, |
1278 SkMatrix::I(), | 1314 SkMatrix::I(), |
1279 SkRect::MakeXYWH(SkIntToScalar(left), | 1315 SkRect::Make(SkIRect::MakeXYWH(left + offset.fX , top + offset.fY, |
1280 SkIntToScalar(top), | 1316 subset.width(), subset.height())), |
1281 SkIntToScalar(w), | 1317 SkRect::MakeXYWH(SkIntToScalar(subset.fLeft) / texture->width(), |
1282 SkIntToScalar(h)), | 1318 SkIntToScalar(subset.fTop) / t exture->height(), |
1283 SkRect::MakeXYWH(SkIntToScalar(offX) / texture- >width(), | 1319 SkIntToScalar(subset.width()) / texture->width(), |
1284 SkIntToScalar(offY) / texture- >height(), | 1320 SkIntToScalar(subset.height()) / texture->height())); |
1285 SkIntToScalar(w) / texture->wi dth(), | |
1286 SkIntToScalar(h) / texture->he ight())); | |
1287 } | 1321 } |
1288 | 1322 |
1289 void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 1323 void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
1290 const SkRect* src, const SkRect& origDst, | 1324 const SkRect* src, const SkRect& origDst, |
1291 const SkPaint& paint, SkCanvas::SrcRectConstrai nt constraint) { | 1325 const SkPaint& paint, SkCanvas::SrcRectConstrai nt constraint) { |
1292 ASSERT_SINGLE_OWNER | 1326 ASSERT_SINGLE_OWNER |
1293 CHECK_SHOULD_DRAW(draw); | 1327 CHECK_SHOULD_DRAW(draw); |
1294 if (bitmap.getTexture()) { | 1328 if (bitmap.getTexture()) { |
1295 GrBitmapTextureAdjuster adjuster(&bitmap); | 1329 GrBitmapTextureAdjuster adjuster(&bitmap); |
1296 this->drawTextureProducer(&adjuster, src, &origDst, constraint, *draw.fM atrix, fClip, | 1330 this->drawTextureProducer(&adjuster, src, &origDst, constraint, *draw.fM atrix, fClip, |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1911 } | 1945 } |
1912 | 1946 |
1913 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1947 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1914 ASSERT_SINGLE_OWNER | 1948 ASSERT_SINGLE_OWNER |
1915 // We always return a transient cache, so it is freed after each | 1949 // We always return a transient cache, so it is freed after each |
1916 // filter traversal. | 1950 // filter traversal. |
1917 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1951 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1918 } | 1952 } |
1919 | 1953 |
1920 #endif | 1954 #endif |
OLD | NEW |