xref: /aosp_15_r20/external/skia/tests/graphite/CacheBudgetTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 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 
10 #include "include/gpu/graphite/Context.h"
11 #include "include/gpu/graphite/ContextOptions.h"
12 #include "include/gpu/graphite/Recorder.h"
13 
14 static constexpr size_t kContextBudget = 1234567;
15 
set_context_budget(skgpu::graphite::ContextOptions * options)16 static void set_context_budget(skgpu::graphite::ContextOptions* options) {
17     options->fGpuBudgetInBytes = kContextBudget;
18 }
19 
DEF_CONDITIONAL_GRAPHITE_TEST_FOR_CONTEXTS(CacheBudgetTest,nullptr,reporter,context,testContext,set_context_budget,true,CtsEnforcement::kApiLevel_V)20 DEF_CONDITIONAL_GRAPHITE_TEST_FOR_CONTEXTS(CacheBudgetTest,
21                                            nullptr,
22                                            reporter,
23                                            context,
24                                            testContext,
25                                            set_context_budget,
26                                            true,
27                                            CtsEnforcement::kApiLevel_V) {
28     REPORTER_ASSERT(reporter, context->maxBudgetedBytes() == kContextBudget);
29 
30     static constexpr size_t kRecorderBudget = 7654321;
31     skgpu::graphite::RecorderOptions recorderOptions;
32     recorderOptions.fGpuBudgetInBytes = kRecorderBudget;
33 
34     auto recorder = context->makeRecorder(recorderOptions);
35     if (!recorder) {
36         ERRORF(reporter, "Could not create recorder.");
37         return;
38     }
39 
40     REPORTER_ASSERT(reporter, recorder->maxBudgetedBytes() == kRecorderBudget);
41 }
42