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.
+ */
+ sk_sp<SkImage> makeNonTextureImage() const;
+ /**
* Apply a given image filter to this image, and return the filtered result.
*
* The subset represents the active portion of this image. The return value is similarly an
return nullptr;
}
+sk_sp<SkImage> SkImage::makeNonTextureImage() const {
+ return sk_ref_sp(const_cast<SkImage*>(this));
+}
+
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
return create_image_from_maker(&maker, at, this->uniqueID());
}
+sk_sp<SkImage> SkImage::makeNonTextureImage() const {
+ GrTexture* texture = as_IB(this)->peekTexture();
+ if (!texture) {
+ return sk_ref_sp(const_cast<SkImage*>(this));
+ }
+ SkColorType ct;
+ sk_sp<SkColorSpace> cs;
+ if (!GrPixelConfigToColorAndColorSpace(texture->config(), &ct, &cs)) {
+ return nullptr;
+ }
+ SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
+ auto info = SkImageInfo::Make(this->width(), this->height(), ct, at, cs);
+ size_t rowBytes = info.minRowBytes();
+ size_t size = info.getSafeSize(rowBytes);
+ auto data = SkData::MakeUninitialized(size);
+ if (!data) {
+ return nullptr;
+ }
+ SkPixmap pm(info, data->writable_data(), rowBytes);
+ if (!this->readPixels(pm, 0, 0, kDisallow_CachingHint)) {
+ return nullptr;
+ }
+ return MakeRasterData(info, data, rowBytes);
+}
+
sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
SkBudgeted budgeted) {
if (!ctx) {
}
}
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contextInfo) {
+ GrContext* context = contextInfo.grContext();
+
+ std::function<sk_sp<SkImage>()> imageFactories[] = {
+ create_image,
+ create_codec_image,
+ create_data_image,
+ create_picture_image,
+ [context] { return create_gpu_image(context); },
+ };
+ for (auto factory : imageFactories) {
+ sk_sp<SkImage> image = factory();
+ if (!image->isTextureBacked()) {
+ REPORTER_ASSERT(reporter, image->makeNonTextureImage().get() == image.get());
+ if (!(image = image->makeTextureImage(context))) {
+ continue;
+ }
+ }
+ auto rasterImage = image->makeNonTextureImage();
+ if (!rasterImage) {
+ ERRORF(reporter, "makeNonTextureImage failed for texture-backed image.");
+ }
+ REPORTER_ASSERT(reporter, !rasterImage->isTextureBacked());
+ assert_equal(reporter, image.get(), nullptr, rasterImage.get());
+ }
+}
+
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_drawAbandonedGpuImage, reporter, contextInfo) {
auto context = contextInfo.grContext();
auto image = create_gpu_image(context);