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

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

Issue 2161533003: Add makeSpecial calls to SkGpuDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Nervous compilers Created 4 years, 5 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') | tests/DeviceTest.cpp » ('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"
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 maxTileSizeForFilter, &tileSize, &clippedSrcR ect)) { 1392 maxTileSizeForFilter, &tileSize, &clippedSrcR ect)) {
1393 this->drawTiledBitmap(bitmap, viewMatrix, *src, clippedSrcRect, para ms, paint, 1393 this->drawTiledBitmap(bitmap, viewMatrix, *src, clippedSrcRect, para ms, paint,
1394 constraint, tileSize, doBicubic); 1394 constraint, tileSize, doBicubic);
1395 return; 1395 return;
1396 } 1396 }
1397 } 1397 }
1398 GrBitmapTextureMaker maker(fContext, bitmap); 1398 GrBitmapTextureMaker maker(fContext, bitmap);
1399 this->drawTextureProducer(&maker, src, dst, constraint, *draw.fMatrix, fClip , paint); 1399 this->drawTextureProducer(&maker, src, dst, constraint, *draw.fMatrix, fClip , paint);
1400 } 1400 }
1401 1401
1402 sk_sp<SkSpecialImage> SkGpuDevice::asSpecial() { 1402 sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
1403 SkASSERT(!bitmap.getTexture());
1404
1405 SkAutoLockPixels alp(bitmap, true);
1406 if (!bitmap.readyToDraw()) {
1407 return nullptr;
1408 }
1409
1410 GrTexture* texture;
1411 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(),»
1412 SkSourceGammaTreatment::kRespect, &texture);
1413 if (!texture) {
1414 return nullptr;
1415 }
1416
1417 return SkSpecialImage::MakeFromGpu(bitmap.bounds(),
1418 bitmap.getGenerationID(),
1419 sk_ref_sp(texture),
1420 &this->surfaceProps());
1421 }
1422
1423 sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(SkImage* image) {
1424 SkPixmap pm;
1425 if (image->isTextureBacked()) {
1426 GrTexture* texture = as_IB(image)->peekTexture();
1427
1428 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(image->width(), image ->height()),
1429 image->uniqueID(),
1430 sk_ref_sp(texture),
1431 &this->surfaceProps());
1432 } else if (image->peekPixels(&pm)) {
1433 SkBitmap bm;
1434
1435 bm.installPixels(pm);
1436 return this->makeSpecial(bm);
1437 } else {
1438 return nullptr;
1439 }
1440 }
1441
1442 sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() {
1403 sk_sp<GrTexture> texture(this->accessDrawContext()->asTexture()); 1443 sk_sp<GrTexture> texture(this->accessDrawContext()->asTexture());
1404 if (!texture) { 1444 if (!texture) {
1405 return nullptr; 1445 return nullptr;
1406 } 1446 }
1407 1447
1408 const SkImageInfo ii = this->imageInfo(); 1448 const SkImageInfo ii = this->imageInfo();
1409 const SkIRect srcRect = SkIRect::MakeWH(ii.width(), ii.height()); 1449 const SkIRect srcRect = SkIRect::MakeWH(ii.width(), ii.height());
1410 1450
1411 return SkSpecialImage::MakeFromGpu(srcRect, 1451 return SkSpecialImage::MakeFromGpu(srcRect,
1412 kNeedNewImageUniqueID_SpecialImage, 1452 kNeedNewImageUniqueID_SpecialImage,
1413 std::move(texture), 1453 std::move(texture),
1414 &this->surfaceProps()); 1454 &this->surfaceProps());
1415 } 1455 }
1416 1456
1417 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, 1457 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
1418 int left, int top, const SkPaint& paint) { 1458 int left, int top, const SkPaint& paint) {
1419 ASSERT_SINGLE_OWNER 1459 ASSERT_SINGLE_OWNER
1420 // clear of the source device must occur before CHECK_SHOULD_DRAW 1460 // clear of the source device must occur before CHECK_SHOULD_DRAW
1421 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext); 1461 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext);
1422 1462
1423 // drawDevice is defined to be in device coords. 1463 // drawDevice is defined to be in device coords.
1424 CHECK_SHOULD_DRAW(draw); 1464 CHECK_SHOULD_DRAW(draw);
1425 1465
1426 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); 1466 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device);
1427 sk_sp<SkSpecialImage> srcImg(dev->asSpecial()); 1467 sk_sp<SkSpecialImage> srcImg(dev->snapSpecial());
1428 if (!srcImg) { 1468 if (!srcImg) {
1429 return; 1469 return;
1430 } 1470 }
1431 1471
1432 this->drawSpecial(draw, srcImg.get(), left, top, paint); 1472 this->drawSpecial(draw, srcImg.get(), left, top, paint);
1433 } 1473 }
1434 1474
1435 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y, 1475 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x , SkScalar y,
1436 const SkPaint& paint) { 1476 const SkPaint& paint) {
1437 ASSERT_SINGLE_OWNER 1477 ASSERT_SINGLE_OWNER
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 } 1888 }
1849 1889
1850 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { 1890 SkImageFilterCache* SkGpuDevice::getImageFilterCache() {
1851 ASSERT_SINGLE_OWNER 1891 ASSERT_SINGLE_OWNER
1852 // We always return a transient cache, so it is freed after each 1892 // We always return a transient cache, so it is freed after each
1853 // filter traversal. 1893 // filter traversal.
1854 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); 1894 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize);
1855 } 1895 }
1856 1896
1857 #endif 1897 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | tests/DeviceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698