2015-06-22 19:48:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-01-30 18:01:40 +00:00
|
|
|
#include <functional>
|
2016-03-10 02:44:43 +00:00
|
|
|
#include <initializer_list>
|
2016-06-13 18:18:14 +00:00
|
|
|
#include <vector>
|
2016-01-30 18:01:40 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkImageEncoder.h"
|
|
|
|
#include "include/core/SkImageGenerator.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkSerialProcs.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2019-05-09 14:30:12 +00:00
|
|
|
#include "include/gpu/GrContextThreadSafeProxy.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
|
|
|
#include "src/core/SkColorSpacePriv.h"
|
|
|
|
#include "src/core/SkImagePriv.h"
|
|
|
|
#include "src/core/SkUtils.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-05-09 14:30:12 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
2020-10-01 13:43:29 +00:00
|
|
|
#include "src/gpu/GrImageContextPriv.h"
|
2020-02-15 18:41:30 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-05-09 14:30:12 +00:00
|
|
|
#include "src/gpu/GrResourceCache.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-05-09 14:30:12 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/image/SkImage_Base.h"
|
2019-05-09 14:30:12 +00:00
|
|
|
#include "src/image/SkImage_GpuYUVA.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/Resources.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
|
2016-04-05 19:59:06 +00:00
|
|
|
using namespace sk_gpu_test;
|
2016-03-31 01:56:19 +00:00
|
|
|
|
2017-02-07 21:52:07 +00:00
|
|
|
SkImageInfo read_pixels_info(SkImage* image) {
|
2019-03-21 19:30:08 +00:00
|
|
|
if (image->colorSpace()) {
|
2017-02-07 21:52:07 +00:00
|
|
|
return SkImageInfo::MakeS32(image->width(), image->height(), image->alphaType());
|
|
|
|
}
|
|
|
|
|
|
|
|
return SkImageInfo::MakeN32(image->width(), image->height(), image->alphaType());
|
|
|
|
}
|
|
|
|
|
2020-08-27 16:44:07 +00:00
|
|
|
// image `b` is assumed to be raster
|
|
|
|
static void assert_equal(skiatest::Reporter* reporter, GrDirectContext* dContextA, SkImage* a,
|
|
|
|
const SkIRect* subsetA, SkImage* b) {
|
2015-06-22 19:48:26 +00:00
|
|
|
const int widthA = subsetA ? subsetA->width() : a->width();
|
|
|
|
const int heightA = subsetA ? subsetA->height() : a->height();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, widthA == b->width());
|
|
|
|
REPORTER_ASSERT(reporter, heightA == b->height());
|
2016-03-09 23:21:32 +00:00
|
|
|
|
|
|
|
// see https://bug.skia.org/3965
|
|
|
|
//REPORTER_ASSERT(reporter, a->isOpaque() == b->isOpaque());
|
2015-06-22 19:48:26 +00:00
|
|
|
|
|
|
|
SkAutoPixmapStorage pmapA, pmapB;
|
2017-02-07 21:52:07 +00:00
|
|
|
pmapA.alloc(read_pixels_info(a));
|
|
|
|
pmapB.alloc(read_pixels_info(b));
|
2015-06-22 19:48:26 +00:00
|
|
|
|
|
|
|
const int srcX = subsetA ? subsetA->x() : 0;
|
|
|
|
const int srcY = subsetA ? subsetA->y() : 0;
|
|
|
|
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, a->readPixels(dContextA, pmapA, srcX, srcY));
|
|
|
|
REPORTER_ASSERT(reporter, b->readPixels(nullptr, pmapB, 0, 0));
|
2015-06-22 19:48:26 +00:00
|
|
|
|
2017-02-07 21:52:07 +00:00
|
|
|
const size_t widthBytes = widthA * 4;
|
2015-06-22 19:48:26 +00:00
|
|
|
for (int y = 0; y < heightA; ++y) {
|
|
|
|
REPORTER_ASSERT(reporter, !memcmp(pmapA.addr32(0, y), pmapB.addr32(0, y), widthBytes));
|
|
|
|
}
|
|
|
|
}
|
2015-11-24 15:39:40 +00:00
|
|
|
static void draw_image_test_pattern(SkCanvas* canvas) {
|
2015-06-22 19:48:26 +00:00
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
2015-11-24 15:39:40 +00:00
|
|
|
canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint);
|
|
|
|
}
|
2016-03-17 17:51:11 +00:00
|
|
|
static sk_sp<SkImage> create_image() {
|
2015-11-24 15:39:40 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRaster(info));
|
2015-11-24 15:39:40 +00:00
|
|
|
draw_image_test_pattern(surface->getCanvas());
|
2016-03-17 17:51:11 +00:00
|
|
|
return surface->makeImageSnapshot();
|
2015-06-22 19:48:26 +00:00
|
|
|
}
|
2016-08-02 21:40:46 +00:00
|
|
|
static sk_sp<SkData> create_image_data(SkImageInfo* info) {
|
2016-04-20 15:27:18 +00:00
|
|
|
*info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
|
|
|
|
const size_t rowBytes = info->minRowBytes();
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data(SkData::MakeUninitialized(rowBytes * info->height()));
|
2016-04-20 15:27:18 +00:00
|
|
|
{
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.installPixels(*info, data->writable_data(), rowBytes);
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
draw_image_test_pattern(&canvas);
|
|
|
|
}
|
2016-08-02 21:40:46 +00:00
|
|
|
return data;
|
2016-04-20 15:27:18 +00:00
|
|
|
}
|
|
|
|
static sk_sp<SkImage> create_data_image() {
|
|
|
|
SkImageInfo info;
|
|
|
|
sk_sp<SkData> data(create_image_data(&info));
|
2016-08-02 21:40:46 +00:00
|
|
|
return SkImage::MakeRasterData(info, std::move(data), info.minRowBytes());
|
2016-04-20 15:27:18 +00:00
|
|
|
}
|
2017-01-03 16:35:56 +00:00
|
|
|
static sk_sp<SkImage> create_image_large(int maxTextureSize) {
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32(maxTextureSize + 1, 32, kOpaque_SkAlphaType);
|
2016-06-13 19:13:03 +00:00
|
|
|
auto surface(SkSurface::MakeRaster(info));
|
|
|
|
surface->getCanvas()->clear(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
surface->getCanvas()->drawRect(SkRect::MakeXYWH(4000, 2, 28000, 30), paint);
|
|
|
|
return surface->makeImageSnapshot();
|
|
|
|
}
|
2016-03-17 17:51:11 +00:00
|
|
|
static sk_sp<SkImage> create_picture_image() {
|
2016-01-30 18:01:40 +00:00
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(10, 10);
|
|
|
|
canvas->clear(SK_ColorCYAN);
|
2016-03-18 14:25:55 +00:00
|
|
|
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize::Make(10, 10),
|
2017-01-09 17:38:59 +00:00
|
|
|
nullptr, nullptr, SkImage::BitDepth::kU8,
|
2017-02-07 18:56:11 +00:00
|
|
|
SkColorSpace::MakeSRGB());
|
2016-01-30 18:01:40 +00:00
|
|
|
};
|
2015-11-24 15:39:40 +00:00
|
|
|
// Want to ensure that our Release is called when the owning image is destroyed
|
|
|
|
struct RasterDataHolder {
|
|
|
|
RasterDataHolder() : fReleaseCount(0) {}
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> fData;
|
2015-11-24 15:39:40 +00:00
|
|
|
int fReleaseCount;
|
|
|
|
static void Release(const void* pixels, void* context) {
|
|
|
|
RasterDataHolder* self = static_cast<RasterDataHolder*>(context);
|
|
|
|
self->fReleaseCount++;
|
|
|
|
self->fData.reset();
|
|
|
|
}
|
|
|
|
};
|
2016-03-17 17:51:11 +00:00
|
|
|
static sk_sp<SkImage> create_rasterproc_image(RasterDataHolder* dataHolder) {
|
2015-11-24 15:39:40 +00:00
|
|
|
SkASSERT(dataHolder);
|
|
|
|
SkImageInfo info;
|
2016-08-02 21:40:46 +00:00
|
|
|
dataHolder->fData = create_image_data(&info);
|
|
|
|
return SkImage::MakeFromRaster(SkPixmap(info, dataHolder->fData->data(), info.minRowBytes()),
|
2016-03-17 17:51:11 +00:00
|
|
|
RasterDataHolder::Release, dataHolder);
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2016-03-17 17:51:11 +00:00
|
|
|
static sk_sp<SkImage> create_codec_image() {
|
2015-11-24 15:39:40 +00:00
|
|
|
SkImageInfo info;
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data(create_image_data(&info));
|
2015-11-24 15:39:40 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(info, data->writable_data(), info.minRowBytes());
|
2018-09-24 19:24:31 +00:00
|
|
|
auto src = SkEncodeBitmap(bitmap, SkEncodedImageFormat::kPNG, 100);
|
2016-08-02 21:40:46 +00:00
|
|
|
return SkImage::MakeFromEncoded(std::move(src));
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2020-07-22 13:35:49 +00:00
|
|
|
static sk_sp<SkImage> create_gpu_image(GrRecordingContext* rContext,
|
2020-03-18 14:06:13 +00:00
|
|
|
bool withMips = false,
|
|
|
|
SkBudgeted budgeted = SkBudgeted::kYes) {
|
2015-11-24 15:39:40 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
|
2020-07-22 13:35:49 +00:00
|
|
|
auto surface = SkSurface::MakeRenderTarget(rContext, budgeted, info, 0,
|
2020-03-18 14:06:13 +00:00
|
|
|
kBottomLeft_GrSurfaceOrigin, nullptr, withMips);
|
2015-11-24 15:39:40 +00:00
|
|
|
draw_image_test_pattern(surface->getCanvas());
|
2016-03-17 17:51:11 +00:00
|
|
|
return surface->makeImageSnapshot();
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2015-06-22 19:48:26 +00:00
|
|
|
|
2020-08-27 16:44:07 +00:00
|
|
|
static void test_encode(skiatest::Reporter* reporter, GrDirectContext* dContext, SkImage* image) {
|
2015-06-22 19:48:26 +00:00
|
|
|
const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10);
|
2017-07-11 20:03:13 +00:00
|
|
|
sk_sp<SkData> origEncoded = image->encodeToData();
|
2015-06-22 19:48:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, origEncoded);
|
|
|
|
REPORTER_ASSERT(reporter, origEncoded->size() > 0);
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> decoded(SkImage::MakeFromEncoded(origEncoded));
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
if (!decoded) {
|
|
|
|
ERRORF(reporter, "failed to decode image!");
|
|
|
|
return;
|
|
|
|
}
|
2015-06-22 19:48:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, decoded);
|
2020-08-27 16:44:07 +00:00
|
|
|
assert_equal(reporter, dContext, image, nullptr, decoded.get());
|
2015-06-22 19:48:26 +00:00
|
|
|
|
|
|
|
// Now see if we can instantiate an image from a subset of the surface/origEncoded
|
2016-03-16 17:28:35 +00:00
|
|
|
|
2020-07-28 16:52:31 +00:00
|
|
|
decoded = SkImage::MakeFromEncoded(origEncoded)->makeSubset(ir);
|
2015-06-22 19:48:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, decoded);
|
2020-08-27 16:44:07 +00:00
|
|
|
assert_equal(reporter, dContext, image, &ir, decoded.get());
|
2015-06-22 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 15:39:40 +00:00
|
|
|
DEF_TEST(ImageEncode, reporter) {
|
2020-08-27 16:44:07 +00:00
|
|
|
test_encode(reporter, nullptr, create_image().get());
|
2015-06-22 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 16:59:58 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, ctxInfo) {
|
2020-08-27 16:44:07 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
test_encode(reporter, dContext, create_gpu_image(dContext).get());
|
2015-06-22 19:48:26 +00:00
|
|
|
}
|
2015-07-04 04:01:10 +00:00
|
|
|
|
2016-08-01 18:12:58 +00:00
|
|
|
DEF_TEST(Image_MakeFromRasterBitmap, reporter) {
|
|
|
|
const struct {
|
2016-08-05 19:07:41 +00:00
|
|
|
SkCopyPixelsMode fCPM;
|
|
|
|
bool fExpectSameAsMutable;
|
|
|
|
bool fExpectSameAsImmutable;
|
2016-08-01 18:12:58 +00:00
|
|
|
} recs[] = {
|
2016-08-05 19:07:41 +00:00
|
|
|
{ kIfMutable_SkCopyPixelsMode, false, true },
|
|
|
|
{ kAlways_SkCopyPixelsMode, false, false },
|
|
|
|
{ kNever_SkCopyPixelsMode, true, true },
|
2016-08-01 18:12:58 +00:00
|
|
|
};
|
|
|
|
for (auto rec : recs) {
|
|
|
|
SkPixmap pm;
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(100, 100);
|
|
|
|
|
2016-08-05 19:07:41 +00:00
|
|
|
auto img = SkMakeImageFromRasterBitmap(bm, rec.fCPM);
|
2016-08-01 18:12:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, img->peekPixels(&pm));
|
|
|
|
const bool sameMutable = pm.addr32(0, 0) == bm.getAddr32(0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, rec.fExpectSameAsMutable == sameMutable);
|
2016-08-05 20:19:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, (bm.getGenerationID() == img->uniqueID()) == sameMutable);
|
2016-08-01 18:12:58 +00:00
|
|
|
|
|
|
|
bm.notifyPixelsChanged(); // force a new generation ID
|
|
|
|
|
|
|
|
bm.setImmutable();
|
2016-08-05 19:07:41 +00:00
|
|
|
img = SkMakeImageFromRasterBitmap(bm, rec.fCPM);
|
2016-08-01 18:12:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, img->peekPixels(&pm));
|
|
|
|
const bool sameImmutable = pm.addr32(0, 0) == bm.getAddr32(0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, rec.fExpectSameAsImmutable == sameImmutable);
|
2016-08-05 20:19:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, (bm.getGenerationID() == img->uniqueID()) == sameImmutable);
|
2016-08-01 18:12:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-04 18:36:39 +00:00
|
|
|
// Test that image encoding failures do not break picture serialization/deserialization.
|
|
|
|
DEF_TEST(Image_Serialize_Encoding_Failure, reporter) {
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRasterN32Premul(100, 100));
|
2015-09-04 18:36:39 +00:00
|
|
|
surface->getCanvas()->clear(SK_ColorGREEN);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
2015-09-04 18:36:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, image);
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(100, 100);
|
Reland "Add new virts, hide old ones"
This reverts commit 8f924ac0ce63806886b7297e8be554984a6e7ce5.
Reason for revert: suppressions landed for fuchsia images to rebaseline
Original change's description:
> Revert "Add new virts, hide old ones"
>
> This reverts commit c56e2e5aa65dd129e5927224d2f6c1f82edff74e.
>
> Reason for revert: suspected of breaking chrome roll
>
> Original change's description:
> > Add new virts, hide old ones
> >
> > Add virtuals for the draw methods that now take sampling/filtermode.
> >
> > drawImage
> > drawImageRect
> > drawImageLattice
> > drawAtlas
> >
> > Add a flag that can remove the older virtuals, once each client has
> > stopped overriding them. In that situation, the older public methods
> > will simplify extract the sampling from the paint, and call the new
> > public methods.
> >
> > Bug: skia:11105, skia:7650
> > Change-Id: I8b0029727295caa983e8148fc743a55cfbecd043
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347022
> > Commit-Queue: Mike Reed <reed@google.com>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,fmalita@chromium.org,reed@google.com
>
> Change-Id: I0a90952c11a180d918126ea06a630f4a0bf9b49b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:11105
> Bug: skia:7650
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348194
> Reviewed-by: Derek Sollenberger <djsollen@google.com>
> Commit-Queue: Derek Sollenberger <djsollen@google.com>
TBR=djsollen@google.com,bsalomon@google.com,fmalita@chromium.org,reed@google.com
# Not skipping CQ checks because this is a reland.
Bug: skia:11105
Bug: skia:7650
Change-Id: Ia2b4537a2d330460b7554278d2c05075cf27162a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348876
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-12-30 14:22:42 +00:00
|
|
|
canvas->drawImage(image.get(), 0, 0, SkSamplingOptions());
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
|
2015-09-04 18:36:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, picture);
|
2018-01-27 17:30:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0);
|
2015-09-04 18:36:39 +00:00
|
|
|
|
2017-12-16 13:41:28 +00:00
|
|
|
bool was_called = false;
|
|
|
|
SkSerialProcs procs;
|
|
|
|
procs.fImageProc = [](SkImage*, void* called) {
|
|
|
|
*(bool*)called = true;
|
|
|
|
return SkData::MakeEmpty();
|
|
|
|
};
|
|
|
|
procs.fImageCtx = &was_called;
|
2015-09-04 18:36:39 +00:00
|
|
|
|
2017-12-16 13:41:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, !was_called);
|
2017-12-20 19:12:07 +00:00
|
|
|
auto data = picture->serialize(&procs);
|
2017-12-16 13:41:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, was_called);
|
|
|
|
REPORTER_ASSERT(reporter, data && data->size() > 0);
|
2015-09-04 18:36:39 +00:00
|
|
|
|
2017-12-16 13:41:28 +00:00
|
|
|
auto deserialized = SkPicture::MakeFromData(data->data(), data->size());
|
|
|
|
REPORTER_ASSERT(reporter, deserialized);
|
2018-01-27 17:30:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0);
|
2015-09-04 18:36:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 12:56:16 +00:00
|
|
|
// Test that a draw that only partially covers the drawing surface isn't
|
|
|
|
// interpreted as covering the entire drawing surface (i.e., exercise one of the
|
|
|
|
// conditions of SkCanvas::wouldOverwriteEntireSurface()).
|
|
|
|
DEF_TEST(Image_RetainSnapshot, reporter) {
|
|
|
|
const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0);
|
|
|
|
const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0);
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRaster(info));
|
2015-07-22 12:56:16 +00:00
|
|
|
surface->getCanvas()->clear(0xFF00FF00);
|
|
|
|
|
|
|
|
SkPMColor pixels[4];
|
|
|
|
memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect
|
|
|
|
const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2);
|
|
|
|
const size_t dstRowBytes = 2 * sizeof(SkPMColor);
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image1(surface->makeImageSnapshot());
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, image1->readPixels(nullptr, dstInfo, pixels, dstRowBytes, 0, 0));
|
2015-07-22 12:56:16 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, pixels[i] == green);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint paint;
|
2016-10-06 00:33:02 +00:00
|
|
|
paint.setBlendMode(SkBlendMode::kSrc);
|
2015-07-22 12:56:16 +00:00
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
|
|
|
|
surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint);
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image2(surface->makeImageSnapshot());
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, image2->readPixels(nullptr, dstInfo, pixels, dstRowBytes, 0, 0));
|
2015-07-22 12:56:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, pixels[0] == green);
|
|
|
|
REPORTER_ASSERT(reporter, pixels[1] == green);
|
|
|
|
REPORTER_ASSERT(reporter, pixels[2] == green);
|
|
|
|
REPORTER_ASSERT(reporter, pixels[3] == red);
|
|
|
|
}
|
2015-07-31 01:58:23 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void make_bitmap_mutable(SkBitmap* bm) {
|
|
|
|
bm->allocN32Pixels(10, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_bitmap_immutable(SkBitmap* bm) {
|
|
|
|
bm->allocN32Pixels(10, 10);
|
|
|
|
bm->setImmutable();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(image_newfrombitmap, reporter) {
|
|
|
|
const struct {
|
|
|
|
void (*fMakeProc)(SkBitmap*);
|
|
|
|
bool fExpectPeekSuccess;
|
|
|
|
bool fExpectSharedID;
|
2015-08-20 15:47:26 +00:00
|
|
|
bool fExpectLazy;
|
2015-07-31 01:58:23 +00:00
|
|
|
} rec[] = {
|
2015-08-20 15:47:26 +00:00
|
|
|
{ make_bitmap_mutable, true, false, false },
|
|
|
|
{ make_bitmap_immutable, true, true, false },
|
2015-07-31 01:58:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
|
|
|
|
SkBitmap bm;
|
|
|
|
rec[i].fMakeProc(&bm);
|
|
|
|
|
2020-12-23 16:50:36 +00:00
|
|
|
sk_sp<SkImage> image(bm.asImage());
|
2015-07-31 01:58:23 +00:00
|
|
|
SkPixmap pmap;
|
|
|
|
|
|
|
|
const bool sharedID = (image->uniqueID() == bm.getGenerationID());
|
|
|
|
REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID);
|
|
|
|
|
|
|
|
const bool peekSuccess = image->peekPixels(&pmap);
|
|
|
|
REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess);
|
2015-08-20 15:47:26 +00:00
|
|
|
|
|
|
|
const bool lazy = image->isLazyGenerated();
|
|
|
|
REPORTER_ASSERT(reporter, lazy == rec[i].fExpectLazy);
|
2015-07-31 01:58:23 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-04 15:10:13 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkBitmapCache.h"
|
2015-08-04 15:10:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This tests the caching (and preemptive purge) of the raster equivalent of a gpu-image.
|
|
|
|
* We cache it for performance when drawing into a raster surface.
|
|
|
|
*
|
|
|
|
* A cleaner test would know if each drawImage call triggered a read-back from the gpu,
|
|
|
|
* but we don't have that facility (at the moment) so we use a little internal knowledge
|
|
|
|
* of *how* the raster version is cached, and look for that.
|
|
|
|
*/
|
2018-10-04 18:19:39 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_Gpu2Cpu, reporter, ctxInfo) {
|
2015-11-24 15:39:40 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
|
2020-07-06 14:56:46 +00:00
|
|
|
sk_sp<SkImage> image(create_gpu_image(ctxInfo.directContext()));
|
2017-03-25 13:51:00 +00:00
|
|
|
const auto desc = SkBitmapCacheDesc::Make(image.get());
|
2015-08-04 15:10:13 +00:00
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRaster(info));
|
2015-08-04 15:10:13 +00:00
|
|
|
|
|
|
|
// now we can test drawing a gpu-backed image into a cpu-backed surface
|
|
|
|
|
|
|
|
{
|
|
|
|
SkBitmap cachedBitmap;
|
2017-03-25 13:51:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, !SkBitmapCache::Find(desc, &cachedBitmap));
|
2015-08-04 15:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
surface->getCanvas()->drawImage(image, 0, 0);
|
|
|
|
{
|
|
|
|
SkBitmap cachedBitmap;
|
2017-03-25 13:51:00 +00:00
|
|
|
if (SkBitmapCache::Find(desc, &cachedBitmap)) {
|
2015-08-04 15:10:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, cachedBitmap.isImmutable());
|
|
|
|
REPORTER_ASSERT(reporter, cachedBitmap.getPixels());
|
|
|
|
} else {
|
|
|
|
// unexpected, but not really a bug, since the cache is global and this test may be
|
|
|
|
// run w/ other threads competing for its budget.
|
|
|
|
SkDebugf("SkImage_Gpu2Cpu : cachedBitmap was already purged\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
image.reset(nullptr);
|
|
|
|
{
|
|
|
|
SkBitmap cachedBitmap;
|
2017-03-25 13:51:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, !SkBitmapCache::Find(desc, &cachedBitmap));
|
2015-08-04 15:10:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-30 18:01:40 +00:00
|
|
|
|
2017-02-07 16:23:28 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextInfo) {
|
2020-07-22 13:35:49 +00:00
|
|
|
auto dContext = contextInfo.directContext();
|
2017-02-07 16:23:28 +00:00
|
|
|
sk_gpu_test::TestContext* testContext = contextInfo.testContext();
|
|
|
|
GrContextFactory otherFactory;
|
2017-06-08 20:03:17 +00:00
|
|
|
ContextInfo otherContextInfo = otherFactory.getContextInfo(contextInfo.type());
|
2017-02-07 16:23:28 +00:00
|
|
|
testContext->makeCurrent();
|
|
|
|
std::function<sk_sp<SkImage>()> imageFactories[] = {
|
2020-03-18 14:06:13 +00:00
|
|
|
create_image, create_codec_image, create_data_image,
|
|
|
|
// Create an image from a picture.
|
|
|
|
create_picture_image,
|
|
|
|
// Create a texture image.
|
2020-07-22 13:35:49 +00:00
|
|
|
[dContext] { return create_gpu_image(dContext, true, SkBudgeted::kYes); },
|
|
|
|
[dContext] { return create_gpu_image(dContext, false, SkBudgeted::kNo); },
|
2020-07-23 17:54:35 +00:00
|
|
|
// Create a texture image in a another context.
|
2020-03-18 14:06:13 +00:00
|
|
|
[otherContextInfo] {
|
|
|
|
auto restore = otherContextInfo.testContext()->makeCurrentAndAutoRestore();
|
2020-07-06 14:56:46 +00:00
|
|
|
auto otherContextImage = create_gpu_image(otherContextInfo.directContext());
|
|
|
|
otherContextInfo.directContext()->flushAndSubmit();
|
2020-03-18 14:06:13 +00:00
|
|
|
return otherContextImage;
|
|
|
|
}};
|
2021-01-26 22:46:50 +00:00
|
|
|
for (auto mipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
|
2020-07-31 00:24:57 +00:00
|
|
|
for (const auto& factory : imageFactories) {
|
2019-08-14 17:19:04 +00:00
|
|
|
sk_sp<SkImage> image(factory());
|
|
|
|
if (!image) {
|
|
|
|
ERRORF(reporter, "Error creating image.");
|
|
|
|
continue;
|
|
|
|
}
|
2020-03-18 14:06:13 +00:00
|
|
|
GrTextureProxy* origProxy = nullptr;
|
2021-01-26 22:46:50 +00:00
|
|
|
bool origIsMippedTexture = false;
|
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
if ((origProxy = sk_gpu_test::GetTextureImageProxy(image.get(), dContext))) {
|
2021-01-26 22:46:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, (origProxy->mipmapped() == GrMipmapped::kYes) ==
|
|
|
|
image->hasMipmaps());
|
|
|
|
origIsMippedTexture = image->hasMipmaps();
|
2019-08-14 17:19:04 +00:00
|
|
|
}
|
2020-03-18 14:06:13 +00:00
|
|
|
for (auto budgeted : {SkBudgeted::kNo, SkBudgeted::kYes}) {
|
2021-01-26 22:46:50 +00:00
|
|
|
auto texImage = image->makeTextureImage(dContext, mipmapped, budgeted);
|
2020-03-18 14:06:13 +00:00
|
|
|
if (!texImage) {
|
2020-09-14 15:58:06 +00:00
|
|
|
auto imageContext = as_IB(image)->context();
|
2020-07-23 17:54:35 +00:00
|
|
|
// We expect to fail if image comes from a different context
|
2020-10-01 13:43:29 +00:00
|
|
|
if (!image->isTextureBacked() || imageContext->priv().matches(dContext)) {
|
2020-03-18 14:06:13 +00:00
|
|
|
ERRORF(reporter, "makeTextureImage failed.");
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!texImage->isTextureBacked()) {
|
|
|
|
ERRORF(reporter, "makeTextureImage returned non-texture image.");
|
|
|
|
continue;
|
|
|
|
}
|
2021-02-23 15:45:39 +00:00
|
|
|
|
|
|
|
GrTextureProxy* copyProxy = sk_gpu_test::GetTextureImageProxy(texImage.get(),
|
|
|
|
dContext);
|
2020-03-18 14:06:13 +00:00
|
|
|
SkASSERT(copyProxy);
|
2021-01-26 22:46:50 +00:00
|
|
|
// Did we ask for MIPs on a context that supports them?
|
|
|
|
bool validRequestForMips = (mipmapped == GrMipmapped::kYes &&
|
|
|
|
dContext->priv().caps()->mipmapSupport());
|
|
|
|
// Do we expect the "copy" to have MIPs?
|
|
|
|
bool shouldBeMipped = origIsMippedTexture || validRequestForMips;
|
|
|
|
REPORTER_ASSERT(reporter, shouldBeMipped == texImage->hasMipmaps());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
shouldBeMipped == (copyProxy->mipmapped() == GrMipmapped::kYes));
|
|
|
|
|
|
|
|
// We should only make a copy of an already texture-backed image if it didn't
|
|
|
|
// already have MIPs but we asked for MIPs and the context supports it.
|
|
|
|
if (image->isTextureBacked() && (!validRequestForMips || origIsMippedTexture)) {
|
2020-03-18 14:06:13 +00:00
|
|
|
if (origProxy->underlyingUniqueID() != copyProxy->underlyingUniqueID()) {
|
2019-08-14 17:19:04 +00:00
|
|
|
ERRORF(reporter, "makeTextureImage made unnecessary texture copy.");
|
2018-06-12 20:39:59 +00:00
|
|
|
}
|
2020-03-18 14:06:13 +00:00
|
|
|
} else {
|
2021-02-23 15:45:39 +00:00
|
|
|
GrTextureProxy* texProxy = sk_gpu_test::GetTextureImageProxy(texImage.get(),
|
|
|
|
dContext);
|
2020-03-18 14:06:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, !texProxy->getUniqueKey().isValid());
|
|
|
|
REPORTER_ASSERT(reporter, texProxy->isBudgeted() == budgeted);
|
|
|
|
}
|
|
|
|
if (image->width() != texImage->width() || image->height() != texImage->height()) {
|
|
|
|
ERRORF(reporter, "makeTextureImage changed the image size.");
|
|
|
|
}
|
|
|
|
if (image->alphaType() != texImage->alphaType()) {
|
|
|
|
ERRORF(reporter, "makeTextureImage changed image alpha type.");
|
2018-06-12 20:39:59 +00:00
|
|
|
}
|
2017-02-07 16:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-22 13:35:49 +00:00
|
|
|
dContext->flushAndSubmit();
|
2017-02-07 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 01:11:17 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contextInfo) {
|
2020-08-27 16:44:07 +00:00
|
|
|
auto dContext = contextInfo.directContext();
|
2016-07-13 01:11:17 +00:00
|
|
|
|
|
|
|
std::function<sk_sp<SkImage>()> imageFactories[] = {
|
|
|
|
create_image,
|
|
|
|
create_codec_image,
|
|
|
|
create_data_image,
|
|
|
|
create_picture_image,
|
2020-08-27 16:44:07 +00:00
|
|
|
[dContext] { return create_gpu_image(dContext); },
|
2016-07-13 01:11:17 +00:00
|
|
|
};
|
2020-07-31 00:24:57 +00:00
|
|
|
for (const auto& factory : imageFactories) {
|
2016-07-13 01:11:17 +00:00
|
|
|
sk_sp<SkImage> image = factory();
|
|
|
|
if (!image->isTextureBacked()) {
|
|
|
|
REPORTER_ASSERT(reporter, image->makeNonTextureImage().get() == image.get());
|
2020-08-27 16:44:07 +00:00
|
|
|
if (!(image = image->makeTextureImage(dContext))) {
|
2017-02-07 16:23:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-07-13 01:11:17 +00:00
|
|
|
}
|
|
|
|
auto rasterImage = image->makeNonTextureImage();
|
|
|
|
if (!rasterImage) {
|
|
|
|
ERRORF(reporter, "makeNonTextureImage failed for texture-backed image.");
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, !rasterImage->isTextureBacked());
|
2020-08-27 16:44:07 +00:00
|
|
|
assert_equal(reporter, dContext, image.get(), nullptr, rasterImage.get());
|
2016-07-13 01:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsImage, reporter, ctxInfo) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2019-05-17 14:01:21 +00:00
|
|
|
|
|
|
|
static constexpr int kSize = 10;
|
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
|
|
|
|
SkColorType colorType = static_cast<SkColorType>(ct);
|
2020-08-11 15:48:49 +00:00
|
|
|
bool can = dContext->colorTypeSupportedAsImage(colorType);
|
2019-05-17 14:01:21 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
|
|
|
|
dContext, kSize, kSize, colorType, GrMipmapped::kNo, GrRenderable::kNo);
|
2020-11-05 16:11:20 +00:00
|
|
|
sk_sp<SkImage> img;
|
|
|
|
if (mbet) {
|
|
|
|
img = SkImage::MakeFromTexture(dContext, mbet->texture(), kTopLeft_GrSurfaceOrigin,
|
|
|
|
colorType, kOpaque_SkAlphaType, nullptr);
|
2020-10-13 00:45:06 +00:00
|
|
|
}
|
2018-02-03 01:32:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, can == SkToBool(img),
|
2018-02-26 14:58:58 +00:00
|
|
|
"colorTypeSupportedAsImage:%d, actual:%d, ct:%d", can, SkToBool(img),
|
2018-02-03 01:32:49 +00:00
|
|
|
colorType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-05 17:57:10 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UnpremulTextureImage, reporter, ctxInfo) {
|
|
|
|
SkBitmap bmp;
|
|
|
|
bmp.allocPixels(
|
|
|
|
SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr));
|
|
|
|
for (int y = 0; y < 256; ++y) {
|
|
|
|
for (int x = 0; x < 256; ++x) {
|
|
|
|
*bmp.getAddr32(x, y) =
|
|
|
|
SkColorSetARGB((U8CPU)y, 255 - (U8CPU)y, (U8CPU)x, 255 - (U8CPU)x);
|
|
|
|
}
|
|
|
|
}
|
2020-08-27 16:44:07 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2020-12-23 16:50:36 +00:00
|
|
|
auto texImage = bmp.asImage()->makeTextureImage(dContext);
|
2018-02-05 17:57:10 +00:00
|
|
|
if (!texImage || texImage->alphaType() != kUnpremul_SkAlphaType) {
|
|
|
|
ERRORF(reporter, "Failed to make unpremul texture image.");
|
|
|
|
return;
|
|
|
|
}
|
2019-07-01 17:05:28 +00:00
|
|
|
SkBitmap unpremul;
|
|
|
|
unpremul.allocPixels(SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType,
|
|
|
|
kUnpremul_SkAlphaType, nullptr));
|
2020-08-27 16:44:07 +00:00
|
|
|
if (!texImage->readPixels(dContext, unpremul.info(), unpremul.getPixels(), unpremul.rowBytes(),
|
|
|
|
0, 0)) {
|
2019-07-01 17:05:28 +00:00
|
|
|
ERRORF(reporter, "Unpremul readback failed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int y = 0; y < 256; ++y) {
|
|
|
|
for (int x = 0; x < 256; ++x) {
|
|
|
|
if (*bmp.getAddr32(x, y) != *unpremul.getAddr32(x, y)) {
|
|
|
|
ERRORF(reporter, "unpremul(0x%08x)->unpremul(0x%08x) at %d, %d.",
|
|
|
|
*bmp.getAddr32(x, y), *unpremul.getAddr32(x, y), x, y);
|
|
|
|
return;
|
2018-02-05 17:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkBitmap premul;
|
|
|
|
premul.allocPixels(
|
|
|
|
SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr));
|
2020-08-27 16:44:07 +00:00
|
|
|
if (!texImage->readPixels(dContext, premul.info(), premul.getPixels(), premul.rowBytes(),
|
|
|
|
0, 0)) {
|
2018-02-05 17:57:10 +00:00
|
|
|
ERRORF(reporter, "Unpremul readback failed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int y = 0; y < 256; ++y) {
|
|
|
|
for (int x = 0; x < 256; ++x) {
|
2019-07-01 17:05:28 +00:00
|
|
|
uint32_t origColor = *bmp.getAddr32(x, y);
|
2018-02-05 17:57:10 +00:00
|
|
|
int32_t origA = (origColor >> 24) & 0xff;
|
2019-07-01 17:05:28 +00:00
|
|
|
float a = origA / 255.f;
|
|
|
|
int32_t origB = sk_float_round2int(((origColor >> 16) & 0xff) * a);
|
|
|
|
int32_t origG = sk_float_round2int(((origColor >> 8) & 0xff) * a);
|
|
|
|
int32_t origR = sk_float_round2int(((origColor >> 0) & 0xff) * a);
|
|
|
|
|
2018-02-05 17:57:10 +00:00
|
|
|
uint32_t read = *premul.getAddr32(x, y);
|
|
|
|
int32_t readA = (read >> 24) & 0xff;
|
|
|
|
int32_t readB = (read >> 16) & 0xff;
|
|
|
|
int32_t readG = (read >> 8) & 0xff;
|
|
|
|
int32_t readR = (read >> 0) & 0xff;
|
|
|
|
// We expect that alpha=1 and alpha=0 should come out exact. Otherwise allow a little
|
|
|
|
// bit of tolerance for GPU vs CPU premul math.
|
|
|
|
int32_t tol = (origA == 0 || origA == 255) ? 0 : 1;
|
|
|
|
if (origA != readA || SkTAbs(readB - origB) > tol || SkTAbs(readG - origG) > tol ||
|
|
|
|
SkTAbs(readR - origR) > tol) {
|
2019-07-01 17:05:28 +00:00
|
|
|
ERRORF(reporter, "unpremul(0x%08x)->premul(0x%08x) expected(0x%08x) at %d, %d.",
|
|
|
|
*bmp.getAddr32(x, y), *premul.getAddr32(x, y), origColor, x, y);
|
2018-02-05 17:57:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-24 18:08:31 +00:00
|
|
|
DEF_GPUTEST(AbandonedContextImage, reporter, options) {
|
|
|
|
using Factory = sk_gpu_test::GrContextFactory;
|
|
|
|
for (int ct = 0; ct < Factory::kContextTypeCnt; ++ct) {
|
|
|
|
auto type = static_cast<Factory::ContextType>(ct);
|
|
|
|
std::unique_ptr<Factory> factory(new Factory);
|
|
|
|
if (!factory->get(type)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<SkImage> img;
|
|
|
|
auto gsurf = SkSurface::MakeRenderTarget(
|
|
|
|
factory->get(type), SkBudgeted::kYes,
|
|
|
|
SkImageInfo::Make(100, 100, kRGBA_8888_SkColorType, kPremul_SkAlphaType), 1,
|
|
|
|
nullptr);
|
|
|
|
if (!gsurf) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
img = gsurf->makeImageSnapshot();
|
|
|
|
gsurf.reset();
|
|
|
|
|
|
|
|
auto rsurf = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100));
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, img->isValid(factory->get(type)));
|
2020-09-14 15:58:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, img->isValid(rsurf->getCanvas()->recordingContext()));
|
2018-05-24 18:08:31 +00:00
|
|
|
|
|
|
|
factory->get(type)->abandonContext();
|
|
|
|
REPORTER_ASSERT(reporter, !img->isValid(factory->get(type)));
|
2020-09-14 15:58:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, !img->isValid(rsurf->getCanvas()->recordingContext()));
|
2018-05-24 18:08:31 +00:00
|
|
|
// This shouldn't crash.
|
|
|
|
rsurf->getCanvas()->drawImage(img, 0, 0);
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
// Give up all other refs on the context.
|
2018-05-24 18:08:31 +00:00
|
|
|
factory.reset(nullptr);
|
2020-09-14 15:58:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, !img->isValid(rsurf->getCanvas()->recordingContext()));
|
2018-05-24 18:08:31 +00:00
|
|
|
// This shouldn't crash.
|
|
|
|
rsurf->getCanvas()->drawImage(img, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 06:53:28 +00:00
|
|
|
class EmptyGenerator : public SkImageGenerator {
|
|
|
|
public:
|
|
|
|
EmptyGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {}
|
|
|
|
};
|
|
|
|
|
2015-11-24 15:39:40 +00:00
|
|
|
DEF_TEST(ImageEmpty, reporter) {
|
2015-11-18 06:53:28 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
|
2016-03-17 17:51:11 +00:00
|
|
|
SkPixmap pmap(info, nullptr, 0);
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkImage::MakeRasterCopy(pmap));
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkImage::MakeRasterData(info, nullptr, 0));
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkImage::MakeFromRaster(pmap, nullptr, nullptr));
|
2017-02-15 20:14:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkImage::MakeFromGenerator(
|
2019-12-11 15:45:01 +00:00
|
|
|
std::make_unique<EmptyGenerator>()));
|
2015-11-18 06:53:28 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 15:39:40 +00:00
|
|
|
DEF_TEST(ImageDataRef, reporter) {
|
2015-11-18 06:53:28 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
|
|
|
|
size_t rowBytes = info.minRowBytes();
|
2017-10-03 18:47:21 +00:00
|
|
|
size_t size = info.computeByteSize(rowBytes);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkData> data = SkData::MakeUninitialized(size);
|
2015-11-18 06:53:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, data->unique());
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, rowBytes);
|
2015-11-18 06:53:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, !data->unique());
|
2016-03-17 17:51:11 +00:00
|
|
|
image.reset();
|
2015-11-18 06:53:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, data->unique());
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected) {
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
if (pixels[i] != expected) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-27 16:44:07 +00:00
|
|
|
static void image_test_read_pixels(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
SkImage* image) {
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
if (!image) {
|
|
|
|
ERRORF(reporter, "Failed to create image!");
|
|
|
|
return;
|
|
|
|
}
|
2015-11-24 15:39:40 +00:00
|
|
|
const SkPMColor expected = SkPreMultiplyColor(SK_ColorWHITE);
|
2015-11-18 06:53:28 +00:00
|
|
|
const SkPMColor notExpected = ~expected;
|
|
|
|
|
|
|
|
const int w = 2, h = 2;
|
|
|
|
const size_t rowBytes = w * sizeof(SkPMColor);
|
|
|
|
SkPMColor pixels[w*h];
|
|
|
|
|
|
|
|
SkImageInfo info;
|
|
|
|
|
|
|
|
info = SkImageInfo::MakeUnknown(w, h);
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes, 0, 0));
|
2015-11-18 06:53:28 +00:00
|
|
|
|
|
|
|
// out-of-bounds should fail
|
|
|
|
info = SkImageInfo::MakeN32Premul(w, h);
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes, -w, 0));
|
|
|
|
REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes, 0, -h));
|
|
|
|
REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes,
|
|
|
|
image->width(), 0));
|
|
|
|
REPORTER_ASSERT(reporter, !image->readPixels(dContext, info, pixels, rowBytes,
|
|
|
|
0, image->height()));
|
2015-11-18 06:53:28 +00:00
|
|
|
|
|
|
|
// top-left should succeed
|
2015-11-24 15:39:40 +00:00
|
|
|
sk_memset32(pixels, notExpected, w*h);
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->readPixels(dContext, info, pixels, rowBytes, 0, 0));
|
2015-11-18 06:53:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected));
|
|
|
|
|
|
|
|
// bottom-right should succeed
|
2015-11-24 15:39:40 +00:00
|
|
|
sk_memset32(pixels, notExpected, w*h);
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->readPixels(dContext, info, pixels, rowBytes,
|
2015-11-18 06:53:28 +00:00
|
|
|
image->width() - w, image->height() - h));
|
|
|
|
REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected));
|
|
|
|
|
|
|
|
// partial top-left should succeed
|
2015-11-24 15:39:40 +00:00
|
|
|
sk_memset32(pixels, notExpected, w*h);
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->readPixels(dContext, info, pixels, rowBytes, -1, -1));
|
2015-11-18 06:53:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, pixels[3] == expected);
|
|
|
|
REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected));
|
|
|
|
|
|
|
|
// partial bottom-right should succeed
|
2015-11-24 15:39:40 +00:00
|
|
|
sk_memset32(pixels, notExpected, w*h);
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->readPixels(dContext, info, pixels, rowBytes,
|
2015-11-18 06:53:28 +00:00
|
|
|
image->width() - 1, image->height() - 1));
|
|
|
|
REPORTER_ASSERT(reporter, pixels[0] == expected);
|
|
|
|
REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected));
|
|
|
|
}
|
2015-11-24 15:39:40 +00:00
|
|
|
DEF_TEST(ImageReadPixels, reporter) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(create_image());
|
2020-08-27 16:44:07 +00:00
|
|
|
image_test_read_pixels(nullptr, reporter, image.get());
|
2015-11-24 15:39:40 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
image = create_data_image();
|
2020-08-27 16:44:07 +00:00
|
|
|
image_test_read_pixels(nullptr, reporter, image.get());
|
2015-11-24 15:39:40 +00:00
|
|
|
|
|
|
|
RasterDataHolder dataHolder;
|
2016-03-17 17:51:11 +00:00
|
|
|
image = create_rasterproc_image(&dataHolder);
|
2020-08-27 16:44:07 +00:00
|
|
|
image_test_read_pixels(nullptr, reporter, image.get());
|
2015-11-24 15:39:40 +00:00
|
|
|
image.reset();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
image = create_codec_image();
|
2020-08-27 16:44:07 +00:00
|
|
|
image_test_read_pixels(nullptr, reporter, image.get());
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, ctxInfo) {
|
2020-08-27 16:44:07 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
image_test_read_pixels(dContext, reporter, create_gpu_image(dContext).get());
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2020-08-27 16:44:07 +00:00
|
|
|
static void check_legacy_bitmap(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
|
|
|
const SkImage* image, const SkBitmap& bitmap) {
|
2015-11-18 06:53:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->width() == bitmap.width());
|
|
|
|
REPORTER_ASSERT(reporter, image->height() == bitmap.height());
|
2016-08-17 21:01:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->alphaType() == bitmap.alphaType());
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2018-02-07 20:51:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, bitmap.isImmutable());
|
2015-11-18 06:53:28 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, bitmap.getPixels());
|
|
|
|
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32(1, 1, bitmap.alphaType());
|
|
|
|
SkPMColor imageColor;
|
2020-08-27 16:44:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->readPixels(dContext, info, &imageColor, sizeof(SkPMColor),
|
|
|
|
0, 0));
|
2015-11-18 06:53:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, imageColor == *bitmap.getAddr32(0, 0));
|
|
|
|
}
|
|
|
|
|
2020-08-27 16:44:07 +00:00
|
|
|
static void test_legacy_bitmap(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
|
|
|
const SkImage* image) {
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
if (!image) {
|
|
|
|
ERRORF(reporter, "Failed to create image.");
|
|
|
|
return;
|
|
|
|
}
|
2015-11-24 15:39:40 +00:00
|
|
|
SkBitmap bitmap;
|
2018-02-07 20:51:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->asLegacyBitmap(&bitmap));
|
2020-08-27 16:44:07 +00:00
|
|
|
check_legacy_bitmap(reporter, dContext, image, bitmap);
|
2015-11-24 15:39:40 +00:00
|
|
|
|
|
|
|
// Test subsetting to exercise the rowBytes logic.
|
|
|
|
SkBitmap tmp;
|
|
|
|
REPORTER_ASSERT(reporter, bitmap.extractSubset(&tmp, SkIRect::MakeWH(image->width() / 2,
|
|
|
|
image->height() / 2)));
|
2020-12-23 16:50:36 +00:00
|
|
|
sk_sp<SkImage> subsetImage(tmp.asImage());
|
2016-03-17 17:51:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, subsetImage.get());
|
2015-11-24 15:39:40 +00:00
|
|
|
|
|
|
|
SkBitmap subsetBitmap;
|
2018-02-07 20:51:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, subsetImage->asLegacyBitmap(&subsetBitmap));
|
2020-08-27 16:44:07 +00:00
|
|
|
check_legacy_bitmap(reporter, nullptr, subsetImage.get(), subsetBitmap);
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
|
|
|
DEF_TEST(ImageLegacyBitmap, reporter) {
|
2018-02-07 20:51:00 +00:00
|
|
|
sk_sp<SkImage> image(create_image());
|
2020-08-27 16:44:07 +00:00
|
|
|
test_legacy_bitmap(reporter, nullptr, image.get());
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2018-02-07 20:51:00 +00:00
|
|
|
image = create_data_image();
|
2020-08-27 16:44:07 +00:00
|
|
|
test_legacy_bitmap(reporter, nullptr, image.get());
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2018-02-07 20:51:00 +00:00
|
|
|
RasterDataHolder dataHolder;
|
|
|
|
image = create_rasterproc_image(&dataHolder);
|
2020-08-27 16:44:07 +00:00
|
|
|
test_legacy_bitmap(reporter, nullptr, image.get());
|
2018-02-07 20:51:00 +00:00
|
|
|
image.reset();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2018-02-07 20:51:00 +00:00
|
|
|
image = create_codec_image();
|
2020-08-27 16:44:07 +00:00
|
|
|
test_legacy_bitmap(reporter, nullptr, image.get());
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2016-04-12 16:59:58 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, ctxInfo) {
|
2020-08-27 16:44:07 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
sk_sp<SkImage> image(create_gpu_image(dContext));
|
|
|
|
test_legacy_bitmap(reporter, dContext, image.get());
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2015-11-24 15:39:40 +00:00
|
|
|
static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectPeekSuccess) {
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
if (!image) {
|
|
|
|
ERRORF(reporter, "Failed to create image!");
|
|
|
|
return;
|
|
|
|
}
|
2016-03-09 22:26:26 +00:00
|
|
|
SkPixmap pm;
|
|
|
|
bool success = image->peekPixels(&pm);
|
2015-11-24 15:39:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectPeekSuccess == success);
|
|
|
|
if (success) {
|
2016-03-09 22:26:26 +00:00
|
|
|
const SkImageInfo& info = pm.info();
|
2015-11-24 15:39:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, 20 == info.width());
|
|
|
|
REPORTER_ASSERT(reporter, 20 == info.height());
|
|
|
|
REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType());
|
|
|
|
REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() ||
|
|
|
|
kOpaque_SkAlphaType == info.alphaType());
|
2016-03-09 22:26:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, info.minRowBytes() <= pm.rowBytes());
|
|
|
|
REPORTER_ASSERT(reporter, SkPreMultiplyColor(SK_ColorWHITE) == *pm.addr32(0, 0));
|
2015-11-18 06:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-24 15:39:40 +00:00
|
|
|
DEF_TEST(ImagePeek, reporter) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(create_image());
|
|
|
|
test_peek(reporter, image.get(), true);
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
image = create_data_image();
|
|
|
|
test_peek(reporter, image.get(), true);
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2015-11-24 15:39:40 +00:00
|
|
|
RasterDataHolder dataHolder;
|
2016-03-17 17:51:11 +00:00
|
|
|
image = create_rasterproc_image(&dataHolder);
|
|
|
|
test_peek(reporter, image.get(), true);
|
2015-11-24 15:39:40 +00:00
|
|
|
image.reset();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == dataHolder.fReleaseCount);
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
image = create_codec_image();
|
|
|
|
test_peek(reporter, image.get(), false);
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
sk_sp<SkImage> image(create_gpu_image(ctxInfo.directContext()));
|
2016-03-17 17:51:11 +00:00
|
|
|
test_peek(reporter, image.get(), false);
|
2015-11-24 15:39:40 +00:00
|
|
|
}
|
2015-11-18 06:53:28 +00:00
|
|
|
|
2015-11-24 15:39:40 +00:00
|
|
|
struct TextureReleaseChecker {
|
|
|
|
TextureReleaseChecker() : fReleaseCount(0) {}
|
|
|
|
int fReleaseCount;
|
|
|
|
static void Release(void* self) {
|
|
|
|
static_cast<TextureReleaseChecker*>(self)->fReleaseCount++;
|
2015-11-18 06:53:28 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2016-07-22 14:22:04 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, ctxInfo) {
|
|
|
|
const int kWidth = 10;
|
|
|
|
const int kHeight = 10;
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext,
|
|
|
|
kWidth,
|
|
|
|
kHeight,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
GrRenderable::kNo,
|
|
|
|
GrProtected::kNo);
|
|
|
|
if (!mbet) {
|
2019-05-07 17:29:22 +00:00
|
|
|
ERRORF(reporter, "couldn't create backend texture\n");
|
2020-11-05 16:11:20 +00:00
|
|
|
return;
|
2019-05-07 17:29:22 +00:00
|
|
|
}
|
2016-07-22 14:22:04 +00:00
|
|
|
|
2015-11-24 15:39:40 +00:00
|
|
|
TextureReleaseChecker releaseChecker;
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin;
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<SkImage> refImg = SkImage::MakeFromTexture(
|
|
|
|
dContext,
|
|
|
|
mbet->texture(),
|
|
|
|
texOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
/*color space*/nullptr,
|
|
|
|
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker));
|
2015-11-24 15:39:40 +00:00
|
|
|
|
2017-01-31 22:53:34 +00:00
|
|
|
GrSurfaceOrigin readBackOrigin;
|
2018-04-04 19:54:55 +00:00
|
|
|
GrBackendTexture readBackBackendTex = refImg->getBackendTexture(false, &readBackOrigin);
|
2020-10-13 00:45:06 +00:00
|
|
|
if (!GrBackendTexture::TestingOnly_Equals(readBackBackendTex, mbet->texture())) {
|
2018-04-04 19:54:55 +00:00
|
|
|
ERRORF(reporter, "backend mismatch\n");
|
2017-01-31 22:53:34 +00:00
|
|
|
}
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
GrBackendTexture::TestingOnly_Equals(readBackBackendTex, mbet->texture()));
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
if (readBackOrigin != texOrigin) {
|
|
|
|
ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin);
|
2017-01-31 22:53:34 +00:00
|
|
|
}
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
REPORTER_ASSERT(reporter, readBackOrigin == texOrigin);
|
2017-01-31 22:53:34 +00:00
|
|
|
|
2015-11-18 06:53:28 +00:00
|
|
|
// Now exercise the release proc
|
2015-11-24 15:39:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
|
2015-11-18 06:53:28 +00:00
|
|
|
refImg.reset(nullptr); // force a release of the image
|
2015-11-24 15:39:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
|
2015-11-18 06:53:28 +00:00
|
|
|
}
|
2016-03-10 02:44:43 +00:00
|
|
|
|
2017-11-15 20:48:03 +00:00
|
|
|
static void test_cross_context_image(skiatest::Reporter* reporter, const GrContextOptions& options,
|
2018-03-22 19:17:42 +00:00
|
|
|
const char* testName,
|
2020-07-22 13:35:49 +00:00
|
|
|
std::function<sk_sp<SkImage>(GrDirectContext*)> imageMaker) {
|
2017-06-21 19:10:33 +00:00
|
|
|
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
|
2017-11-15 20:48:03 +00:00
|
|
|
GrContextFactory testFactory(options);
|
2017-06-21 19:10:33 +00:00
|
|
|
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
|
|
|
|
ContextInfo ctxInfo = testFactory.getContextInfo(ctxType);
|
2020-07-22 13:35:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
if (!dContext) {
|
2017-06-21 19:10:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
// If we don't have proper support for this feature, the factory will fallback to returning
|
|
|
|
// codec-backed images. Those will "work", but some of our checks will fail because we
|
|
|
|
// expect the cross-context images not to work on multiple contexts at once.
|
2020-07-22 13:35:49 +00:00
|
|
|
if (!dContext->priv().caps()->crossContextTextureSupport()) {
|
2017-06-21 19:10:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
// We test three lifetime patterns for a single context:
|
|
|
|
// 1) Create image, free image
|
|
|
|
// 2) Create image, draw, flush, free image
|
|
|
|
// 3) Create image, draw, free image, flush
|
|
|
|
// ... and then repeat the last two patterns with drawing on a second* context:
|
|
|
|
// 4) Create image, draw*, flush*, free image
|
|
|
|
// 5) Create image, draw*, free iamge, flush*
|
|
|
|
|
|
|
|
// Case #1: Create image, free image
|
|
|
|
{
|
2020-07-22 13:35:49 +00:00
|
|
|
sk_sp<SkImage> refImg(imageMaker(dContext));
|
2017-06-21 19:10:33 +00:00
|
|
|
refImg.reset(nullptr); // force a release of the image
|
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
|
2020-07-22 13:35:49 +00:00
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info);
|
2018-03-22 19:17:42 +00:00
|
|
|
if (!surface) {
|
|
|
|
ERRORF(reporter, "SkSurface::MakeRenderTarget failed for %s.", testName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
// Case #2: Create image, draw, flush, free image
|
|
|
|
{
|
2020-07-22 13:35:49 +00:00
|
|
|
sk_sp<SkImage> refImg(imageMaker(dContext));
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
canvas->drawImage(refImg, 0, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
refImg.reset(nullptr); // force a release of the image
|
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
// Case #3: Create image, draw, free image, flush
|
|
|
|
{
|
2020-07-22 13:35:49 +00:00
|
|
|
sk_sp<SkImage> refImg(imageMaker(dContext));
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
canvas->drawImage(refImg, 0, 0);
|
|
|
|
refImg.reset(nullptr); // force a release of the image
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2017-06-21 19:10:33 +00:00
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
// Configure second context
|
|
|
|
sk_gpu_test::TestContext* testContext = ctxInfo.testContext();
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2020-07-22 13:35:49 +00:00
|
|
|
ContextInfo otherContextInfo = testFactory.getSharedContextInfo(dContext);
|
2020-07-06 14:56:46 +00:00
|
|
|
auto otherCtx = otherContextInfo.directContext();
|
2017-06-21 19:10:33 +00:00
|
|
|
sk_gpu_test::TestContext* otherTestContext = otherContextInfo.testContext();
|
|
|
|
|
|
|
|
// Creating a context in a share group may fail
|
|
|
|
if (!otherCtx) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
surface = SkSurface::MakeRenderTarget(otherCtx, SkBudgeted::kNo, info);
|
|
|
|
canvas = surface->getCanvas();
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
// Case #4: Create image, draw*, flush*, free image
|
|
|
|
{
|
|
|
|
testContext->makeCurrent();
|
2020-07-22 13:35:49 +00:00
|
|
|
sk_sp<SkImage> refImg(imageMaker(dContext));
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
otherTestContext->makeCurrent();
|
|
|
|
canvas->drawImage(refImg, 0, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
testContext->makeCurrent();
|
|
|
|
refImg.reset(nullptr); // force a release of the image
|
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
// Case #5: Create image, draw*, free image, flush*
|
|
|
|
{
|
|
|
|
testContext->makeCurrent();
|
2020-07-22 13:35:49 +00:00
|
|
|
sk_sp<SkImage> refImg(imageMaker(dContext));
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
otherTestContext->makeCurrent();
|
|
|
|
canvas->drawImage(refImg, 0, 0);
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
testContext->makeCurrent();
|
|
|
|
refImg.reset(nullptr); // force a release of the image
|
|
|
|
|
|
|
|
otherTestContext->makeCurrent();
|
2021-02-12 17:10:43 +00:00
|
|
|
// Sync is specifically here for vulkan to guarantee the command buffer will finish
|
2018-03-08 14:49:58 +00:00
|
|
|
// which is when we call the ReleaseProc.
|
2021-02-12 17:10:43 +00:00
|
|
|
surface->flushAndSubmit(true);
|
2017-06-21 19:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Case #6: Verify that only one context can be using the image at a time
|
|
|
|
{
|
2020-07-23 17:54:35 +00:00
|
|
|
// Suppress warnings about trying to use a texture in two contexts.
|
2020-02-15 18:41:30 +00:00
|
|
|
GrRecordingContextPriv::AutoSuppressWarningMessages aswm(otherCtx);
|
|
|
|
|
2017-06-21 19:10:33 +00:00
|
|
|
testContext->makeCurrent();
|
2020-07-22 13:35:49 +00:00
|
|
|
sk_sp<SkImage> refImg(imageMaker(dContext));
|
2021-02-03 15:15:31 +00:00
|
|
|
GrSurfaceProxyView view, otherView, viewSecondRef;
|
2017-06-21 19:10:33 +00:00
|
|
|
|
|
|
|
// Any context should be able to borrow the texture at this point
|
2021-02-03 15:15:31 +00:00
|
|
|
std::tie(view, std::ignore) = as_IB(refImg)->asView(dContext, GrMipmapped::kNo);
|
2020-02-05 22:06:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, view);
|
2017-06-21 19:10:33 +00:00
|
|
|
|
|
|
|
// But once it's borrowed, no other context should be able to borrow
|
|
|
|
otherTestContext->makeCurrent();
|
2021-02-03 15:15:31 +00:00
|
|
|
std::tie(otherView, std::ignore) = as_IB(refImg)->asView(otherCtx, GrMipmapped::kNo);
|
2020-02-05 22:06:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, !otherView);
|
2017-06-21 19:10:33 +00:00
|
|
|
|
|
|
|
// Original context (that's already borrowing) should be okay
|
|
|
|
testContext->makeCurrent();
|
2021-02-03 15:15:31 +00:00
|
|
|
std::tie(viewSecondRef, std::ignore) = as_IB(refImg)->asView(dContext,
|
|
|
|
GrMipmapped::kNo);
|
2020-02-05 22:06:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, viewSecondRef);
|
2017-06-21 19:10:33 +00:00
|
|
|
|
2018-02-01 15:07:57 +00:00
|
|
|
// Release first ref from the original context
|
2020-02-05 22:06:27 +00:00
|
|
|
view.reset();
|
2018-02-01 15:07:57 +00:00
|
|
|
|
|
|
|
// We released one proxy but not the other from the current borrowing context. Make sure
|
|
|
|
// a new context is still not able to borrow the texture.
|
|
|
|
otherTestContext->makeCurrent();
|
2021-02-03 15:15:31 +00:00
|
|
|
std::tie(otherView, std::ignore) = as_IB(refImg)->asView(otherCtx, GrMipmapped::kNo);
|
2020-02-05 22:06:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, !otherView);
|
2018-02-01 15:07:57 +00:00
|
|
|
|
|
|
|
// Release second ref from the original context
|
|
|
|
testContext->makeCurrent();
|
2020-02-05 22:06:27 +00:00
|
|
|
viewSecondRef.reset();
|
2017-06-21 19:10:33 +00:00
|
|
|
|
2018-01-22 21:11:35 +00:00
|
|
|
// Now we should be able to borrow the texture from the other context
|
2017-06-21 19:10:33 +00:00
|
|
|
otherTestContext->makeCurrent();
|
2021-02-03 15:15:31 +00:00
|
|
|
std::tie(otherView, std::ignore) = as_IB(refImg)->asView(otherCtx, GrMipmapped::kNo);
|
2020-02-05 22:06:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, otherView);
|
2017-06-21 19:10:33 +00:00
|
|
|
|
|
|
|
// Release everything
|
2020-02-05 22:06:27 +00:00
|
|
|
otherView.reset();
|
2017-06-21 19:10:33 +00:00
|
|
|
refImg.reset(nullptr);
|
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 20:48:03 +00:00
|
|
|
DEF_GPUTEST(SkImage_MakeCrossContextFromPixmapRelease, reporter, options) {
|
2017-11-07 15:37:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
SkPixmap pixmap;
|
2018-11-26 20:34:12 +00:00
|
|
|
if (!GetResourceAsBitmap("images/mandrill_128.png", &bitmap) || !bitmap.peekPixels(&pixmap)) {
|
|
|
|
ERRORF(reporter, "missing resource");
|
|
|
|
return;
|
|
|
|
}
|
2018-03-22 19:17:42 +00:00
|
|
|
test_cross_context_image(reporter, options, "SkImage_MakeCrossContextFromPixmapRelease",
|
2020-07-22 13:35:49 +00:00
|
|
|
[&pixmap](GrDirectContext* dContext) {
|
|
|
|
return SkImage::MakeCrossContextFromPixmap(dContext, pixmap, false);
|
2017-11-07 15:37:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-27 13:56:31 +00:00
|
|
|
DEF_GPUTEST(SkImage_CrossContextGrayAlphaConfigs, reporter, options) {
|
|
|
|
|
|
|
|
for (SkColorType ct : { kGray_8_SkColorType, kAlpha_8_SkColorType }) {
|
|
|
|
SkAutoPixmapStorage pixmap;
|
|
|
|
pixmap.alloc(SkImageInfo::Make(4, 4, ct, kPremul_SkAlphaType));
|
|
|
|
|
|
|
|
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
|
|
|
|
GrContextFactory testFactory(options);
|
|
|
|
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
|
|
|
|
ContextInfo ctxInfo = testFactory.getContextInfo(ctxType);
|
2020-08-11 15:47:47 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
if (!dContext || !dContext->priv().caps()->crossContextTextureSupport()) {
|
2018-03-27 13:56:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-08-11 15:47:47 +00:00
|
|
|
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, false);
|
2018-03-27 13:56:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, image);
|
|
|
|
|
2021-02-03 15:15:31 +00:00
|
|
|
auto [view, viewCT] = as_IB(image)->asView(dContext, GrMipmapped::kNo);
|
2020-02-05 22:06:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, view);
|
2021-02-03 15:15:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrColorTypeToSkColorType(viewCT) == ct);
|
2018-03-27 13:56:31 +00:00
|
|
|
|
|
|
|
bool expectAlpha = kAlpha_8_SkColorType == ct;
|
2019-10-11 17:51:02 +00:00
|
|
|
GrColorType grCT = SkColorTypeToGrColorType(image->colorType());
|
|
|
|
REPORTER_ASSERT(reporter, expectAlpha == GrColorTypeIsAlphaOnly(grCT));
|
2018-03-27 13:56:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 19:44:50 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(makeBackendTexture, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2017-10-12 19:44:50 +00:00
|
|
|
sk_gpu_test::TestContext* testContext = ctxInfo.testContext();
|
|
|
|
sk_sp<GrContextThreadSafeProxy> proxy = context->threadSafeProxy();
|
|
|
|
|
|
|
|
GrContextFactory otherFactory;
|
|
|
|
ContextInfo otherContextInfo = otherFactory.getContextInfo(ctxInfo.type());
|
|
|
|
|
|
|
|
testContext->makeCurrent();
|
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
auto createLarge = [context] {
|
2019-02-04 18:26:26 +00:00
|
|
|
return create_image_large(context->priv().caps()->maxTextureSize());
|
2017-10-12 19:44:50 +00:00
|
|
|
};
|
2020-07-31 00:24:57 +00:00
|
|
|
struct TestCase {
|
|
|
|
std::function<sk_sp<SkImage>()> fImageFactory;
|
|
|
|
bool fExpectation;
|
|
|
|
bool fCanTakeDirectly;
|
|
|
|
};
|
|
|
|
TestCase testCases[] = {
|
2017-10-12 19:44:50 +00:00
|
|
|
{ create_image, true, false },
|
|
|
|
{ create_codec_image, true, false },
|
|
|
|
{ create_data_image, true, false },
|
|
|
|
{ create_picture_image, true, false },
|
|
|
|
{ [context] { return create_gpu_image(context); }, true, true },
|
2020-07-23 17:54:35 +00:00
|
|
|
// Create a texture image in a another context.
|
2017-11-17 14:25:23 +00:00
|
|
|
{ [otherContextInfo] {
|
|
|
|
auto restore = otherContextInfo.testContext()->makeCurrentAndAutoRestore();
|
2020-07-06 14:56:46 +00:00
|
|
|
sk_sp<SkImage> otherContextImage = create_gpu_image(otherContextInfo.directContext());
|
|
|
|
otherContextInfo.directContext()->flushAndSubmit();
|
2017-10-12 19:44:50 +00:00
|
|
|
return otherContextImage;
|
|
|
|
}, false, false },
|
|
|
|
// Create an image that is too large to be texture backed.
|
|
|
|
{ createLarge, false, false }
|
|
|
|
};
|
|
|
|
|
2020-07-31 00:24:57 +00:00
|
|
|
for (const TestCase& testCase : testCases) {
|
2017-10-12 19:44:50 +00:00
|
|
|
sk_sp<SkImage> image(testCase.fImageFactory());
|
|
|
|
if (!image) {
|
|
|
|
ERRORF(reporter, "Failed to create image!");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-11 14:08:06 +00:00
|
|
|
GrBackendTexture origBackend = image->getBackendTexture(true);
|
|
|
|
if (testCase.fCanTakeDirectly) {
|
|
|
|
SkASSERT(origBackend.isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
GrBackendTexture newBackend;
|
2017-10-12 19:44:50 +00:00
|
|
|
SkImage::BackendTextureReleaseProc proc;
|
2018-04-11 14:08:06 +00:00
|
|
|
bool result = SkImage::MakeBackendTextureFromSkImage(context, std::move(image),
|
|
|
|
&newBackend, &proc);
|
2017-10-12 19:44:50 +00:00
|
|
|
if (result != testCase.fExpectation) {
|
|
|
|
static const char *const kFS[] = { "fail", "succeed" };
|
|
|
|
ERRORF(reporter, "This image was expected to %s but did not.",
|
|
|
|
kFS[testCase.fExpectation]);
|
|
|
|
}
|
|
|
|
|
2018-04-11 14:08:06 +00:00
|
|
|
if (result) {
|
|
|
|
SkASSERT(newBackend.isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tookDirectly = result && GrBackendTexture::TestingOnly_Equals(origBackend, newBackend);
|
2017-10-12 19:44:50 +00:00
|
|
|
if (testCase.fCanTakeDirectly != tookDirectly) {
|
|
|
|
static const char *const kExpectedState[] = { "not expected", "expected" };
|
|
|
|
ERRORF(reporter, "This backend texture was %s to be taken directly.",
|
|
|
|
kExpectedState[testCase.fCanTakeDirectly]);
|
|
|
|
}
|
|
|
|
|
2020-05-14 19:45:44 +00:00
|
|
|
context->flushAndSubmit();
|
2017-10-12 19:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-27 02:42:04 +00:00
|
|
|
|
2021-03-10 21:17:21 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageBackendAccessAbandoned_Gpu, reporter, ctxInfo) {
|
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
sk_sp<SkImage> image(create_gpu_image(ctxInfo.directContext()));
|
|
|
|
if (!image) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrBackendTexture beTex = image->getBackendTexture(true);
|
|
|
|
REPORTER_ASSERT(reporter, beTex.isValid());
|
|
|
|
|
|
|
|
dContext->abandonContext();
|
|
|
|
|
|
|
|
// After abandoning the context the backend texture should not be valid.
|
|
|
|
beTex = image->getBackendTexture(true);
|
|
|
|
REPORTER_ASSERT(reporter, !beTex.isValid());
|
|
|
|
}
|
|
|
|
|
2016-07-27 02:42:04 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-03-06 15:28:24 +00:00
|
|
|
static sk_sp<SkImage> create_picture_image(sk_sp<SkColorSpace> space) {
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(10, 10);
|
|
|
|
canvas->clear(SK_ColorCYAN);
|
|
|
|
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize::Make(10, 10),
|
|
|
|
nullptr, nullptr, SkImage::BitDepth::kU8, std::move(space));
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_TEST(Image_ColorSpace, r) {
|
|
|
|
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
|
2017-12-08 15:21:31 +00:00
|
|
|
sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_512_q075.jpg");
|
2017-03-06 15:28:24 +00:00
|
|
|
REPORTER_ASSERT(r, srgb.get() == image->colorSpace());
|
|
|
|
|
2017-12-08 15:21:31 +00:00
|
|
|
image = GetResourceAsImage("images/webp-color-profile-lossy.webp");
|
2019-01-04 22:03:00 +00:00
|
|
|
skcms_TransferFunction fn;
|
2017-03-06 15:28:24 +00:00
|
|
|
bool success = image->colorSpace()->isNumericalTransferFn(&fn);
|
|
|
|
REPORTER_ASSERT(r, success);
|
2019-01-04 22:03:00 +00:00
|
|
|
REPORTER_ASSERT(r, color_space_almost_equal(1.8f, fn.g));
|
2017-03-06 15:28:24 +00:00
|
|
|
|
2019-01-04 22:03:00 +00:00
|
|
|
sk_sp<SkColorSpace> rec2020 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
|
|
|
|
SkNamedGamut::kRec2020);
|
2017-03-06 15:28:24 +00:00
|
|
|
image = create_picture_image(rec2020);
|
|
|
|
REPORTER_ASSERT(r, SkColorSpace::Equals(rec2020.get(), image->colorSpace()));
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(10, 10, kPremul_SkAlphaType, rec2020);
|
|
|
|
bitmap.allocPixels(info);
|
2020-12-23 16:50:36 +00:00
|
|
|
image = bitmap.asImage();
|
2017-03-06 15:28:24 +00:00
|
|
|
REPORTER_ASSERT(r, SkColorSpace::Equals(rec2020.get(), image->colorSpace()));
|
|
|
|
|
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRaster(
|
|
|
|
SkImageInfo::MakeN32Premul(SkISize::Make(10, 10)));
|
|
|
|
image = surface->makeImageSnapshot();
|
|
|
|
REPORTER_ASSERT(r, nullptr == image->colorSpace());
|
|
|
|
|
|
|
|
surface = SkSurface::MakeRaster(info);
|
|
|
|
image = surface->makeImageSnapshot();
|
|
|
|
REPORTER_ASSERT(r, SkColorSpace::Equals(rec2020.get(), image->colorSpace()));
|
|
|
|
}
|
|
|
|
|
2017-03-14 18:10:48 +00:00
|
|
|
DEF_TEST(Image_makeColorSpace, r) {
|
2020-01-16 17:11:06 +00:00
|
|
|
sk_sp<SkColorSpace> p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3);
|
2019-01-04 22:03:00 +00:00
|
|
|
skcms_TransferFunction fn;
|
|
|
|
fn.a = 1.f; fn.b = 0.f; fn.c = 0.f; fn.d = 0.f; fn.e = 0.f; fn.f = 0.f; fn.g = 1.8f;
|
|
|
|
sk_sp<SkColorSpace> adobeGamut = SkColorSpace::MakeRGB(fn, SkNamedGamut::kAdobeRGB);
|
2017-03-14 18:10:48 +00:00
|
|
|
|
|
|
|
SkBitmap srgbBitmap;
|
|
|
|
srgbBitmap.allocPixels(SkImageInfo::MakeS32(1, 1, kOpaque_SkAlphaType));
|
|
|
|
*srgbBitmap.getAddr32(0, 0) = SkSwizzle_RGBA_to_PMColor(0xFF604020);
|
|
|
|
srgbBitmap.setImmutable();
|
2020-12-23 16:50:36 +00:00
|
|
|
sk_sp<SkImage> srgbImage = srgbBitmap.asImage();
|
2020-07-15 14:37:50 +00:00
|
|
|
sk_sp<SkImage> p3Image = srgbImage->makeColorSpace(p3, nullptr);
|
2017-03-14 18:10:48 +00:00
|
|
|
SkBitmap p3Bitmap;
|
2018-02-07 20:51:00 +00:00
|
|
|
bool success = p3Image->asLegacyBitmap(&p3Bitmap);
|
2018-04-23 19:39:21 +00:00
|
|
|
|
|
|
|
auto almost_equal = [](int a, int b) { return SkTAbs(a - b) <= 2; };
|
|
|
|
|
2017-03-14 18:10:48 +00:00
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x28, SkGetPackedR32(*p3Bitmap.getAddr32(0, 0))));
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x40, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0))));
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x5E, SkGetPackedB32(*p3Bitmap.getAddr32(0, 0))));
|
|
|
|
|
2020-07-15 14:37:50 +00:00
|
|
|
sk_sp<SkImage> adobeImage = srgbImage->makeColorSpace(adobeGamut, nullptr);
|
2017-04-03 15:42:52 +00:00
|
|
|
SkBitmap adobeBitmap;
|
2018-02-07 20:51:00 +00:00
|
|
|
success = adobeImage->asLegacyBitmap(&adobeBitmap);
|
2017-04-03 15:42:52 +00:00
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x21, SkGetPackedR32(*adobeBitmap.getAddr32(0, 0))));
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x31, SkGetPackedG32(*adobeBitmap.getAddr32(0, 0))));
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x4C, SkGetPackedB32(*adobeBitmap.getAddr32(0, 0))));
|
|
|
|
|
2017-12-08 15:21:31 +00:00
|
|
|
srgbImage = GetResourceAsImage("images/1x1.png");
|
2020-07-15 14:37:50 +00:00
|
|
|
p3Image = srgbImage->makeColorSpace(p3, nullptr);
|
2018-02-07 20:51:00 +00:00
|
|
|
success = p3Image->asLegacyBitmap(&p3Bitmap);
|
2017-03-14 18:10:48 +00:00
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x8B, SkGetPackedR32(*p3Bitmap.getAddr32(0, 0))));
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x82, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0))));
|
|
|
|
REPORTER_ASSERT(r, almost_equal(0x77, SkGetPackedB32(*p3Bitmap.getAddr32(0, 0))));
|
|
|
|
}
|
|
|
|
|
2017-03-06 15:28:24 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-07-27 02:42:04 +00:00
|
|
|
static void make_all_premul(SkBitmap* bm) {
|
|
|
|
bm->allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
|
|
|
|
for (int a = 0; a < 256; ++a) {
|
|
|
|
for (int r = 0; r < 256; ++r) {
|
|
|
|
// make all valid premul combinations
|
2020-02-07 15:36:46 +00:00
|
|
|
int c = std::min(a, r);
|
2016-07-27 02:42:04 +00:00
|
|
|
*bm->getAddr32(a, r) = SkPackARGB32(a, c, c, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool equal(const SkBitmap& a, const SkBitmap& b) {
|
|
|
|
SkASSERT(a.width() == b.width());
|
|
|
|
SkASSERT(a.height() == b.height());
|
|
|
|
for (int y = 0; y < a.height(); ++y) {
|
2016-11-28 22:26:27 +00:00
|
|
|
for (int x = 0; x < a.width(); ++x) {
|
|
|
|
SkPMColor pa = *a.getAddr32(x, y);
|
|
|
|
SkPMColor pb = *b.getAddr32(x, y);
|
|
|
|
if (pa != pb) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-27 02:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(image_roundtrip_encode, reporter) {
|
|
|
|
SkBitmap bm0;
|
|
|
|
make_all_premul(&bm0);
|
|
|
|
|
2020-12-23 16:50:36 +00:00
|
|
|
auto img0 = bm0.asImage();
|
2017-07-11 20:03:13 +00:00
|
|
|
sk_sp<SkData> data = img0->encodeToData(SkEncodedImageFormat::kPNG, 100);
|
2016-07-27 02:42:04 +00:00
|
|
|
auto img1 = SkImage::MakeFromEncoded(data);
|
2016-08-02 23:02:05 +00:00
|
|
|
|
2016-07-27 02:42:04 +00:00
|
|
|
SkBitmap bm1;
|
|
|
|
bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
|
2020-08-27 16:44:07 +00:00
|
|
|
img1->readPixels(nullptr, bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
|
2016-08-02 23:02:05 +00:00
|
|
|
|
2016-07-27 02:42:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, equal(bm0, bm1));
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(image_roundtrip_premul, reporter) {
|
|
|
|
SkBitmap bm0;
|
|
|
|
make_all_premul(&bm0);
|
|
|
|
|
|
|
|
SkBitmap bm1;
|
|
|
|
bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType));
|
|
|
|
bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
|
|
|
|
|
|
|
|
SkBitmap bm2;
|
|
|
|
bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
|
|
|
|
bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, equal(bm0, bm2));
|
|
|
|
}
|
2017-04-26 19:28:30 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void check_scaled_pixels(skiatest::Reporter* reporter, SkPixmap* pmap, uint32_t expected) {
|
|
|
|
// Verify that all pixels contain the original test color
|
|
|
|
for (auto y = 0; y < pmap->height(); ++y) {
|
|
|
|
for (auto x = 0; x < pmap->width(); ++x) {
|
|
|
|
uint32_t pixel = *pmap->addr32(x, y);
|
|
|
|
if (pixel != expected) {
|
|
|
|
ERRORF(reporter, "Expected scaled pixels to be the same. At %d,%d 0x%08x != 0x%08x",
|
|
|
|
x, y, pixel, expected);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_scale_pixels(skiatest::Reporter* reporter, const SkImage* image,
|
|
|
|
uint32_t expected) {
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(image->width() * 2, image->height() * 2);
|
|
|
|
|
|
|
|
// Make sure to test kDisallow first, so we don't just get a cache hit in that case
|
|
|
|
for (auto chint : { SkImage::kDisallow_CachingHint, SkImage::kAllow_CachingHint }) {
|
|
|
|
SkAutoPixmapStorage scaled;
|
|
|
|
scaled.alloc(info);
|
2021-01-15 02:59:01 +00:00
|
|
|
if (!image->scalePixels(scaled, SkSamplingOptions(SkFilterMode::kLinear), chint)) {
|
2017-04-26 19:28:30 +00:00
|
|
|
ERRORF(reporter, "Failed to scale image");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
check_scaled_pixels(reporter, &scaled, expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(ImageScalePixels, reporter) {
|
|
|
|
const SkPMColor pmRed = SkPackARGB32(0xFF, 0xFF, 0, 0);
|
|
|
|
const SkColor red = SK_ColorRED;
|
|
|
|
|
|
|
|
// Test raster image
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
|
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRaster(info);
|
|
|
|
surface->getCanvas()->clear(red);
|
|
|
|
sk_sp<SkImage> rasterImage = surface->makeImageSnapshot();
|
|
|
|
test_scale_pixels(reporter, rasterImage.get(), pmRed);
|
|
|
|
|
|
|
|
// Test encoded image
|
2017-07-11 20:03:13 +00:00
|
|
|
sk_sp<SkData> data = rasterImage->encodeToData();
|
2017-04-26 19:28:30 +00:00
|
|
|
sk_sp<SkImage> codecImage = SkImage::MakeFromEncoded(data);
|
|
|
|
test_scale_pixels(reporter, codecImage.get(), pmRed);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageScalePixels_Gpu, reporter, ctxInfo) {
|
|
|
|
const SkPMColor pmRed = SkPackARGB32(0xFF, 0xFF, 0, 0);
|
|
|
|
const SkColor red = SK_ColorRED;
|
|
|
|
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(16, 16);
|
2020-07-06 14:56:46 +00:00
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctxInfo.directContext(),
|
|
|
|
SkBudgeted::kNo, info);
|
2017-04-26 19:28:30 +00:00
|
|
|
surface->getCanvas()->clear(red);
|
|
|
|
sk_sp<SkImage> gpuImage = surface->makeImageSnapshot();
|
|
|
|
test_scale_pixels(reporter, gpuImage.get(), pmRed);
|
|
|
|
}
|
2018-01-30 16:15:27 +00:00
|
|
|
|
|
|
|
static sk_sp<SkImage> any_image_will_do() {
|
|
|
|
return GetResourceAsImage("images/mandrill_32.png");
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Image_nonfinite_dst, reporter) {
|
|
|
|
auto surf = SkSurface::MakeRasterN32Premul(10, 10);
|
|
|
|
auto img = any_image_will_do();
|
|
|
|
|
|
|
|
for (SkScalar bad : { SK_ScalarInfinity, SK_ScalarNaN}) {
|
|
|
|
for (int bits = 1; bits <= 15; ++bits) {
|
|
|
|
SkRect dst = { 0, 0, 10, 10 };
|
|
|
|
if (bits & 1) dst.fLeft = bad;
|
|
|
|
if (bits & 2) dst.fTop = bad;
|
|
|
|
if (bits & 4) dst.fRight = bad;
|
|
|
|
if (bits & 8) dst.fBottom = bad;
|
|
|
|
|
2021-01-28 02:21:08 +00:00
|
|
|
surf->getCanvas()->drawImageRect(img, dst, SkSamplingOptions());
|
2018-01-30 16:15:27 +00:00
|
|
|
|
|
|
|
// we should draw nothing
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::PixelIter iter(surf.get());
|
2018-01-30 16:15:27 +00:00
|
|
|
while (void* addr = iter.next()) {
|
|
|
|
REPORTER_ASSERT(reporter, *(SkPMColor*)addr == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 13:35:49 +00:00
|
|
|
static sk_sp<SkImage> make_yuva_image(GrDirectContext* dContext) {
|
2019-05-10 13:22:49 +00:00
|
|
|
SkAutoPixmapStorage pm;
|
|
|
|
pm.alloc(SkImageInfo::Make(1, 1, kAlpha_8_SkColorType, kPremul_SkAlphaType));
|
2020-11-11 21:34:19 +00:00
|
|
|
SkYUVAInfo yuvaInfo({1, 1},
|
|
|
|
SkYUVAInfo::PlaneConfig::kY_U_V,
|
|
|
|
SkYUVAInfo::Subsampling::k444,
|
|
|
|
kJPEG_Full_SkYUVColorSpace);
|
2020-09-15 15:24:28 +00:00
|
|
|
const SkPixmap pmaps[] = {pm, pm, pm};
|
|
|
|
auto yuvaPixmaps = SkYUVAPixmaps::FromExternalPixmaps(yuvaInfo, pmaps);
|
|
|
|
|
|
|
|
return SkImage::MakeFromYUVAPixmaps(dContext, yuvaPixmaps);
|
2019-05-10 13:22:49 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 14:30:12 +00:00
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(ImageFlush, reporter, ctxInfo) {
|
2020-07-22 13:35:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2019-05-09 14:30:12 +00:00
|
|
|
auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2020-07-22 13:35:49 +00:00
|
|
|
auto s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes, ii, 1, nullptr);
|
2019-05-09 14:30:12 +00:00
|
|
|
|
|
|
|
s->getCanvas()->clear(SK_ColorRED);
|
|
|
|
auto i0 = s->makeImageSnapshot();
|
|
|
|
s->getCanvas()->clear(SK_ColorBLUE);
|
|
|
|
auto i1 = s->makeImageSnapshot();
|
|
|
|
s->getCanvas()->clear(SK_ColorGREEN);
|
|
|
|
// Make a YUVA image.
|
2020-07-22 13:35:49 +00:00
|
|
|
auto i2 = make_yuva_image(dContext);
|
2019-05-09 14:30:12 +00:00
|
|
|
|
|
|
|
// Flush all the setup work we did above and then make little lambda that reports the flush
|
|
|
|
// count delta since the last time it was called.
|
2020-07-22 13:35:49 +00:00
|
|
|
dContext->flushAndSubmit();
|
|
|
|
auto numSubmits =
|
|
|
|
[dContext,
|
|
|
|
submitCnt = dContext->priv().getGpu()->stats()->numSubmitToGpus()]() mutable {
|
|
|
|
int curr = dContext->priv().getGpu()->stats()->numSubmitToGpus();
|
2020-05-20 17:16:00 +00:00
|
|
|
int n = curr - submitCnt;
|
|
|
|
submitCnt = curr;
|
2019-05-09 14:30:12 +00:00
|
|
|
return n;
|
|
|
|
};
|
|
|
|
|
2020-05-20 17:16:00 +00:00
|
|
|
// Images aren't used therefore flush is ignored, but submit is still called.
|
2020-07-22 13:35:49 +00:00
|
|
|
i0->flushAndSubmit(dContext);
|
|
|
|
i1->flushAndSubmit(dContext);
|
|
|
|
i2->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 3);
|
2019-05-09 14:30:12 +00:00
|
|
|
|
|
|
|
// Syncing forces the flush to happen even if the images aren't used.
|
2020-07-22 13:35:49 +00:00
|
|
|
i0->flush(dContext);
|
|
|
|
dContext->submit(true);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2020-07-22 13:35:49 +00:00
|
|
|
i1->flush(dContext);
|
|
|
|
dContext->submit(true);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2020-07-22 13:35:49 +00:00
|
|
|
i2->flush(dContext);
|
|
|
|
dContext->submit(true);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2019-05-09 14:30:12 +00:00
|
|
|
|
|
|
|
// Use image 1
|
|
|
|
s->getCanvas()->drawImage(i1, 0, 0);
|
2020-05-20 17:16:00 +00:00
|
|
|
// Flushing image 0 should do nothing, but submit is still called.
|
2020-07-22 13:35:49 +00:00
|
|
|
i0->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2019-05-09 14:30:12 +00:00
|
|
|
// Flushing image 1 should flush.
|
2020-07-22 13:35:49 +00:00
|
|
|
i1->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
|
|
|
// Flushing image 2 should do nothing, but submit is still called.
|
2020-07-22 13:35:49 +00:00
|
|
|
i2->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2019-05-09 14:30:12 +00:00
|
|
|
|
|
|
|
// Use image 2
|
|
|
|
s->getCanvas()->drawImage(i2, 0, 0);
|
2020-05-20 17:16:00 +00:00
|
|
|
// Flushing image 0 should do nothing, but submit is still called.
|
2020-07-22 13:35:49 +00:00
|
|
|
i0->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
|
|
|
// Flushing image 1 do nothing, but submit is still called.
|
2020-07-22 13:35:49 +00:00
|
|
|
i1->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2019-05-09 14:30:12 +00:00
|
|
|
// Flushing image 2 should flush.
|
2020-07-22 13:35:49 +00:00
|
|
|
i2->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2019-05-10 13:22:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, static_cast<SkImage_GpuYUVA*>(as_IB(i2.get()))->isTextureBacked());
|
|
|
|
s->getCanvas()->drawImage(i2, 0, 0);
|
2020-05-20 17:16:00 +00:00
|
|
|
// Flushing image 0 should do nothing, but submit is still called.
|
2020-07-22 13:35:49 +00:00
|
|
|
i0->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
|
|
|
// Flushing image 1 do nothing, but submit is still called.
|
2020-07-22 13:35:49 +00:00
|
|
|
i1->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2019-05-10 13:22:49 +00:00
|
|
|
// Flushing image 2 should flush.
|
2020-07-22 13:35:49 +00:00
|
|
|
i2->flushAndSubmit(dContext);
|
2020-05-20 17:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, numSubmits() == 1);
|
2019-05-09 14:30:12 +00:00
|
|
|
}
|
2020-07-22 20:55:02 +00:00
|
|
|
|
|
|
|
#include "src/shaders/SkImageShader.h"
|
|
|
|
|
|
|
|
constexpr SkM44 gCentripetalCatmulRom
|
|
|
|
(0.0f/2, -1.0f/2, 2.0f/2, -1.0f/2,
|
|
|
|
2.0f/2, 0.0f/2, -5.0f/2, 3.0f/2,
|
|
|
|
0.0f/2, 1.0f/2, 4.0f/2, -3.0f/2,
|
|
|
|
0.0f/2, 0.0f/2, -1.0f/2, 1.0f/2);
|
|
|
|
|
|
|
|
constexpr SkM44 gMitchellNetravali
|
|
|
|
( 1.0f/18, -9.0f/18, 15.0f/18, -7.0f/18,
|
|
|
|
16.0f/18, 0.0f/18, -36.0f/18, 21.0f/18,
|
|
|
|
1.0f/18, 9.0f/18, 27.0f/18, -21.0f/18,
|
|
|
|
0.0f/18, 0.0f/18, -6.0f/18, 7.0f/18);
|
|
|
|
|
|
|
|
DEF_TEST(image_cubicresampler, reporter) {
|
|
|
|
auto diff = [reporter](const SkM44& a, const SkM44& b) {
|
|
|
|
const float tolerance = 0.000001f;
|
|
|
|
for (int r = 0; r < 4; ++r) {
|
|
|
|
for (int c = 0; c < 4; ++c) {
|
|
|
|
float d = std::abs(a.rc(r, c) - b.rc(r, c));
|
|
|
|
REPORTER_ASSERT(reporter, d <= tolerance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
diff(SkImageShader::CubicResamplerMatrix(1.0f/3, 1.0f/3), gMitchellNetravali);
|
|
|
|
|
|
|
|
diff(SkImageShader::CubicResamplerMatrix(0, 1.0f/2), gCentripetalCatmulRom);
|
|
|
|
}
|
2020-07-29 17:55:45 +00:00
|
|
|
|
|
|
|
DEF_TEST(image_subset_encode_skbug_7752, reporter) {
|
|
|
|
sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_128.png");
|
|
|
|
const int W = image->width();
|
|
|
|
const int H = image->height();
|
|
|
|
|
|
|
|
auto check_roundtrip = [&](sk_sp<SkImage> img) {
|
|
|
|
auto img2 = SkImage::MakeFromEncoded(img->encodeToData());
|
|
|
|
REPORTER_ASSERT(reporter, ToolUtils::equal_pixels(img.get(), img2.get()));
|
|
|
|
};
|
|
|
|
check_roundtrip(image); // should trivially pass
|
|
|
|
check_roundtrip(image->makeSubset({0, 0, W/2, H/2}));
|
|
|
|
check_roundtrip(image->makeSubset({W/2, H/2, W, H}));
|
|
|
|
check_roundtrip(image->makeColorSpace(SkColorSpace::MakeSRGBLinear()));
|
|
|
|
}
|