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/GrDawnStencilAttachment.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
GrDawnStencilAttachment(GrDawnGpu * gpu,int width,int height,int bits,int samples,wgpu::Texture texture,wgpu::TextureView view)15 GrDawnStencilAttachment::GrDawnStencilAttachment(GrDawnGpu* gpu,
16 int width,
17 int height,
18 int bits,
19 int samples,
20 wgpu::Texture texture,
21 wgpu::TextureView view)
22 : INHERITED(gpu, width, height, bits, samples)
23 , fTexture(texture)
24 , fView(view) {
25 this->registerWithCache(SkBudgeted::kYes);
26 }
27
Create(GrDawnGpu * gpu,int width,int height,int sampleCnt)28 GrDawnStencilAttachment* GrDawnStencilAttachment::Create(GrDawnGpu* gpu,
29 int width,
30 int height,
31 int sampleCnt) {
32 wgpu::TextureDescriptor desc;
33 desc.usage = wgpu::TextureUsage::OutputAttachment;
34 desc.size.width = width;
35 desc.size.height = height;
36 desc.size.depth = 1;
37 desc.format = wgpu::TextureFormat::Depth24PlusStencil8;
38 wgpu::Texture texture = gpu->device().CreateTexture(&desc);
39 if (!texture) {
40 return nullptr;
41 }
42 wgpu::TextureView view = texture.CreateView();
43 if (!view) {
44 return nullptr;
45 }
46 return new GrDawnStencilAttachment(gpu, width, height, 8, sampleCnt, texture, view);
47 }
48
~GrDawnStencilAttachment()49 GrDawnStencilAttachment::~GrDawnStencilAttachment() {
50 }
51
onGpuMemorySize() const52 size_t GrDawnStencilAttachment::onGpuMemorySize() const {
53 uint64_t size = this->width();
54 size *= this->height();
55 size *= 32;
56 size *= std::max(1,this->numSamples());
57 return static_cast<size_t>(size / 8);
58 }
59
onRelease()60 void GrDawnStencilAttachment::onRelease() {
61 GrStencilAttachment::onRelease();
62 }
63
onAbandon()64 void GrDawnStencilAttachment::onAbandon() {
65 GrStencilAttachment::onAbandon();
66 }
67
getDawnGpu() const68 GrDawnGpu* GrDawnStencilAttachment::getDawnGpu() const {
69 SkASSERT(!this->wasDestroyed());
70 return static_cast<GrDawnGpu*>(this->getGpu());
71 }
72