Remove MakeCrossContextFromEncoded, unused argument from ...FromPixmap

Change-Id: I962e923a4994eb549a9c1002323f33d05b936b84
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/234912
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2019-08-15 12:13:53 -04:00 committed by Skia Commit-Bot
parent 5b218519a4
commit 4c3fd34e00
9 changed files with 19 additions and 137 deletions

View File

@ -30,6 +30,9 @@ Milestone 78
* Add SkCodec::SelectionPolicy for distinguishing between decoding a still image
or an image sequence for a container format that has both (e.g. HEIF).
* SkImage::makeTextureImage no longer takes an SkColorSpace parameter. It was unused.
* SkImage::makeTextureImage and SkImage::MakeCrossContextFromPixmap no longer take an
SkColorSpace parameter. It was unused.
* SkImage::reinterpretColorSpace - to reinterpret image contents in a new color space.
* Removed SkImage::MakeCrossContextFromEncoded.

View File

@ -1,13 +0,0 @@
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "tools/fiddle/examples.h"
// HASH=069c7b116479e3ca46f953f07dcbdd36
REG_FIDDLE(Image_MakeCrossContextFromEncoded, 256, 64, false, 4) {
void draw(SkCanvas* canvas) {
GrContext* context = canvas->getGrContext();
sk_sp<SkData> encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, 100);
sk_sp<SkImage> image = SkImage::MakeCrossContextFromEncoded(context,
encodedData, false, nullptr);
canvas->drawImage(image, 0, 0);
}
} // END FIDDLE

View File

@ -7,8 +7,7 @@ void draw(SkCanvas* canvas) {
GrContext* context = canvas->getGrContext();
SkPixmap pixmap;
if (source.peekPixels(&pixmap)) {
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap,
false, nullptr);
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap, false);
canvas->drawImage(image, 0, 0);
}
}

View File

