2013-10-29 19:55:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkData.h"
|
2013-11-21 15:32:08 +00:00
|
|
|
#include "SkDecodingImageGenerator.h"
|
2013-12-05 18:31:42 +00:00
|
|
|
#include "SkDiscardableMemoryPool.h"
|
2013-10-29 19:55:00 +00:00
|
|
|
#include "SkImageDecoder.h"
|
2013-12-05 14:00:03 +00:00
|
|
|
#include "SkCachingPixelRef.h"
|
2013-10-29 19:55:00 +00:00
|
|
|
#include "SkScaledImageCache.h"
|
|
|
|
#include "SkStream.h"
|
2013-12-05 18:31:42 +00:00
|
|
|
#include "SkUtils.h"
|
2013-11-06 10:08:30 +00:00
|
|
|
|
2013-10-29 19:55:00 +00:00
|
|
|
#include "Test.h"
|
2013-11-06 10:08:30 +00:00
|
|
|
#include "TestClassDef.h"
|
2013-10-29 19:55:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill this bitmap with some color.
|
|
|
|
*/
|
|
|
|
static void make_test_image(SkBitmap* bm) {
|
|
|
|
static const int W = 50, H = 50;
|
|
|
|
static const SkBitmap::Config config = SkBitmap::kARGB_8888_Config;
|
|
|
|
bm->setConfig(config, W, H);
|
|
|
|
bm->allocPixels();
|
|
|
|
bm->eraseColor(SK_ColorBLACK);
|
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas.drawRectCoords(0, 0, SkIntToScalar(W/2),
|
|
|
|
SkIntToScalar(H/2), paint);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas.drawRectCoords(SkIntToScalar(W/2), SkIntToScalar(H/2),
|
|
|
|
SkIntToScalar(W), SkIntToScalar(H), paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* encode this bitmap into some data via SkImageEncoder
|
|
|
|
*/
|
|
|
|
static SkData* create_data_from_bitmap(const SkBitmap& bm,
|
|
|
|
SkImageEncoder::Type type) {
|
|
|
|
SkDynamicMemoryWStream stream;
|
|
|
|
if (SkImageEncoder::EncodeStream(&stream, bm, type, 100)) {
|
|
|
|
return stream.copyToData();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-12-05 18:31:42 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-10-29 19:55:00 +00:00
|
|
|
|
|
|
|
static void compare_bitmaps(skiatest::Reporter* reporter,
|
|
|
|
const SkBitmap& b1, const SkBitmap& b2,
|
|
|
|
bool pixelPerfect = true) {
|
|
|
|
REPORTER_ASSERT(reporter, b1.empty() == b2.empty());
|
|
|
|
REPORTER_ASSERT(reporter, b1.width() == b2.width());
|
|
|
|
REPORTER_ASSERT(reporter, b1.height() == b2.height());
|
|
|
|
REPORTER_ASSERT(reporter, b1.isNull() == b2.isNull());
|
|
|
|
SkAutoLockPixels autoLockPixels1(b1);
|
|
|
|
SkAutoLockPixels autoLockPixels2(b2);
|
|
|
|
REPORTER_ASSERT(reporter, b1.isNull() == b2.isNull());
|
|
|
|
if (b1.isNull() || b1.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, NULL != b1.getPixels());
|
|
|
|
REPORTER_ASSERT(reporter, NULL != b2.getPixels());
|
|
|
|
if ((!(b1.getPixels())) || (!(b2.getPixels()))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((b1.width() != b2.width()) ||
|
|
|
|
(b1.height() != b2.height())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!pixelPerfect) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-06 10:08:30 +00:00
|
|
|
|
2013-10-29 19:55:00 +00:00
|
|
|
int pixelErrors = 0;
|
|
|
|
for (int y = 0; y < b2.height(); ++y) {
|
|
|
|
for (int x = 0; x < b2.width(); ++x) {
|
|
|
|
if (b1.getColor(x, y) != b2.getColor(x, y)) {
|
|
|
|
++pixelErrors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, 0 == pixelErrors);
|
|
|
|
}
|
|
|
|
|
2013-12-05 14:00:03 +00:00
|
|
|
typedef bool (*InstallEncoded)(SkData* encoded, SkBitmap* dst);
|
|
|
|
|
2013-10-29 19:55:00 +00:00
|
|
|
/**
|
2013-12-05 14:00:03 +00:00
|
|
|
This function tests three differently encoded images against the
|
|
|
|
original bitmap */
|
2013-11-06 10:08:30 +00:00
|
|
|
static void test_three_encodings(skiatest::Reporter* reporter,
|
2013-12-05 14:00:03 +00:00
|
|
|
InstallEncoded install) {
|
2013-10-29 19:55:00 +00:00
|
|
|
SkBitmap original;
|
|
|
|
make_test_image(&original);
|
2013-11-06 10:08:30 +00:00
|
|
|
REPORTER_ASSERT(reporter, !original.empty());
|
|
|
|
REPORTER_ASSERT(reporter, !original.isNull());
|
|
|
|
if (original.empty() || original.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-29 19:55:00 +00:00
|
|
|
static const SkImageEncoder::Type types[] = {
|
|
|
|
SkImageEncoder::kPNG_Type,
|
|
|
|
SkImageEncoder::kJPEG_Type,
|
|
|
|
SkImageEncoder::kWEBP_Type
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(types); i++) {
|
|
|
|
SkImageEncoder::Type type = types[i];
|
|
|
|
SkAutoDataUnref encoded(create_data_from_bitmap(original, type));
|
|
|
|
REPORTER_ASSERT(reporter, encoded.get() != NULL);
|
2013-12-05 14:00:03 +00:00
|
|
|
if (NULL == encoded.get()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkBitmap lazy;
|
|
|
|
bool installSuccess = install(encoded.get(), &lazy);
|
|
|
|
REPORTER_ASSERT(reporter, installSuccess);
|
|
|
|
if (!installSuccess) {
|
|
|
|
continue;
|
2013-10-29 19:55:00 +00:00
|
|
|
}
|
2013-12-05 14:00:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
|
|
|
|
{
|
|
|
|
SkAutoLockPixels autoLockPixels(lazy); // now pixels are good.
|
|
|
|
REPORTER_ASSERT(reporter, NULL != lazy.getPixels());
|
|
|
|
if (NULL == lazy.getPixels()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// pixels should be gone!
|
|
|
|
REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
|
|
|
|
{
|
|
|
|
SkAutoLockPixels autoLockPixels(lazy); // now pixels are good.
|
|
|
|
REPORTER_ASSERT(reporter, NULL != lazy.getPixels());
|
|
|
|
if (NULL == lazy.getPixels()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool comparePixels = (SkImageEncoder::kPNG_Type == type);
|
|
|
|
compare_bitmaps(reporter, original, lazy, comparePixels);
|
2013-11-06 10:08:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-29 19:55:00 +00:00
|
|
|
|
2013-12-05 14:00:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-12-05 18:31:42 +00:00
|
|
|
static bool install_skCachingPixelRef(SkData* encoded, SkBitmap* dst) {
|
|
|
|
return SkCachingPixelRef::Install(
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
SkDecodingImageGenerator::Create(
|
|
|
|
encoded, SkDecodingImageGenerator::Options()), dst);
|
2013-11-06 10:08:30 +00:00
|
|
|
}
|
2013-12-05 18:31:42 +00:00
|
|
|
static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) {
|
|
|
|
// Use system-default discardable memory.
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
return SkInstallDiscardablePixelRef(
|
|
|
|
SkDecodingImageGenerator::Create(
|
|
|
|
encoded, SkDecodingImageGenerator::Options()), dst, NULL);
|
2013-11-06 10:08:30 +00:00
|
|
|
}
|
2013-10-29 19:55:00 +00:00
|
|
|
|
2013-12-05 14:00:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-11-06 10:08:30 +00:00
|
|
|
/**
|
2013-12-05 18:31:42 +00:00
|
|
|
* This checks to see that a SkCachingPixelRef and a
|
|
|
|
* SkDiscardablePixelRef works as advertised with a
|
|
|
|
* SkDecodingImageGenerator.
|
2013-11-06 10:08:30 +00:00
|
|
|
*/
|
2013-12-05 18:31:42 +00:00
|
|
|
DEF_TEST(DecodingImageGenerator, reporter) {
|
2013-12-05 14:00:03 +00:00
|
|
|
test_three_encodings(reporter, install_skCachingPixelRef);
|
2013-12-05 18:31:42 +00:00
|
|
|
test_three_encodings(reporter, install_skDiscardablePixelRef);
|
2013-10-29 19:55:00 +00:00
|
|
|
}
|
2013-11-21 15:32:08 +00:00
|
|
|
|
2013-12-05 14:00:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-12-05 18:31:42 +00:00
|
|
|
namespace {
|
|
|
|
class TestImageGenerator : public SkImageGenerator {
|
|
|
|
public:
|
|
|
|
enum TestType {
|
|
|
|
kFailGetInfo_TestType,
|
|
|
|
kFailGetPixels_TestType,
|
|
|
|
kSucceedGetPixels_TestType,
|
|
|
|
kLast_TestType = kSucceedGetPixels_TestType
|
|
|
|
};
|
|
|
|
static int Width() { return 10; }
|
|
|
|
static int Height() { return 10; }
|
|
|
|
static SkColor Color() { return SK_ColorCYAN; }
|
|
|
|
TestImageGenerator(TestType type, skiatest::Reporter* reporter)
|
|
|
|
: fType(type), fReporter(reporter) {
|
|
|
|
SkASSERT((fType <= kLast_TestType) && (fType >= 0));
|
|
|
|
}
|
|
|
|
~TestImageGenerator() { }
|
|
|
|
bool getInfo(SkImageInfo* info) SK_OVERRIDE {
|
|
|
|
REPORTER_ASSERT(fReporter, NULL != info);
|
|
|
|
if ((NULL == info) || (kFailGetInfo_TestType == fType)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
info->fWidth = TestImageGenerator::Width();
|
|
|
|
info->fHeight = TestImageGenerator::Height();
|
|
|
|
info->fColorType = kPMColor_SkColorType;
|
|
|
|
info->fAlphaType = kOpaque_SkAlphaType;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool getPixels(const SkImageInfo& info,
|
|
|
|
void* pixels,
|
|
|
|
size_t rowBytes) SK_OVERRIDE {
|
|
|
|
REPORTER_ASSERT(fReporter, pixels != NULL);
|
|
|
|
size_t minRowBytes
|
|
|
|
= static_cast<size_t>(info.fWidth * info.bytesPerPixel());
|
|
|
|
REPORTER_ASSERT(fReporter, rowBytes >= minRowBytes);
|
|
|
|
if ((NULL == pixels)
|
|
|
|
|| (fType != kSucceedGetPixels_TestType)
|
|
|
|
|| (info.fColorType != kPMColor_SkColorType)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
char* bytePtr = static_cast<char*>(pixels);
|
|
|
|
for (int y = 0; y < info.fHeight; ++y) {
|
|
|
|
sk_memset32(reinterpret_cast<SkColor*>(bytePtr),
|
|
|
|
TestImageGenerator::Color(), info.fWidth);
|
|
|
|
bytePtr += rowBytes;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
|
2013-12-05 18:31:42 +00:00
|
|
|
private:
|
|
|
|
const TestType fType;
|
|
|
|
skiatest::Reporter* const fReporter;
|
|
|
|
};
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
|
2013-12-05 18:31:42 +00:00
|
|
|
void CheckTestImageGeneratorBitmap(skiatest::Reporter* reporter,
|
|
|
|
const SkBitmap& bm) {
|
|
|
|
REPORTER_ASSERT(reporter, TestImageGenerator::Width() == bm.width());
|
|
|
|
REPORTER_ASSERT(reporter, TestImageGenerator::Height() == bm.height());
|
|
|
|
SkAutoLockPixels autoLockPixels(bm);
|
|
|
|
REPORTER_ASSERT(reporter, NULL != bm.getPixels());
|
|
|
|
if (NULL == bm.getPixels()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int errors = 0;
|
|
|
|
for (int y = 0; y < bm.height(); ++y) {
|
|
|
|
for (int x = 0; x < bm.width(); ++x) {
|
|
|
|
if (TestImageGenerator::Color() != *bm.getAddr32(x, y)) {
|
|
|
|
++errors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, 0 == errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum PixelRefType {
|
|
|
|
kSkCaching_PixelRefType,
|
|
|
|
kSkDiscardable_PixelRefType,
|
|
|
|
kLast_PixelRefType = kSkDiscardable_PixelRefType
|
|
|
|
};
|
|
|
|
void CheckPixelRef(TestImageGenerator::TestType type,
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
PixelRefType pixelRefType,
|
|
|
|
SkDiscardableMemory::Factory* factory) {
|
|
|
|
SkASSERT((pixelRefType >= 0) && (pixelRefType <= kLast_PixelRefType));
|
|
|
|
SkAutoTDelete<SkImageGenerator> gen(SkNEW_ARGS(TestImageGenerator,
|
|
|
|
(type, reporter)));
|
|
|
|
REPORTER_ASSERT(reporter, gen.get() != NULL);
|
|
|
|
SkBitmap lazy;
|
|
|
|
bool success;
|
|
|
|
if (kSkCaching_PixelRefType == pixelRefType) {
|
|
|
|
// Ignore factory; use global SkScaledImageCache.
|
|
|
|
success = SkCachingPixelRef::Install(gen.detach(), &lazy);
|
|
|
|
} else {
|
2013-12-10 21:11:12 +00:00
|
|
|
success = SkInstallDiscardablePixelRef(gen.detach(), &lazy, factory);
|
2013-12-05 18:31:42 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, success
|
|
|
|
== (TestImageGenerator::kFailGetInfo_TestType != type));
|
|
|
|
if (TestImageGenerator::kSucceedGetPixels_TestType == type) {
|
|
|
|
CheckTestImageGeneratorBitmap(reporter, lazy);
|
|
|
|
} else if (TestImageGenerator::kFailGetPixels_TestType == type) {
|
|
|
|
SkAutoLockPixels autoLockPixels(lazy);
|
|
|
|
REPORTER_ASSERT(reporter, NULL == lazy.getPixels());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
2013-12-12 22:37:32 +00:00
|
|
|
|
|
|
|
// new/lock/delete is an odd pattern for a pixelref, but it needs to not assert
|
|
|
|
static void test_newlockdelete(skiatest::Reporter* reporter) {
|
|
|
|
SkBitmap bm;
|
|
|
|
SkImageGenerator* ig = new TestImageGenerator(
|
|
|
|
TestImageGenerator::kSucceedGetPixels_TestType,
|
|
|
|
reporter);
|
|
|
|
SkInstallDiscardablePixelRef(ig, &bm, NULL);
|
|
|
|
bm.pixelRef()->lockPixels();
|
|
|
|
}
|
|
|
|
|
2013-12-05 14:00:03 +00:00
|
|
|
/**
|
2013-12-05 18:31:42 +00:00
|
|
|
* This tests the basic functionality of SkDiscardablePixelRef with a
|
|
|
|
* basic SkImageGenerator implementation and several
|
|
|
|
* SkDiscardableMemory::Factory choices.
|
2013-12-05 14:00:03 +00:00
|
|
|
*/
|
2013-12-05 18:31:42 +00:00
|
|
|
DEF_TEST(DiscardableAndCachingPixelRef, reporter) {
|
2013-12-12 22:37:32 +00:00
|
|
|
test_newlockdelete(reporter);
|
|
|
|
|
2013-12-05 18:31:42 +00:00
|
|
|
CheckPixelRef(TestImageGenerator::kFailGetInfo_TestType,
|
|
|
|
reporter, kSkCaching_PixelRefType, NULL);
|
|
|
|
CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType,
|
|
|
|
reporter, kSkCaching_PixelRefType, NULL);
|
|
|
|
CheckPixelRef(TestImageGenerator::kSucceedGetPixels_TestType,
|
|
|
|
reporter, kSkCaching_PixelRefType, NULL);
|
|
|
|
|
|
|
|
CheckPixelRef(TestImageGenerator::kFailGetInfo_TestType,
|
|
|
|
reporter, kSkDiscardable_PixelRefType, NULL);
|
|
|
|
CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType,
|
|
|
|
reporter, kSkDiscardable_PixelRefType, NULL);
|
|
|
|
CheckPixelRef(TestImageGenerator::kSucceedGetPixels_TestType,
|
|
|
|
reporter, kSkDiscardable_PixelRefType, NULL);
|
|
|
|
|
|
|
|
SkAutoTUnref<SkDiscardableMemoryPool> pool(
|
|
|
|
SkNEW_ARGS(SkDiscardableMemoryPool, (1, NULL)));
|
|
|
|
REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
|
|
|
|
CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType,
|
|
|
|
reporter, kSkDiscardable_PixelRefType, pool);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
|
|
|
|
CheckPixelRef(TestImageGenerator::kSucceedGetPixels_TestType,
|
|
|
|
reporter, kSkDiscardable_PixelRefType, pool);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
|
|
|
|
|
|
|
|
SkDiscardableMemoryPool* globalPool = SkGetGlobalDiscardableMemoryPool();
|
2013-12-10 18:33:07 +00:00
|
|
|
// Only acts differently from NULL on a platform that has a
|
|
|
|
// default discardable memory implementation that differs from the
|
|
|
|
// global DM pool.
|
2013-12-05 18:31:42 +00:00
|
|
|
CheckPixelRef(TestImageGenerator::kFailGetPixels_TestType,
|
|
|
|
reporter, kSkDiscardable_PixelRefType, globalPool);
|
|
|
|
CheckPixelRef(TestImageGenerator::kSucceedGetPixels_TestType,
|
|
|
|
reporter, kSkDiscardable_PixelRefType, globalPool);
|
2013-11-21 15:32:08 +00:00
|
|
|
}
|
2013-12-05 18:31:42 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|