1 /*
2 * Copyright 2019 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 "src/gpu/ganesh/dawn/GrDawnAttachment.h"
9
10 #include "src/gpu/ganesh/dawn/GrDawnGpu.h"
11 #include "src/gpu/ganesh/dawn/GrDawnUtil.h"
12
13 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
14
GrDawnAttachment(GrDawnGpu * gpu,SkISize dimensions,UsageFlags supportedUsages,int samples,wgpu::Texture texture,wgpu::TextureView view,std::string_view label)15 GrDawnAttachment::GrDawnAttachment(GrDawnGpu* gpu,
16 SkISize dimensions,
17 UsageFlags supportedUsages,
18 int samples,
19 wgpu::Texture texture,
20 wgpu::TextureView view,
21 std::string_view label)
22 : INHERITED(gpu,
23 dimensions,
24 supportedUsages,
25 samples,
26 GrMipmapped::kNo,
27 GrProtected::kNo,
28 label)
29 , fTexture(texture)
30 , fView(view) {
31 this->registerWithCache(skgpu::Budgeted::kYes);
32 }
33
MakeStencil(GrDawnGpu * gpu,SkISize dimensions,int sampleCnt)34 sk_sp<GrDawnAttachment> GrDawnAttachment::MakeStencil(GrDawnGpu* gpu,
35 SkISize dimensions,
36 int sampleCnt) {
37 wgpu::TextureDescriptor desc;
38 desc.usage = wgpu::TextureUsage::RenderAttachment;
39 desc.size.width = dimensions.width();
40 desc.size.height = dimensions.height();
41 desc.size.depthOrArrayLayers = 1;
42 desc.format = wgpu::TextureFormat::Depth24PlusStencil8;
43 wgpu::Texture texture = gpu->device().CreateTexture(&desc);
44 if (!texture) {
45 return nullptr;
46 }
47 wgpu::TextureView view = texture.CreateView();
48 if (!view) {
49 return nullptr;
50 }
51 return sk_sp<GrDawnAttachment>(new GrDawnAttachment(gpu,
52 dimensions,
53 UsageFlags::kStencilAttachment,
54 sampleCnt,
55 texture,
56 view,
57 /*label=*/"DawnAttachment_MakeStencil"));
58 }
59
~GrDawnAttachment()60 GrDawnAttachment::~GrDawnAttachment() {}
61
onRelease()62 void GrDawnAttachment::onRelease() { GrAttachment::onRelease(); }
63
onAbandon()64 void GrDawnAttachment::onAbandon() { GrAttachment::onAbandon(); }
65
getDawnGpu() const66 GrDawnGpu* GrDawnAttachment::getDawnGpu() const {
67 SkASSERT(!this->wasDestroyed());
68 return static_cast<GrDawnGpu*>(this->getGpu());
69 }
70