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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | tests/DeviceTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/SkGpuDevice.cpp
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 3ceff366c40fa1aaf1fcf2b6c35fdf504a4d78be..f96b6553d5b54fb83a62de53f2381330ebdefa5b 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1399,7 +1399,47 @@ void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
this->drawTextureProducer(&maker, src, dst, constraint, *draw.fMatrix, fClip, paint);
}
-sk_sp<SkSpecialImage> SkGpuDevice::asSpecial() {
+sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
+ SkASSERT(!bitmap.getTexture());
+
+ SkAutoLockPixels alp(bitmap, true);
+ if (!bitmap.readyToDraw()) {
+ return nullptr;
+ }
+
+ GrTexture* texture;
+ AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(),
+ SkSourceGammaTreatment::kRespect, &texture);
+ if (!texture) {
+ return nullptr;
+ }
+
+ return SkSpecialImage::MakeFromGpu(bitmap.bounds(),
+ bitmap.getGenerationID(),
+ sk_ref_sp(texture),
+ &this->surfaceProps());
+}
+
+sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(SkImage* image) {
+ SkPixmap pm;
+ if (image->isTextureBacked()) {
+ GrTexture* texture = as_IB(image)->peekTexture();
+
+ return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(image->width(), image->height()),
+ image->uniqueID(),
+ sk_ref_sp(texture),
+ &this->surfaceProps());
+ } else if (image->peekPixels(&pm)) {
+ SkBitmap bm;
+
+ bm.installPixels(pm);
+ return this->makeSpecial(bm);
+ } else {
+ return nullptr;
+ }
+}
+
+sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() {
sk_sp<GrTexture> texture(this->accessDrawContext()->asTexture());
if (!texture) {
return nullptr;
@@ -1424,7 +1464,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
CHECK_SHOULD_DRAW(draw);
SkGpuDevice* dev = static_cast<SkGpuDevice*>(device);
- sk_sp<SkSpecialImage> srcImg(dev->asSpecial());
+ sk_sp<SkSpecialImage> srcImg(dev->snapSpecial());
if (!srcImg) {
return;
}
« 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