Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
tests
DiscardableMemoryTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2013 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
8
#include "
include/core/SkRefCnt.h
"
9
#include "
include/private/chromium/SkDiscardableMemory.h
"
10
#include "
src/lazy/SkDiscardableMemoryPool.h
"
11
#include "
tests/Test.h
"
12
13
#include <cstring>
14
#include <memory>
15
16
namespace
{
17
constexpr
char
kTestString[] =
"HELLO, WORLD!"
;
18
constexpr
size_t
kTestStringLength =
sizeof
(kTestString);
19
}
// namespace
20
21
static
void
test_dm
(
skiatest::Reporter
*
reporter
,
22
SkDiscardableMemory
* dm,
23
bool
assertRelock) {
24
REPORTER_ASSERT
(
reporter
, dm);
25
if
(!dm) {
26
return
;
27
}
28
void
* ptr = dm->
data
();
29
REPORTER_ASSERT
(
reporter
, ptr);
30
if
(!ptr) {
31
return
;
32
}
33
memcpy(ptr, kTestString,
sizeof
(kTestString));
34
dm->
unlock
();
35
bool
relockSuccess = dm->
lock
();
36
if
(assertRelock) {
37
REPORTER_ASSERT
(
reporter
, relockSuccess);
38
}
39
if
(!relockSuccess) {
40
return
;
41
}
42
ptr = dm->
data
();
43
REPORTER_ASSERT
(
reporter
, ptr);
44
if
(!ptr) {
45
return
;
46
}
47
REPORTER_ASSERT
(
reporter
, 0 == memcmp(ptr, kTestString, kTestStringLength));
48
dm->
unlock
();
49
}
50
51
DEF_TEST
(DiscardableMemory_global,
reporter
) {
52
std::unique_ptr<SkDiscardableMemory> dm(
SkDiscardableMemory::Create
(kTestStringLength));
53
// lock() test is allowed to fail, since other threads could be
54
// using global pool.
55
test_dm
(
reporter
, dm.get(),
false
);
56
}
57
58
DEF_TEST
(DiscardableMemory_nonglobal,
reporter
) {
59
sk_sp<SkDiscardableMemoryPool>
pool
(
60
SkDiscardableMemoryPool::Make
(1024));
61
std::unique_ptr<SkDiscardableMemory> dm(
pool
->create(kTestStringLength));
62
test_dm
(
reporter
, dm.get(),
true
);
63
}
64
pool
AutoreleasePool pool
Definition
BazelBenchmarkTestRunner.cpp:313
test_dm
static void test_dm(skiatest::Reporter *reporter, SkDiscardableMemory *dm, bool assertRelock)
Definition
DiscardableMemoryTest.cpp:21
reporter
reporter
Definition
FontMgrTest.cpp:39
SkDiscardableMemoryPool.h
SkDiscardableMemory.h
SkRefCnt.h
Test.h
DEF_TEST
#define DEF_TEST(name, reporter)
Definition
Test.h:312
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition
Test.h:286
SkDiscardableMemoryPool::Make
static sk_sp< SkDiscardableMemoryPool > Make(size_t size)
Definition
SkDiscardableMemoryPool.cpp:233
SkDiscardableMemory
Definition
SkDiscardableMemory.h:18
SkDiscardableMemory::lock
virtual bool lock()=0
SkDiscardableMemory::unlock
virtual void unlock()=0
SkDiscardableMemory::Create
static SkDiscardableMemory * Create(size_t bytes)
Definition
SkDiscardableMemory_none.cpp:12
SkDiscardableMemory::data
virtual void * data()=0
sk_sp
Definition
SkRefCnt.h:220
skiatest::Reporter
Definition
Test.h:58
Generated on Fri Apr 26 2024 06:17:40 for Flutter Engine by
1.9.8