Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
YUVCacheTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
15#include "tests/Test.h"
16
17#include <cstdint>
18#include <cstring>
19
24
29
31 int refcnt, CachedState cacheState, LockedState lockedState) {
32 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
33 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cacheState));
34 bool isLocked = (data->data() != nullptr);
35 REPORTER_ASSERT(reporter, isLocked == (lockedState == kLocked));
36}
37
38DEF_TEST(YUVPlanesCache, reporter) {
39 SkResourceCache cache(1024);
40
41 SkYUVAInfo yuvaInfo({5, 5},
45 SkYUVAPixmapInfo yuvaPixmapInfo(yuvaInfo,
47 /*rowBytes[]*/ nullptr);
48 SkYUVAPixmaps yuvaPixmaps;
49 const uint32_t genID = 12345678;
50
51 SkCachedData* data = SkYUVPlanesCache::FindAndRef(genID, &yuvaPixmaps, &cache);
53
54 size_t size = yuvaPixmapInfo.computeTotalBytes();
55 data = cache.newCachedData(size);
56 memset(data->writable_data(), 0xff, size);
57
59 yuvaPixmapInfo.initPixmapsFromSingleAllocation(data->writable_data(), pmaps);
60 yuvaPixmaps = SkYUVAPixmaps::FromExternalPixmaps(yuvaInfo, pmaps);
61
62 SkYUVPlanesCache::Add(genID, data, yuvaPixmaps, &cache);
64
65 data->unref();
67
68 SkYUVAPixmaps yuvaPixmapsRead;
69 data = SkYUVPlanesCache::FindAndRef(genID, &yuvaPixmapsRead, &cache);
70
72 REPORTER_ASSERT(reporter, data->size() == size);
73 REPORTER_ASSERT(reporter, yuvaPixmapsRead.yuvaInfo() == yuvaPixmaps.yuvaInfo());
74
75 for (int i = 0; i < yuvaPixmaps.numPlanes(); ++i) {
76 REPORTER_ASSERT(reporter, yuvaPixmaps.plane(i).info() == yuvaPixmapsRead.plane(i).info());
77 REPORTER_ASSERT(reporter, yuvaPixmaps.plane(i).addr() == yuvaPixmapsRead.plane(i).addr());
78 REPORTER_ASSERT(reporter, yuvaPixmaps.plane(i).rowBytes() ==
79 yuvaPixmapsRead.plane(i).rowBytes());
80 }
81
83
84 cache.purgeAll();
86 data->unref();
87}
CachedState
LockedState
reporter
@ kRec601_Limited_SkYUVColorSpace
describes SDTV range
Definition SkImageInfo.h:70
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static void check_data(skiatest::Reporter *reporter, SkCachedData *data, int refcnt, CachedState cacheState, LockedState lockedState)
@ kInCache
@ kNotInCache
@ kUnlocked
@ kLocked
size_t rowBytes() const
Definition SkPixmap.h:145
const SkImageInfo & info() const
Definition SkPixmap.h:135
const void * addr() const
Definition SkPixmap.h:153
@ kY_U_V
Plane 0: Y, Plane 1: U, Plane 2: V.
static constexpr int kMaxPlanes
Definition SkYUVAInfo.h:98
@ k420
1 set of UV values for each 2x2 block of Y values.
@ kUnorm8
8 bit unsigned normalized
const SkYUVAInfo & yuvaInfo() const
const SkPixmap & plane(int i) const
static SkYUVAPixmaps FromExternalPixmaps(const SkYUVAInfo &, const SkPixmap[kMaxPlanes])
int numPlanes() const
static void Add(uint32_t genID, SkCachedData *data, const SkYUVAPixmaps &pixmaps, SkResourceCache *localCache=nullptr)
static SkCachedData * FindAndRef(uint32_t genID, SkYUVAPixmaps *pixmaps, SkResourceCache *localCache=nullptr)