Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 1893993002: Revert of Remove deprecated paths from image filter infrastructure. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 1152
1153 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) { 1153 if (kAlpha_8_SkColorType == bitmap.colorType() && paint.getShader()) {
1154 // We don't have local coords in this case and have previously set the t ransform 1154 // We don't have local coords in this case and have previously set the t ransform
1155 // matrices directly on the texture processor. 1155 // matrices directly on the texture processor.
1156 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); 1156 fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect);
1157 } else { 1157 } else {
1158 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintR ect); 1158 fDrawContext->fillRectToRect(fClip, grPaint, viewMatrix, dstRect, paintR ect);
1159 } 1159 }
1160 } 1160 }
1161 1161
1162 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
1163 int width, int height,
1164 const SkImageFilter* filter,
1165 const SkImageFilter::Context& ctx,
1166 SkBitmap* result, SkIPoint* offset) {
1167 ASSERT_SINGLE_OWNER
1168 SkASSERT(filter);
1169
1170 SkImageFilter::DeviceProxy proxy(this);
1171
1172 if (filter->canFilterImageGPU()) {
1173 SkBitmap bm;
1174 GrWrapTextureInBitmap(texture, width, height, false, &bm);
1175 return filter->filterImageGPUDeprecated(&proxy, bm, ctx, result, offset) ;
1176 } else {
1177 return false;
1178 }
1179 }
1180
1162 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, 1181 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
1163 int left, int top, const SkPaint& paint) { 1182 int left, int top, const SkPaint& paint) {
1164 ASSERT_SINGLE_OWNER 1183 ASSERT_SINGLE_OWNER
1165 // drawSprite is defined to be in device coords. 1184 // drawSprite is defined to be in device coords.
1166 CHECK_SHOULD_DRAW(draw); 1185 CHECK_SHOULD_DRAW(draw);
1167 1186
1168 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); 1187 SkAutoLockPixels alp(bitmap, !bitmap.getTexture());
1169 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { 1188 if (!bitmap.getTexture() && !bitmap.readyToDraw()) {
1170 return; 1189 return;
1171 } 1190 }
1172 1191
1173 int offX = bitmap.pixelRefOrigin().fX; 1192 int offX = bitmap.pixelRefOrigin().fX;
1174 int offY = bitmap.pixelRefOrigin().fY; 1193 int offY = bitmap.pixelRefOrigin().fY;
1175 int w = bitmap.width(); 1194 int w = bitmap.width();
1176 int h = bitmap.height(); 1195 int h = bitmap.height();
1177 1196
1178 GrTexture* texture; 1197 GrTexture* texture;
1179 // draw sprite neither filters nor tiles. 1198 // draw sprite neither filters nor tiles.
1180 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &t exture); 1199 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &t exture);
1181 if (!texture) { 1200 if (!texture) {
1182 return; 1201 return;
1183 } 1202 }
1184 1203
1185 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); 1204 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType();
1186 1205
1187 SkASSERT(!paint.getImageFilter()); 1206 SkImageFilter* filter = paint.getImageFilter();
1207 // This bitmap will own the filtered result as a texture.
1208 SkBitmap filteredBitmap;
1209
1210 if (filter) {
1211 SkIPoint offset = SkIPoint::Make(0, 0);
1212 SkMatrix matrix(*draw.fMatrix);
1213 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
1214 SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-left, -top);
1215 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
1216 // This cache is transient, and is freed (along with all its contained
1217 // textures) when it goes out of scope.
1218 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1219 if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredB itmap,
1220 &offset)) {
1221 texture = (GrTexture*) filteredBitmap.getTexture();
1222 offX = filteredBitmap.pixelRefOrigin().fX;
1223 offY = filteredBitmap.pixelRefOrigin().fY;
1224 w = filteredBitmap.width();
1225 h = filteredBitmap.height();
1226 left += offset.x();
1227 top += offset.y();
1228 } else {
1229 return;
1230 }
1231 SkASSERT(!GrPixelConfigIsAlphaOnly(texture->config()));
1232 alphaOnly = false;
1233 }
1188 1234
1189 GrPaint grPaint; 1235 GrPaint grPaint;
1190 SkAutoTUnref<const GrFragmentProcessor> fp( 1236 SkAutoTUnref<const GrFragmentProcessor> fp(
1191 GrSimpleTextureEffect::Create(texture, SkMatrix::I())); 1237 GrSimpleTextureEffect::Create(texture, SkMatrix::I()));
1192 if (alphaOnly) { 1238 if (alphaOnly) {
1193 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); 1239 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
1194 } else { 1240 } else {
1195 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); 1241 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
1196 } 1242 }
1197 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, 1243 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 GrRenderTarget* devRT = dev->accessRenderTarget(); 1359 GrRenderTarget* devRT = dev->accessRenderTarget();
1314 GrTexture* devTex; 1360 GrTexture* devTex;
1315 if (nullptr == (devTex = devRT->asTexture())) { 1361 if (nullptr == (devTex = devRT->asTexture())) {
1316 return; 1362 return;
1317 } 1363 }
1318 1364
1319 const SkImageInfo ii = dev->imageInfo(); 1365 const SkImageInfo ii = dev->imageInfo();
1320 int w = ii.width(); 1366 int w = ii.width();
1321 int h = ii.height(); 1367 int h = ii.height();
1322 1368
1323 SkASSERT(!paint.getImageFilter()); 1369 SkImageFilter* filter = paint.getImageFilter();
1370 // This bitmap will own the filtered result as a texture.
1371 SkBitmap filteredBitmap;
1372
1373 if (filter) {
1374 SkIPoint offset = SkIPoint::Make(0, 0);
1375 SkMatrix matrix(*draw.fMatrix);
1376 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
1377 SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-x, -y);
1378 // This cache is transient, and is freed (along with all its contained
1379 // textures) when it goes out of scope.
1380 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
1381 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1382 if (this->filterTexture(fContext, devTex, device->width(), device->heigh t(),
1383 filter, ctx, &filteredBitmap, &offset)) {
1384 devTex = filteredBitmap.getTexture();
1385 w = filteredBitmap.width();
1386 h = filteredBitmap.height();
1387 x += offset.fX;
1388 y += offset.fY;
1389 } else {
1390 return;
1391 }
1392 }
1324 1393
1325 GrPaint grPaint; 1394 GrPaint grPaint;
1326 SkAutoTUnref<const GrFragmentProcessor> fp( 1395 SkAutoTUnref<const GrFragmentProcessor> fp(
1327 GrSimpleTextureEffect::Create(devTex, SkMatrix::I())); 1396 GrSimpleTextureEffect::Create(devTex, SkMatrix::I()));
1328 if (GrPixelConfigIsAlphaOnly(devTex->config())) { 1397 if (GrPixelConfigIsAlphaOnly(devTex->config())) {
1329 // Can this happen? 1398 // Can this happen?
1330 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); 1399 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
1331 } else { 1400 } else {
1332 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); 1401 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
1333 } 1402 }
1334 1403
1335 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, 1404 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp,
1336 this->surfaceProps().isGammaCorrect(), &g rPaint)) { 1405 this->surfaceProps().isGammaCorrect(), &g rPaint)) {
1337 return; 1406 return;
1338 } 1407 }
1339 1408
1340 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x), 1409 SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x),
1341 SkIntToScalar(y), 1410 SkIntToScalar(y),
1342 SkIntToScalar(w), 1411 SkIntToScalar(w),
1343 SkIntToScalar(h)); 1412 SkIntToScalar(h));
1344 1413
1345 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate 1414 // The device being drawn may not fill up its texture (e.g. saveLayer uses a pproximate
1346 // scratch texture). 1415 // scratch texture).
1347 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), 1416 SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(),
1348 SK_Scalar1 * h / devTex->height()); 1417 SK_Scalar1 * h / devTex->height());
1349 1418
1350 fDrawContext->fillRectToRect(fClip, grPaint, SkMatrix::I(), dstRect, srcRect ); 1419 fDrawContext->fillRectToRect(fClip, grPaint, SkMatrix::I(), dstRect, srcRect );
1351 } 1420 }
1352 1421
1422 bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) {
1423 ASSERT_SINGLE_OWNER
1424 return filter->canFilterImageGPU();
1425 }
1426
1427 bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src,
1428 const SkImageFilter::Context& ctx,
1429 SkBitmap* result, SkIPoint* offset) {
1430 ASSERT_SINGLE_OWNER
1431 // want explicitly our impl, so guard against a subclass of us overriding it
1432 if (!this->SkGpuDevice::canHandleImageFilter(filter)) {
1433 return false;
1434 }
1435
1436 SkAutoLockPixels alp(src, !src.getTexture());
1437 if (!src.getTexture() && !src.readyToDraw()) {
1438 return false;
1439 }
1440
1441 GrTexture* texture;
1442 // We assume here that the filter will not attempt to tile the src. Otherwis e, this cache lookup
1443 // must be pushed upstack.
1444 AutoBitmapTexture abt(fContext, src, GrTextureParams::ClampNoFilter(), &text ure);
1445 if (!texture) {
1446 return false;
1447 }
1448
1449 return this->filterTexture(fContext, texture, src.width(), src.height(),
1450 filter, ctx, result, offset);
1451 }
1452
1353 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, 1453 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y,
1354 const SkPaint& paint) { 1454 const SkPaint& paint) {
1355 ASSERT_SINGLE_OWNER 1455 ASSERT_SINGLE_OWNER
1356 SkMatrix viewMatrix = *draw.fMatrix; 1456 SkMatrix viewMatrix = *draw.fMatrix;
1357 viewMatrix.preTranslate(x, y); 1457 viewMatrix.preTranslate(x, y);
1358 if (as_IB(image)->peekTexture()) { 1458 if (as_IB(image)->peekTexture()) {
1359 CHECK_SHOULD_DRAW(draw); 1459 CHECK_SHOULD_DRAW(draw);
1360 GrImageTextureAdjuster adjuster(as_IB(image)); 1460 GrImageTextureAdjuster adjuster(as_IB(image));
1361 this->drawTextureProducer(&adjuster, nullptr, nullptr, SkCanvas::kFast_S rcRectConstraint, 1461 this->drawTextureProducer(&adjuster, nullptr, nullptr, SkCanvas::kFast_S rcRectConstraint,
1362 viewMatrix, fClip, paint); 1462 viewMatrix, fClip, paint);
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 GrLayerHoister::UnlockLayers(fContext, atlasedNeedRendering); 1929 GrLayerHoister::UnlockLayers(fContext, atlasedNeedRendering);
1830 GrLayerHoister::UnlockLayers(fContext, atlasedRecycled); 1930 GrLayerHoister::UnlockLayers(fContext, atlasedRecycled);
1831 GrLayerHoister::End(fContext); 1931 GrLayerHoister::End(fContext);
1832 1932
1833 return true; 1933 return true;
1834 #else 1934 #else
1835 return false; 1935 return false;
1836 #endif 1936 #endif
1837 } 1937 }
1838 1938
1939 SkImageFilter::Cache* SkGpuDevice::NewImageFilterCache() {
1940 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1941 }
1942
1839 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1943 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1840 ASSERT_SINGLE_OWNER 1944 ASSERT_SINGLE_OWNER
1841 // We always return a transient cache, so it is freed after each 1945 // We always return a transient cache, so it is freed after each
1842 // filter traversal. 1946 // filter traversal.
1843 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1947 return SkGpuDevice::NewImageFilterCache();
1844 } 1948 }
1845 1949
1846 #endif 1950 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698