Flutter Engine
The Flutter Engine
CachedDataTest.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
13#include "tests/Test.h"
14
15#include <cstring>
16
18
22};
23
27};
28
30 int refcnt, CachedState cacheState, LockedState lockedState) {
31 REPORTER_ASSERT(reporter, data->testing_only_getRefCnt() == refcnt);
32 REPORTER_ASSERT(reporter, data->testing_only_isInCache() == (kInCache == cacheState));
33 REPORTER_ASSERT(reporter, data->testing_only_isLocked() == (lockedState == kLocked));
34}
35
37 if (pool) {
38 SkDiscardableMemory* dm = pool->create(size);
39 // the pool "can" return null, but it shouldn't in these controlled conditions
41 return new SkCachedData(size, dm);
42 } else {
44 }
45}
46
47// returns with the data locked by client and cache
51
52 memset(data->writable_data(), 0x80, size); // just to use writable_data()
53
55
56 data->ref();
58 data->unref();
60
61 data->attachToCacheAndRef();
63
64 data->unref();
66
67 data->ref();
69
70 return data;
71}
72
73/*
74 * SkCachedData behaves differently (regarding its locked/unlocked state) depending on
75 * when it is in the cache or not. Being in the cache is signaled by calling attachToCacheAndRef()
76 * instead of ref(). (and balanced by detachFromCacheAndUnref).
77 *
78 * Thus, among other things, we test the end-of-life behavior when the client is the last owner
79 * and when the cache is.
80 */
81DEF_TEST(CachedData, reporter) {
83
84 for (int useDiscardable = 0; useDiscardable <= 1; ++useDiscardable) {
85 const size_t size = 100;
86
87 // test with client as last owner
88 SkCachedData* data = test_locking(reporter, size, useDiscardable ? pool.get() : nullptr);
90 data->detachFromCacheAndUnref();
92 data->unref();
93
94 // test with cache as last owner
95 data = test_locking(reporter, size, useDiscardable ? pool.get() : nullptr);
97 data->unref();
99 data->detachFromCacheAndUnref();
100 }
101}
AutoreleasePool pool
static void check_data(skiatest::Reporter *reporter, SkCachedData *data, int refcnt, CachedState cacheState, LockedState lockedState)
static SkCachedData * make_data(size_t size, SkDiscardableMemoryPool *pool)
DEF_TEST(CachedData, reporter)
CachedState
@ kInCache
@ kNotInCache
LockedState
@ kUnlocked
@ kLocked
static SkCachedData * test_locking(skiatest::Reporter *reporter, size_t size, SkDiscardableMemoryPool *pool)
reporter
Definition: FontMgrTest.cpp:39
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
static void * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static sk_sp< SkDiscardableMemoryPool > Make(size_t size)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63