@ -23,14 +23,14 @@ class GrContext;
class GrRenderTargetContext;
DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg,
5 * 256 + 60, 256 + 128 + 30) {
3 * 256 + 40, 256 + 128 + 30) {
sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png");
if (!encodedData) {
*errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?";
return skiagm::DrawResult::kFail;
}
sk_sp<SkImage> images[5];
sk_sp<SkImage> images[3];
images[0] = SkImage::MakeFromEncoded(encodedData);
SkBitmap bmp;
@ -38,10 +38,8 @@ DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg,
SkAssertResult(images[0]->asLegacyBitmap(&bmp) &&
bmp.peekPixels(&pixmap));
images[1] = SkImage::MakeCrossContextFromEncoded(context, encodedData, false, nullptr);
images[2] = SkImage::MakeCrossContextFromEncoded(context, encodedData, true, nullptr);
images[3] = SkImage::MakeCrossContextFromPixmap(context, pixmap, false, nullptr);
images[4] = SkImage::MakeCrossContextFromPixmap(context, pixmap, true, nullptr);
images[1] = SkImage::MakeCrossContextFromPixmap(context, pixmap, false);
images[2] = SkImage::MakeCrossContextFromPixmap(context, pixmap, true);
canvas->translate(10, 10);

View File

@ -315,35 +315,6 @@ public:
TextureReleaseProc textureReleaseProc,
ReleaseContext releaseContext);
/** Creates SkImage from encoded data. SkImage is uploaded to GPU back-end using context.
Created SkImage is available to other GPU contexts, and is available across thread
boundaries. All contexts must be in the same GPU share group, or otherwise
share resources.
When SkImage is no longer referenced, context releases texture memory
asynchronously.
GrBackendTexture decoded from data is uploaded to match SkSurface created with
dstColorSpace. SkColorSpace of SkImage is determined by encoded data.
SkImage is returned if format of data is recognized and supported, and if context
supports moving resources. Recognized formats vary by platform and GPU back-end.
SkImage is returned using MakeFromEncoded() if context is nullptr or does not support
moving resources between contexts.
@param context GPU context
@param data SkImage to decode
@param buildMips create SkImage as mip map if true
@param dstColorSpace range of colors of matching SkSurface on GPU
@param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary
@return created SkImage, or nullptr
*/
static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data,
bool buildMips, SkColorSpace* dstColorSpace,
bool limitToMaxTextureSize = false);
/** Creates SkImage from pixmap. SkImage is uploaded to GPU back-end using context.
Created SkImage is available to other GPU contexts, and is available across thread
@ -370,9 +341,15 @@ public:
@return created SkImage, or nullptr
*/
static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
bool buildMips, SkColorSpace* dstColorSpace,
bool buildMips,
bool limitToMaxTextureSize = false);
static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
bool buildMips, SkColorSpace*,
bool limitToMaxTextureSize = false) {
return MakeCrossContextFromPixmap(context, pixmap, buildMips, limitToMaxTextureSize);
}
/** Creates SkImage from backendTexture associated with context. backendTexture and
returned SkImage are managed internally, and are released when no longer needed.

View File

@ -462,72 +462,8 @@ sk_sp<SkImage> SkImage_Gpu::MakePromiseTexture(GrContext* context,
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkImage> SkImage::MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> encoded,
bool buildMips, SkColorSpace* dstColorSpace,
bool limitToMaxTextureSize) {
sk_sp<SkImage> codecImage = SkImage::MakeFromEncoded(std::move(encoded));
if (!codecImage) {
return nullptr;
}
// Some backends or drivers don't support (safely) moving resources between contexts
if (!context || !context->priv().caps()->crossContextTextureSupport()) {
return codecImage;
}
// If non-power-of-two mipmapping isn't supported, ignore the client's request
if (!context->priv().caps()->mipMapSupport()) {
buildMips = false;
}
auto maxTextureSize = context->priv().caps()->maxTextureSize();
if (limitToMaxTextureSize &&
(codecImage->width() > maxTextureSize || codecImage->height() > maxTextureSize)) {
SkAutoPixmapStorage pmap;
SkImageInfo info = codecImage->imageInfo();
if (!dstColorSpace) {
info = info.makeColorSpace(nullptr);
}
if (!pmap.tryAlloc(info) || !codecImage->readPixels(pmap, 0, 0, kDisallow_CachingHint)) {
return nullptr;
}
return MakeCrossContextFromPixmap(context, pmap, buildMips, dstColorSpace, true);
}
// Turn the codec image into a GrTextureProxy
GrImageTextureMaker maker(context, codecImage.get(), kDisallow_CachingHint);
GrSamplerState samplerState(
GrSamplerState::WrapMode::kClamp,
buildMips ? GrSamplerState::Filter::kMipMap : GrSamplerState::Filter::kBilerp);
SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
sk_sp<GrTextureProxy> proxy(maker.refTextureProxyForParams(samplerState, scaleAdjust));
// Given that we disable mipmaps if non-power-of-two mipmapping isn't supported, we always
// expect the created texture to be unscaled.
SkASSERT(scaleAdjust[0] == 1.0f && scaleAdjust[1] == 1.0f);
if (!proxy) {
return codecImage;
}
// Flush any writes or uploads
context->priv().flushSurface(proxy.get());
if (!proxy->isInstantiated()) {
return codecImage;
}
sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture());
GrGpu* gpu = context->priv().getGpu();
sk_sp<GrSemaphore> sema = gpu->prepareTextureForCrossContextUsage(texture.get());
auto gen = GrBackendTextureImageGenerator::Make(
std::move(texture), proxy->origin(), std::move(sema), codecImage->colorType(),
codecImage->alphaType(), codecImage->refColorSpace());
return SkImage::MakeFromGenerator(std::move(gen));
}
sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrContext* context,
const SkPixmap& originalPixmap, bool buildMips,
SkColorSpace* dstColorSpace,
bool limitToMaxTextureSize) {
// Some backends or drivers don't support (safely) moving resources between contexts
if (!context || !context->priv().caps()->crossContextTextureSupport()) {

View File

@ -1010,19 +1010,6 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte
}
}
DEF_GPUTEST(SkImage_MakeCrossContextFromEncodedRelease, reporter, options) {
sk_sp<SkData> data = GetResourceAsData("images/mandrill_128.png");
if (!data) {
ERRORF(reporter, "missing resource");
return;
}
test_cross_context_image(reporter, options, "SkImage_MakeCrossContextFromEncodedRelease",
[&data](GrContext* ctx) {
return SkImage::MakeCrossContextFromEncoded(ctx, data, false, nullptr);
});
}
DEF_GPUTEST(SkImage_MakeCrossContextFromPixmapRelease, reporter, options) {
SkBitmap bitmap;
SkPixmap pixmap;
@ -1032,7 +1019,7 @@ DEF_GPUTEST(SkImage_MakeCrossContextFromPixmapRelease, reporter, options) {
}
test_cross_context_image(reporter, options, "SkImage_MakeCrossContextFromPixmapRelease",
[&pixmap](GrContext* ctx) {
return SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false, nullptr);
return SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false);
});
}
@ -1051,7 +1038,7 @@ DEF_GPUTEST(SkImage_CrossContextGrayAlphaConfigs, reporter, options) {
continue;
}
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false, nullptr);
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false);
REPORTER_ASSERT(reporter, image);
sk_sp<GrTextureProxy> proxy = as_IB(image)->asTextureProxyRef(

View File

@ -372,7 +372,6 @@
#include "../../docs/examples/ImageInfo_width.cpp"
#include "../../docs/examples/Image_Filter_Methods.cpp"
#include "../../docs/examples/Image_MakeBackendTextureFromSkImage.cpp"
#include "../../docs/examples/Image_MakeCrossContextFromEncoded.cpp"
#include "../../docs/examples/Image_MakeCrossContextFromPixmap.cpp"
#include "../../docs/examples/Image_MakeFromAdoptedTexture.cpp"
#include "../../docs/examples/Image_MakeFromBitmap.cpp"

View File

@ -1208,13 +1208,9 @@ int32_t y() const;
SkImage
static bool MakeBackendTextureFromSkImage(GrContext* context, sk_sp<SkImage> image, GrBackendTexture* backendTexture, BackendTextureReleaseProc* backendTextureReleaseProc);
[Image_MakeCrossContextFromEncoded]
SkImage
static sk_sp<SkImage> MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> data, bool buildMips, SkColorSpace* dstColorSpace, bool limitToMaxTextureSize = false);
[Image_MakeCrossContextFromPixmap]
SkImage
static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap, bool buildMips, SkColorSpace* dstColorSpace, bool limitToMaxTextureSize = false);
static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap, bool buildMips, bool limitToMaxTextureSize = false);
[Image_MakeFromAdoptedTexture]
SkImage