Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DawnBackendTextureTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
14
15#include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
16
17using namespace skgpu::graphite;
18
19namespace {
20const SkISize kSize = {16, 16};
21}
22
23DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureSimpleCreationTest,
25 context,
26 testContext) {
27 auto recorder = context->makeRecorder();
28
29 DawnTextureInfo textureInfo;
30 textureInfo.fSampleCount = 1;
31 textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
32 textureInfo.fFormat = wgpu::TextureFormat::RGBA8Unorm;
33 textureInfo.fUsage = wgpu::TextureUsage::TextureBinding;
34
35 auto beTexture = recorder->createBackendTexture(kSize, textureInfo);
36 REPORTER_ASSERT(reporter, beTexture.isValid());
37 recorder->deleteBackendTexture(beTexture);
38
39 // It should also pass if we set the usage to be a render target
40 textureInfo.fUsage |= wgpu::TextureUsage::RenderAttachment;
41 beTexture = recorder->createBackendTexture(kSize, textureInfo);
42 REPORTER_ASSERT(reporter, beTexture.isValid());
43 recorder->deleteBackendTexture(beTexture);
44}
45
46// Test that copying BackendTexture variables works.
47DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureCopyVariableTest,
49 context,
50 testContext) {
51 auto recorder = context->makeRecorder();
52
53 DawnTextureInfo textureInfo;
54 textureInfo.fSampleCount = 1;
55 textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
56 textureInfo.fFormat = wgpu::TextureFormat::RGBA8Unorm;
57 textureInfo.fUsage = wgpu::TextureUsage::TextureBinding;
58
59 BackendTexture beTexture = recorder->createBackendTexture(kSize, textureInfo);
60 REPORTER_ASSERT(reporter, beTexture.isValid());
61
62 BackendTexture beTexture2;
63 REPORTER_ASSERT(reporter, beTexture2 != beTexture);
64 REPORTER_ASSERT(reporter, beTexture2.getDawnTexturePtr() == nullptr);
65 REPORTER_ASSERT(reporter, beTexture2.getDawnTextureViewPtr() == nullptr);
66
67 beTexture2 = beTexture;
68 REPORTER_ASSERT(reporter, beTexture2 == beTexture);
69 REPORTER_ASSERT(reporter, beTexture2.getDawnTexturePtr() != nullptr);
70 REPORTER_ASSERT(reporter, beTexture2.getDawnTexturePtr() == beTexture.getDawnTexturePtr());
71
72 recorder->deleteBackendTexture(beTexture);
73}
reporter
#define DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(name, reporter, graphite_context, test_context)
Definition Test.h:389
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static constexpr int kSize
wgpu::TextureFormat fFormat
Definition DawnTypes.h:21
wgpu::TextureUsage fUsage
Definition DawnTypes.h:24