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

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

Issue 1510903002: Stop wrapping images backed by generators as bitmaps in SkGpuDevice (except when tiling) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comment Created 5 years 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/GrImageIDTextureAdjuster.cpp ('k') | src/image/SkImage_Base.h » ('j') | 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"
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "SkDraw.h" 12 #include "SkDraw.h"
13 #include "GrDrawContext.h" 13 #include "GrDrawContext.h"
14 #include "GrFontScaler.h" 14 #include "GrFontScaler.h"
15 #include "GrGpu.h" 15 #include "GrGpu.h"
16 #include "GrGpuResourcePriv.h" 16 #include "GrGpuResourcePriv.h"
17 #include "GrImageIDTextureAdjuster.h" 17 #include "GrImageIDTextureAdjuster.h"
18 #include "GrLayerHoister.h" 18 #include "GrLayerHoister.h"
19 #include "GrRecordReplaceDraw.h" 19 #include "GrRecordReplaceDraw.h"
20 #include "GrStrokeInfo.h" 20 #include "GrStrokeInfo.h"
21 #include "GrTextContext.h" 21 #include "GrTextContext.h"
22 #include "GrTracing.h" 22 #include "GrTracing.h"
23 #include "SkCanvasPriv.h" 23 #include "SkCanvasPriv.h"
24 #include "SkErrorInternals.h" 24 #include "SkErrorInternals.h"
25 #include "SkGlyphCache.h" 25 #include "SkGlyphCache.h"
26 #include "SkGrTexturePixelRef.h" 26 #include "SkGrTexturePixelRef.h"
27 #include "SkGr.h" 27 #include "SkGr.h"
28 #include "SkGrPriv.h" 28 #include "SkGrPriv.h"
29 #include "SkImage_Base.h" 29 #include "SkImage_Base.h"
30 #include "SkImageCacherator.h"
30 #include "SkImageFilter.h" 31 #include "SkImageFilter.h"
31 #include "SkLayerInfo.h" 32 #include "SkLayerInfo.h"
32 #include "SkMaskFilter.h" 33 #include "SkMaskFilter.h"
33 #include "SkNinePatchIter.h" 34 #include "SkNinePatchIter.h"
34 #include "SkPathEffect.h" 35 #include "SkPathEffect.h"
35 #include "SkPicture.h" 36 #include "SkPicture.h"
36 #include "SkPictureData.h" 37 #include "SkPictureData.h"
37 #include "SkRRect.h" 38 #include "SkRRect.h"
38 #include "SkRecord.h" 39 #include "SkRecord.h"
39 #include "SkStroke.h" 40 #include "SkStroke.h"
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 // must be pushed upstack. 1393 // must be pushed upstack.
1393 AutoBitmapTexture abt(fContext, src, GrTextureParams::ClampNoFilter(), &text ure); 1394 AutoBitmapTexture abt(fContext, src, GrTextureParams::ClampNoFilter(), &text ure);
1394 if (!texture) { 1395 if (!texture) {
1395 return false; 1396 return false;
1396 } 1397 }
1397 1398
1398 return this->filterTexture(fContext, texture, src.width(), src.height(), 1399 return this->filterTexture(fContext, texture, src.width(), src.height(),
1399 filter, ctx, result, offset); 1400 filter, ctx, result, offset);
1400 } 1401 }
1401 1402
1402 static bool wrap_as_bm(GrContext* ctx, const SkImage* image, SkBitmap* bm) {
1403 // TODO: It is wrong to assume these texture params here.
1404 SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, GrTextureParams: :ClampNoFilter()));
1405 if (tex) {
1406 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa que(), bm);
1407 return true;
1408 } else {
1409 return as_IB(image)->getROPixels(bm);
1410 }
1411 }
1412
1413 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, 1403 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y,
1414 const SkPaint& paint) { 1404 const SkPaint& paint) {
1415 SkBitmap bm; 1405 SkMatrix viewMatrix = *draw.fMatrix;
1406 viewMatrix.preTranslate(x, y);
1416 if (GrTexture* tex = as_IB(image)->peekTexture()) { 1407 if (GrTexture* tex = as_IB(image)->peekTexture()) {
1417 CHECK_SHOULD_DRAW(draw); 1408 CHECK_SHOULD_DRAW(draw);
1418 SkMatrix viewMatrix = *draw.fMatrix;
1419 viewMatrix.preTranslate(x, y);
1420 bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config()); 1409 bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config());
1421 GrImageTextureAdjuster adjuster(as_IB(image)); 1410 GrImageTextureAdjuster adjuster(as_IB(image));
1422 this->drawTextureProducer(&adjuster, alphaOnly, nullptr, nullptr, 1411 this->drawTextureProducer(&adjuster, alphaOnly, nullptr, nullptr,
1423 SkCanvas::kFast_SrcRectConstraint, viewMatrix, fClip, paint); 1412 SkCanvas::kFast_SrcRectConstraint, viewMatrix, fClip, paint);
1424 return; 1413 return;
1425 } else { 1414 } else {
1415 SkBitmap bm;
1426 if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstra int, 1416 if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstra int,
1427 paint.getFilterQuality(), *draw.fMatrix)) { 1417 paint.getFilterQuality(), *draw.fMatrix)) {
1428 // only support tiling as bitmap at the moment, so force raster-vers ion 1418 // only support tiling as bitmap at the moment, so force raster-vers ion
1429 if (!as_IB(image)->getROPixels(&bm)) { 1419 if (!as_IB(image)->getROPixels(&bm)) {
1430 return; 1420 return;
1431 } 1421 }
1432 } else { 1422 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint);
1433 if (!wrap_as_bm(this->context(), image, &bm)) { 1423 } else if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) {
1434 return; 1424 CHECK_SHOULD_DRAW(draw);
1435 } 1425 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_C achingHint);
1426 bool alphaOnly = kAlpha_8_SkColorType == cacher->info().colorType();
1427 this->drawTextureProducer(&maker, alphaOnly, nullptr, nullptr,
1428 SkCanvas::kFast_SrcRectConstraint, viewMat rix, fClip, paint);
1429 } else if (as_IB(image)->getROPixels(&bm)) {
1430 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint);
1436 } 1431 }
1437 } 1432 }
1438 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint);
1439 } 1433 }
1440 1434
1441 void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src, 1435 void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src,
1442 const SkRect& dst, const SkPaint& paint, 1436 const SkRect& dst, const SkPaint& paint,
1443 SkCanvas::SrcRectConstraint constraint) { 1437 SkCanvas::SrcRectConstraint constraint) {
1444 if (GrTexture* tex = as_IB(image)->peekTexture()) { 1438 if (GrTexture* tex = as_IB(image)->peekTexture()) {
1445 CHECK_SHOULD_DRAW(draw); 1439 CHECK_SHOULD_DRAW(draw);
1446 GrImageTextureAdjuster adjuster(as_IB(image)); 1440 GrImageTextureAdjuster adjuster(as_IB(image));
1447 bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config()); 1441 bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config());
1448 this->drawTextureProducer(&adjuster, alphaOnly, src, &dst, constraint, * draw.fMatrix, 1442 this->drawTextureProducer(&adjuster, alphaOnly, src, &dst, constraint, * draw.fMatrix,
1449 fClip, paint); 1443 fClip, paint);
1450 return; 1444 return;
1451 } 1445 }
1452 SkBitmap bm; 1446 SkBitmap bm;
1453 SkMatrix viewMatrix = *draw.fMatrix; 1447 SkMatrix totalMatrix = *draw.fMatrix;
1454 viewMatrix.preScale(dst.width() / (src ? src->width() : image->width()), 1448 totalMatrix.preScale(dst.width() / (src ? src->width() : image->width()),
1455 dst.height() / (src ? src->height() : image->height())); 1449 dst.height() / (src ? src->height() : image->height())) ;
1456 if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), viewMatrix)) { 1450 if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), totalMatrix)) {
1457 // only support tiling as bitmap at the moment, so force raster-version 1451 // only support tiling as bitmap at the moment, so force raster-version
1458 if (!as_IB(image)->getROPixels(&bm)) { 1452 if (!as_IB(image)->getROPixels(&bm)) {
1459 return; 1453 return;
1460 } 1454 }
1455 this->drawBitmapRect(draw, bm, src, dst, paint, constraint);
1456 } else if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) {
1457 CHECK_SHOULD_DRAW(draw);
1458 GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_Cachi ngHint);
1459 bool alphaOnly = kAlpha_8_SkColorType == cacher->info().colorType();
1460 this->drawTextureProducer(&maker, alphaOnly, src, &dst, constraint, *dra w.fMatrix,
1461 fClip, paint);
1462 } else if (as_IB(image)->getROPixels(&bm)) {
1463 this->drawBitmapRect(draw, bm, src, dst, paint, constraint);
1464 }
1465 }
1466
1467 static bool wrap_as_bm(GrContext* ctx, const SkImage* image, SkBitmap* bm) {
1468 // TODO: It is wrong to assume these texture params here.
1469 SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, GrTextureParams: :ClampNoFilter()));
1470 if (tex) {
1471 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa que(), bm);
1472 return true;
1461 } else { 1473 } else {
1462 if (!wrap_as_bm(this->context(), image, &bm)) { 1474 return as_IB(image)->getROPixels(bm);
1463 return;
1464 }
1465 } 1475 }
1466 this->drawBitmapRect(draw, bm, src, dst, paint, constraint);
1467 } 1476 }
1468 1477
1469 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, 1478 void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image,
1470 const SkIRect& center, const SkRect& dst, const SkPaint& paint) { 1479 const SkIRect& center, const SkRect& dst, const SkPaint& paint) {
1471 // TODO write native implementation 1480 // TODO write native implementation
1472 SkBitmap bitmap; 1481 SkBitmap bitmap;
1473 if (!wrap_as_bm(this->context(), image, &bitmap)) { 1482 if (!wrap_as_bm(this->context(), image, &bitmap)) {
1474 return; 1483 return;
1475 } 1484 }
1476 return this->drawBitmapNine(draw, bitmap, center, dst, paint); 1485 return this->drawBitmapNine(draw, bitmap, center, dst, paint);
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1877 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1869 } 1878 }
1870 1879
1871 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1880 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1872 // We always return a transient cache, so it is freed after each 1881 // We always return a transient cache, so it is freed after each
1873 // filter traversal. 1882 // filter traversal.
1874 return SkGpuDevice::NewImageFilterCache(); 1883 return SkGpuDevice::NewImageFilterCache();
1875 } 1884 }
1876 1885
1877 #endif 1886 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrImageIDTextureAdjuster.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698