Remove SkImage::makeTextureImage
No one (other than test code) was using this API, and it lacks the context
to do the right thing. Specifically, if this forces a decode of an encoded
image, we don't know the intended use (re: color spaces) to determine how
we should decode.
BUG=skia:
Change-Id: I6ff700b3a5adce8257f35c5e3dd5ba557b2a3219
Reviewed-on: https://skia-review.googlesource.com/5614
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/gm/image.cpp b/gm/image.cpp
index 6545c0a..c1d3372 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -424,86 +424,3 @@
typedef skiagm::GM INHERITED;
};
DEF_GM( return new ScaleGeneratorGM; )
-
-#if SK_SUPPORT_GPU
-#include "GrContextFactory.h"
-#endif
-
-DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) {
- GrContext* context = nullptr;
-#if SK_SUPPORT_GPU
- context = canvas->getGrContext();
- sk_gpu_test::GrContextFactory factory;
-#endif
- if (!context) {
- skiagm::GM::DrawGpuOnlyMessage(canvas);
- return;
- }
-
- auto render_image = [](SkCanvas* canvas) {
- canvas->clear(SK_ColorBLUE);
- SkPaint paint;
- paint.setColor(SK_ColorRED);
- canvas->drawRect(SkRect::MakeXYWH(10.f,10.f,10.f,10.f), paint);
- paint.setColor(SK_ColorGREEN);
- canvas->drawRect(SkRect::MakeXYWH(30.f,10.f,10.f,10.f), paint);
- paint.setColor(SK_ColorYELLOW);
- canvas->drawRect(SkRect::MakeXYWH(10.f,30.f,10.f,10.f), paint);
- paint.setColor(SK_ColorCYAN);
- canvas->drawRect(SkRect::MakeXYWH(30.f,30.f,10.f,10.f), paint);
- };
-
- static constexpr int kSize = 50;
- SkBitmap bmp;
- bmp.allocN32Pixels(kSize, kSize);
- SkCanvas bmpCanvas(bmp);
- render_image(&bmpCanvas);
-
- std::function<sk_sp<SkImage>()> imageFactories[] = {
- // Create sw raster image.
- [bmp] {
- return SkImage::MakeFromBitmap(bmp);
- },
- // Create encoded image.
- [bmp] {
- sk_sp<SkData> src(
- sk_tool_utils::EncodeImageToData(bmp, SkEncodedImageFormat::kPNG, 100));
- return SkImage::MakeFromEncoded(std::move(src));
- },
- // Create a picture image.
- [render_image] {
- SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkIntToScalar(kSize));
- render_image(canvas);
- return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
- SkISize::Make(kSize, kSize), nullptr, nullptr);
- },
- // Create a texture image
- [context, render_image]() -> sk_sp<SkImage> {
- auto surface(
- SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
- SkImageInfo::MakeN32Premul(kSize, kSize)));
- if (!surface) {
- return nullptr;
- }
- render_image(surface->getCanvas());
- return surface->makeImageSnapshot();
- }
- };
-
- constexpr SkScalar kPad = 5.f;
- canvas->translate(kPad, kPad);
- for (auto factory : imageFactories) {
- auto image(factory());
- if (!image) {
- continue;
- }
- if (context) {
- sk_sp<SkImage> texImage(image->makeTextureImage(context));
- if (texImage) {
- canvas->drawImage(texImage, 0, 0);
- }
- }
- canvas->translate(image->width() + kPad, 0);
- }
-}
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 625d0a0..8c4ed5e 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -321,13 +321,6 @@
sk_sp<SkImage> makeSubset(const SkIRect& subset) const;
/**
- * Ensures that an image is backed by a texture (when GrContext is non-null). If no
- * transformation is required, the returned image may be the same as this image. If the this
- * image is from a different GrContext, this will fail.
- */
- sk_sp<SkImage> makeTextureImage(GrContext*) const;
-
- /**
* If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
* the pixels fails). Otherwise, it returns the original image.
*/
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index d8c3b32..baabd56 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -420,10 +420,6 @@
return nullptr;
}
-sk_sp<SkImage> SkImage::makeTextureImage(GrContext*) const {
- return nullptr;
-}
-
sk_sp<SkImage> SkImage::makeNonTextureImage() const {
return sk_ref_sp(const_cast<SkImage*>(this));
}
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 07d352a..24e5c1d 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -305,39 +305,6 @@
std::move(imageColorSpace));
}
-static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
- sk_sp<SkColorSpace> texColorSpace;
- sk_sp<GrTexture> texture(
- maker->refTextureForParams(GrSamplerParams::ClampNoFilter(),
- SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware,
- &texColorSpace));
- if (!texture) {
- return nullptr;
- }
- return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, std::move(texture),
- std::move(texColorSpace), SkBudgeted::kNo);
-}
-
-sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
- if (!context) {
- return nullptr;
- }
- if (GrTexture* peek = as_IB(this)->peekTexture()) {
- return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(this)) : nullptr;
- }
-
- if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) {
- GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint);
- return create_image_from_maker(&maker, this->alphaType(), this->uniqueID());
- }
-
- if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) {
- GrBitmapTextureMaker maker(context, *bmp);
- return create_image_from_maker(&maker, this->alphaType(), this->uniqueID());
- }
- return nullptr;
-}
-
sk_sp<SkImage> SkImage::makeNonTextureImage() const {
if (!this->isTextureBacked()) {
return sk_ref_sp(const_cast<SkImage*>(this));
diff --git a/tests/DeviceTest.cpp b/tests/DeviceTest.cpp
index 34140a7..9fb4fa2 100644
--- a/tests/DeviceTest.cpp
+++ b/tests/DeviceTest.cpp
@@ -106,7 +106,9 @@
SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset());
// Create a gpu-backed special image from a gpu-backed SkImage
- image = image->makeTextureImage(context);
+ SkPixmap pixmap;
+ bm.peekPixels(&pixmap);
+ image = SkImage::MakeTextureFromPixmap(context, pixmap, SkBudgeted::kNo);
special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), image.get());
SkASSERT(special->isTextureBacked());
SkASSERT(kWidth == special->width());
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 45681be..3b99394 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -455,68 +455,6 @@
}
}
-DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_newTextureImage, reporter, contextInfo) {
- GrContext* context = contextInfo.grContext();
- sk_gpu_test::TestContext* testContext = contextInfo.testContext();
-
- GrContextFactory otherFactory;
- GrContextFactory::ContextType otherContextType =
- GrContextFactory::NativeContextTypeForBackend(testContext->backend());
- ContextInfo otherContextInfo = otherFactory.getContextInfo(otherContextType);
- testContext->makeCurrent();
-
- std::function<sk_sp<SkImage>()> imageFactories[] = {
- create_image,
- create_codec_image,
- create_data_image,
- // Create an image from a picture.
- create_picture_image,
- // Create a texture image.
- [context] { return create_gpu_image(context); },
- // Create a texture image in a another GrContext.
- [testContext, otherContextInfo] {
- otherContextInfo.testContext()->makeCurrent();
- sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.grContext());
- testContext->makeCurrent();
- return otherContextImage;
- }
- };
-
- for (auto factory : imageFactories) {
- sk_sp<SkImage> image(factory());
- if (!image) {
- ERRORF(reporter, "Error creating image.");
- continue;
- }
- GrTexture* origTexture = as_IB(image)->peekTexture();
-
- sk_sp<SkImage> texImage(image->makeTextureImage(context));
- if (!texImage) {
- // We execpt to fail if image comes from a different GrContext.
- if (!origTexture || origTexture->getContext() == context) {
- ERRORF(reporter, "newTextureImage failed.");
- }
- continue;
- }
- GrTexture* copyTexture = as_IB(texImage)->peekTexture();
- if (!copyTexture) {
- ERRORF(reporter, "newTextureImage returned non-texture image.");
- continue;
- }
- if (origTexture) {
- if (origTexture != copyTexture) {
- ERRORF(reporter, "newTextureImage made unnecessary texture copy.");
- }
- }
- if (image->width() != texImage->width() || image->height() != texImage->height()) {
- ERRORF(reporter, "newTextureImage changed the image size.");
- }
- if (image->alphaType() != texImage->alphaType()) {
- ERRORF(reporter, "newTextureImage changed image alpha type.");
- }
- }
-}
-
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contextInfo) {
GrContext* context = contextInfo.grContext();
@@ -531,9 +469,7 @@
sk_sp<SkImage> image = factory();
if (!image->isTextureBacked()) {
REPORTER_ASSERT(reporter, image->makeNonTextureImage().get() == image.get());
- if (!(image = image->makeTextureImage(context))) {
- continue;
- }
+ continue;
}
auto rasterImage = image->makeNonTextureImage();
if (!rasterImage) {