2015-01-19 18:10:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-10-19 17:31:49 +00:00
|
|
|
#include "include/core/SkYUVAInfo.h"
|
|
|
|
#include "include/core/SkYUVAPixmaps.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkCachedData.h"
|
|
|
|
#include "src/core/SkResourceCache.h"
|
|
|
|
#include "src/core/SkYUVPlanesCache.h"
|
|
|
|
#include "tests/Test.h"
|
2015-01-19 18:10:27 +00:00
|
|
|
|
|
|
|
enum LockedState {
|
|
|
|
kUnlocked,
|
|
|
|
kLocked,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CachedState {
|
|
|
|
kNotInCache,
|
|
|
|
kInCache,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void check_data(skiatest::Reporter* reporter, SkCachedData* data,
|
|
|
|
int refcnt, CachedState cacheState, LockedState lockedState) {
|
|
|
|
REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
|
|
|
|
REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cacheState));
|
2015-08-27 14:41:13 +00:00
|
|
|
bool isLocked = (data->data() != nullptr);
|
2015-01-19 18:10:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked));
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(YUVPlanesCache, reporter) {
|
|
|
|
SkResourceCache cache(1024);
|
|
|
|
|
2020-10-19 17:31:49 +00:00
|
|
|
SkYUVAInfo yuvaInfo({5, 5},
|
2020-11-11 21:34:19 +00:00
|
|
|
SkYUVAInfo::PlaneConfig::kY_U_V,
|
|
|
|
SkYUVAInfo::Subsampling::k420,
|
2020-10-19 17:31:49 +00:00
|
|
|
kRec601_Limited_SkYUVColorSpace);
|
|
|
|
SkYUVAPixmapInfo yuvaPixmapInfo(yuvaInfo,
|
|
|
|
SkYUVAPixmapInfo::DataType::kUnorm8,
|
|
|
|
/*rowBytes[]*/ nullptr);
|
|
|
|
SkYUVAPixmaps yuvaPixmaps;
|
2015-01-19 18:10:27 +00:00
|
|
|
const uint32_t genID = 12345678;
|
|
|
|
|
2020-10-19 17:31:49 +00:00
|
|
|
SkCachedData* data = SkYUVPlanesCache::FindAndRef(genID, &yuvaPixmaps, &cache);
|
|
|
|
REPORTER_ASSERT(reporter, !data);
|
2015-01-19 18:10:27 +00:00
|
|
|
|
2020-10-19 17:31:49 +00:00
|
|
|
size_t size = yuvaPixmapInfo.computeTotalBytes();
|
2015-01-19 18:10:27 +00:00
|
|
|
data = cache.newCachedData(size);
|
|
|
|
memset(data->writable_data(), 0xff, size);
|
|
|
|
|
2020-10-19 17:31:49 +00:00
|
|
|
SkPixmap pmaps[SkYUVAInfo::kMaxPlanes];
|
|
|
|
yuvaPixmapInfo.initPixmapsFromSingleAllocation(data->writable_data(), pmaps);
|
|
|
|
yuvaPixmaps = SkYUVAPixmaps::FromExternalPixmaps(yuvaInfo, pmaps);
|
|
|
|
|
|
|
|
SkYUVPlanesCache::Add(genID, data, yuvaPixmaps, &cache);
|
2015-01-19 18:10:27 +00:00
|
|
|
check_data(reporter, data, 2, kInCache, kLocked);
|
|
|
|
|
|
|
|
data->unref();
|
|
|
|
check_data(reporter, data, 1, kInCache, kUnlocked);
|
|
|
|
|
2020-10-19 17:31:49 +00:00
|
|
|
SkYUVAPixmaps yuvaPixmapsRead;
|
|
|
|
data = SkYUVPlanesCache::FindAndRef(genID, &yuvaPixmapsRead, &cache);
|
2015-01-19 18:10:27 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, data);
|
|
|
|
REPORTER_ASSERT(reporter, data->size() == size);
|
2020-10-19 17:31:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, yuvaPixmapsRead.yuvaInfo() == yuvaPixmaps.yuvaInfo());
|
2018-10-18 18:36:59 +00:00
|
|
|
|
2020-10-19 17:31:49 +00:00
|
|
|
for (int i = 0; i < yuvaPixmaps.numPlanes(); ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, yuvaPixmaps.plane(i).info() == yuvaPixmapsRead.plane(i).info());
|
|
|
|
REPORTER_ASSERT(reporter, yuvaPixmaps.plane(i).addr() == yuvaPixmapsRead.plane(i).addr());
|
|
|
|
REPORTER_ASSERT(reporter, yuvaPixmaps.plane(i).rowBytes() ==
|
|
|
|
yuvaPixmapsRead.plane(i).rowBytes());
|
2015-01-19 18:10:27 +00:00
|
|
|
}
|
2018-10-18 18:36:59 +00:00
|
|
|
|
2015-01-19 18:10:27 +00:00
|
|
|
check_data(reporter, data, 2, kInCache, kLocked);
|
|
|
|
|
|
|
|
cache.purgeAll();
|
|
|
|
check_data(reporter, data, 1, kNotInCache, kLocked);
|
|
|
|
data->unref();
|
|
|
|
}
|