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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkCachedData.h"
|
|
|
|
#include "SkYUVPlanesCache.h"
|
|
|
|
#include "SkResourceCache.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
SkYUVPlanesCache::Info yuvInfo;
|
2016-03-10 13:44:43 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
yuvInfo.fSizeInfo.fSizes[i].fWidth = 20 * i;
|
|
|
|
yuvInfo.fSizeInfo.fSizes[i].fHeight = 10 * i;
|
|
|
|
yuvInfo.fSizeInfo.fWidthBytes[i] = 80 * i;
|
2015-01-19 18:10:27 +00:00
|
|
|
}
|
|
|
|
yuvInfo.fColorSpace = kRec601_SkYUVColorSpace;
|
|
|
|
|
|
|
|
const uint32_t genID = 12345678;
|
|
|
|
|
|
|
|
SkCachedData* data = SkYUVPlanesCache::FindAndRef(genID, &yuvInfo, &cache);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == data);
|
2015-01-19 18:10:27 +00:00
|
|
|
|
|
|
|
size_t size = 256;
|
|
|
|
data = cache.newCachedData(size);
|
|
|
|
memset(data->writable_data(), 0xff, size);
|
|
|
|
|
|
|
|
SkYUVPlanesCache::Add(genID, data, &yuvInfo, &cache);
|
|
|
|
check_data(reporter, data, 2, kInCache, kLocked);
|
|
|
|
|
|
|
|
data->unref();
|
|
|
|
check_data(reporter, data, 1, kInCache, kUnlocked);
|
|
|
|
|
|
|
|
SkYUVPlanesCache::Info yuvInfoRead;
|
|
|
|
data = SkYUVPlanesCache::FindAndRef(genID, &yuvInfoRead, &cache);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, data);
|
|
|
|
REPORTER_ASSERT(reporter, data->size() == size);
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2016-03-10 13:44:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fSizes[i].fWidth ==
|
|
|
|
yuvInfoRead.fSizeInfo.fSizes[i].fWidth);
|
|
|
|
REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fSizes[i].fHeight ==
|
|
|
|
yuvInfoRead.fSizeInfo.fSizes[i].fHeight);
|
|
|
|
REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fWidthBytes[i] ==
|
|
|
|
yuvInfoRead.fSizeInfo.fWidthBytes[i]);
|
2015-01-19 18:10:27 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, yuvInfo.fColorSpace == yuvInfoRead.fColorSpace);
|
|
|
|
|
|
|
|
check_data(reporter, data, 2, kInCache, kLocked);
|
|
|
|
|
|
|
|
cache.purgeAll();
|
|
|
|
check_data(reporter, data, 1, kNotInCache, kLocked);
|
|
|
|
data->unref();
|
|
|
|
}
|