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/dawn/GrDawnAttachment.h"
9
10 #include "src/gpu/dawn/GrDawnGpu.h"
11 #include "src/gpu/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)15 GrDawnAttachment::GrDawnAttachment(GrDawnGpu* gpu,
16 SkISize dimensions,
17 UsageFlags supportedUsages,
18 int samples,
19 wgpu::Texture texture,
20 wgpu::TextureView view)
21 : INHERITED(gpu, dimensions, supportedUsages, samples, GrMipmapped::kNo, GrProtected::kNo)
22 , fTexture(texture)
23 , fView(view) {
24 this->registerWithCache(SkBudgeted::kYes);
25 }
26
MakeStencil(GrDawnGpu * gpu,SkISize dimensions,int sampleCnt)27 sk_sp<GrDawnAttachment> GrDawnAttachment::MakeStencil(GrDawnGpu* gpu,
28 SkISize dimensions,
29 int sampleCnt) {
30 wgpu::TextureDescriptor desc;
31 desc.usage = wgpu::TextureUsage::RenderAttachment;
32 desc.size.width = dimensions.width();
33 desc.size.height = dimensions.height();
34 desc.size.depthOrArrayLayers = 1;
35 desc.format = wgpu::TextureFormat::Depth24PlusStencil8;
36 wgpu::Texture texture = gpu->device().CreateTexture(&desc);
37 if (!texture) {
38 return nullptr;
39 }
40 wgpu::TextureView view = texture.CreateView();
41 if (!view) {
42 return nullptr;
43 }
44 return sk_sp<GrDawnAttachment>(
45 new GrDawnAttachment(gpu, dimensions, UsageFlags::kStencilAttachment, sampleCnt,
46 texture, view));
47 }
48
~GrDawnAttachment()49 GrDawnAttachment::~GrDawnAttachment() {}
50
onRelease()51 void GrDawnAttachment::onRelease() { GrAttachment::onRelease(); }
52
onAbandon()53 void GrDawnAttachment::onAbandon() { GrAttachment::onAbandon(); }
54
getDawnGpu() const55 GrDawnGpu* GrDawnAttachment::getDawnGpu() const {
56 SkASSERT(!this->wasDestroyed());
57 return static_cast<GrDawnGpu*>(this->getGpu());
58 }
59