OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 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 "GrVkStencilAttachment.h" | |
9 #include "GrVkGpu.h" | |
10 #include "GrVkImage.h" | |
11 #include "GrVkImageView.h" | |
12 #include "GrVkUtil.h" | |
13 | |
14 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) | |
15 | |
16 GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu, | |
17 GrGpuResource::LifeCycle lifeCycle, | |
18 const Format& format, | |
19 const GrVkImage::ImageDesc& desc, | |
20 const GrVkImage::Resource* imageRes
ource, | |
21 const GrVkImageView* stencilView) | |
22 : INHERITED(gpu, lifeCycle, desc.fWidth, desc.fHeight, format.fStencilBits,
desc.fSamples) | |
23 , fFormat(format) | |
24 , fImageResource(imageResource) | |
25 , fStencilView(stencilView) { | |
26 this->registerWithCache(); | |
27 imageResource->ref(); | |
28 stencilView->ref(); | |
29 } | |
30 | |
31 GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu, | |
32 GrGpuResource::LifeCycle li
feCycle, | |
33 int width, | |
34 int height, | |
35 int sampleCnt, | |
36 const Format& format) { | |
37 GrVkImage::ImageDesc imageDesc; | |
38 imageDesc.fImageType = VK_IMAGE_TYPE_2D; | |
39 imageDesc.fFormat = format.fInternalFormat; | |
40 imageDesc.fWidth = width; | |
41 imageDesc.fHeight = height; | |
42 imageDesc.fLevels = 1; | |
43 imageDesc.fSamples = sampleCnt; | |
44 imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; | |
45 imageDesc.fUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; | |
46 imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | |
47 | |
48 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im
ageDesc); | |
49 if (!imageResource) { | |
50 return nullptr; | |
51 } | |
52 | |
53 const GrVkImageView* imageView = GrVkImageView::Create(gpu, imageResource->f
Image, | |
54 format.fInternalForma
t, | |
55 GrVkImageView::kStenc
il_Type); | |
56 if (!imageView) { | |
57 imageResource->unref(gpu); | |
58 return nullptr; | |
59 } | |
60 | |
61 GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, lifeCycle, f
ormat, imageDesc, | |
62 imageResource, im
ageView); | |
63 imageResource->unref(gpu); | |
64 imageView->unref(gpu); | |
65 | |
66 return stencil; | |
67 } | |
68 | |
69 GrVkStencilAttachment::~GrVkStencilAttachment() { | |
70 // should have been released or abandoned first | |
71 SkASSERT(!fImageResource); | |
72 SkASSERT(!fStencilView); | |
73 } | |
74 | |
75 size_t GrVkStencilAttachment::onGpuMemorySize() const { | |
76 uint64_t size = this->width(); | |
77 size *= this->height(); | |
78 size *= fFormat.fTotalBits; | |
79 size *= SkTMax(1,this->numSamples()); | |
80 return static_cast<size_t>(size / 8); | |
81 } | |
82 | |
83 void GrVkStencilAttachment::onRelease() { | |
84 GrVkGpu* gpu = this->getVkGpu(); | |
85 | |
86 fImageResource->unref(gpu); | |
87 fImageResource = nullptr; | |
88 | |
89 fStencilView->unref(gpu); | |
90 fStencilView = nullptr; | |
91 INHERITED::onRelease(); | |
92 } | |
93 | |
94 void GrVkStencilAttachment::onAbandon() { | |
95 fImageResource->unrefAndAbandon(); | |
96 fImageResource = nullptr; | |
97 fStencilView->unrefAndAbandon(); | |
98 fStencilView = nullptr; | |
99 INHERITED::onAbandon(); | |
100 } | |
101 | |
102 GrVkGpu* GrVkStencilAttachment::getVkGpu() const { | |
103 SkASSERT(!this->wasDestroyed()); | |
104 return static_cast<GrVkGpu*>(this->getGpu()); | |
105 } | |
OLD | NEW |