Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PipelineDataCacheTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
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 "tests/Test.h"
9
16
17using namespace skgpu::graphite;
18
19DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(PipelineDataCacheTest, reporter, context,
21 std::unique_ptr<Recorder> recorder = context->makeRecorder();
22
23 auto cache = recorder->priv().uniformDataCache();
24
25 REPORTER_ASSERT(reporter, cache->count() == 0);
26
27 static const int kSize = 16;
28
29 // Add a new unique UDB
30 static const char kMemory1[kSize] = {
31 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
32 };
33 UniformDataBlock udb1(SkSpan(kMemory1, kSize));
34 const UniformDataBlock* id1;
35 {
36 id1 = cache->insert(udb1);
38 REPORTER_ASSERT(reporter, id1 != &udb1); // must be a separate address
39 REPORTER_ASSERT(reporter, *id1 == udb1); // but equal contents
40
41 REPORTER_ASSERT(reporter, cache->count() == 1);
42 }
43
44 // Try to add a duplicate UDB
45 {
46 static const char kMemory2[kSize] = {
47 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
48 };
49 UniformDataBlock udb2(SkSpan(kMemory2, kSize));
50 const UniformDataBlock* id2 = cache->insert(udb2);
51 REPORTER_ASSERT(reporter, id2 == id1);
52
53 REPORTER_ASSERT(reporter, cache->count() == 1);
54 }
55
56 // Add a second new unique UDB
57 {
58 static const char kMemory3[kSize] = {
59 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
60 };
61 UniformDataBlock udb3(SkSpan(kMemory3, kSize));
62 const UniformDataBlock* id3 = cache->insert(udb3);
64 REPORTER_ASSERT(reporter, id3 != id1);
65 REPORTER_ASSERT(reporter, *id3 == udb3);
66
67 REPORTER_ASSERT(reporter, cache->count() == 2);
68 }
69
70 // TODO(robertphillips): expand this test to exercise all the UDB comparison failure modes
71}
reporter
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
#define DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(name, reporter, graphite_ctx, ctsEnforcement)
Definition Test.h:373
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static constexpr int kSize