Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: src/gpu/vk/GrVkStencilAttachment.cpp

Issue 1862043002: Refactor to separate backend object lifecycle and GpuResource budget decision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove verbosity Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrVkStencilAttachment.h" 8 #include "GrVkStencilAttachment.h"
9 #include "GrVkGpu.h" 9 #include "GrVkGpu.h"
10 #include "GrVkImage.h" 10 #include "GrVkImage.h"
11 #include "GrVkImageView.h" 11 #include "GrVkImageView.h"
12 #include "GrVkUtil.h" 12 #include "GrVkUtil.h"
13 13
14 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) 14 #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
15 15
16 GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu, 16 GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu,
17 GrGpuResource::LifeCycle lifeCycle,
18 const Format& format, 17 const Format& format,
19 const GrVkImage::ImageDesc& desc, 18 const GrVkImage::ImageDesc& desc,
20 const GrVkImage::Resource* imageRes ource, 19 const GrVkImage::Resource* imageRes ource,
21 const GrVkImageView* stencilView) 20 const GrVkImageView* stencilView)
22 : GrStencilAttachment(gpu, lifeCycle, desc.fWidth, desc.fHeight, 21 : GrStencilAttachment(gpu, desc.fWidth, desc.fHeight,
23 format.fStencilBits, desc.fSamples) 22 format.fStencilBits, desc.fSamples)
24 , GrVkImage(imageResource) 23 , GrVkImage(imageResource)
25 , fFormat(format) 24 , fFormat(format)
26 , fStencilView(stencilView) { 25 , fStencilView(stencilView) {
27 this->registerWithCache(); 26 this->registerWithCache(SkBudgeted::kYes);
28 stencilView->ref(); 27 stencilView->ref();
29 } 28 }
30 29
31 GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu, 30 GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu,
32 GrGpuResource::LifeCycle li feCycle,
33 int width, 31 int width,
34 int height, 32 int height,
35 int sampleCnt, 33 int sampleCnt,
36 const Format& format) { 34 const Format& format) {
37 GrVkImage::ImageDesc imageDesc; 35 GrVkImage::ImageDesc imageDesc;
38 imageDesc.fImageType = VK_IMAGE_TYPE_2D; 36 imageDesc.fImageType = VK_IMAGE_TYPE_2D;
39 imageDesc.fFormat = format.fInternalFormat; 37 imageDesc.fFormat = format.fInternalFormat;
40 imageDesc.fWidth = width; 38 imageDesc.fWidth = width;
41 imageDesc.fHeight = height; 39 imageDesc.fHeight = height;
42 imageDesc.fLevels = 1; 40 imageDesc.fLevels = 1;
43 imageDesc.fSamples = sampleCnt; 41 imageDesc.fSamples = sampleCnt;
44 imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL; 42 imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
45 imageDesc.fUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; 43 imageDesc.fUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
46 imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; 44 imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
47 45
48 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im ageDesc); 46 const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, im ageDesc);
49 if (!imageResource) { 47 if (!imageResource) {
50 return nullptr; 48 return nullptr;
51 } 49 }
52 50
53 const GrVkImageView* imageView = GrVkImageView::Create(gpu, imageResource->f Image, 51 const GrVkImageView* imageView = GrVkImageView::Create(gpu, imageResource->f Image,
54 format.fInternalForma t, 52 format.fInternalForma t,
55 GrVkImageView::kStenc il_Type); 53 GrVkImageView::kStenc il_Type);
56 if (!imageView) { 54 if (!imageView) {
57 imageResource->unref(gpu); 55 imageResource->unref(gpu);
58 return nullptr; 56 return nullptr;
59 } 57 }
60 58
61 GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, lifeCycle, f ormat, imageDesc, 59 GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, format, imag eDesc,
62 imageResource, im ageView); 60 imageResource, im ageView);
63 imageResource->unref(gpu); 61 imageResource->unref(gpu);
64 imageView->unref(gpu); 62 imageView->unref(gpu);
65 63
66 return stencil; 64 return stencil;
67 } 65 }
68 66
69 GrVkStencilAttachment::~GrVkStencilAttachment() { 67 GrVkStencilAttachment::~GrVkStencilAttachment() {
70 // should have been released or abandoned first 68 // should have been released or abandoned first
71 SkASSERT(!fStencilView); 69 SkASSERT(!fStencilView);
(...skipping 21 matching lines...) Expand all
93 this->abandonImage(); 91 this->abandonImage();
94 fStencilView->unrefAndAbandon(); 92 fStencilView->unrefAndAbandon();
95 fStencilView = nullptr; 93 fStencilView = nullptr;
96 GrStencilAttachment::onAbandon(); 94 GrStencilAttachment::onAbandon();
97 } 95 }
98 96
99 GrVkGpu* GrVkStencilAttachment::getVkGpu() const { 97 GrVkGpu* GrVkStencilAttachment::getVkGpu() const {
100 SkASSERT(!this->wasDestroyed()); 98 SkASSERT(!this->wasDestroyed());
101 return static_cast<GrVkGpu*>(this->getGpu()); 99 return static_cast<GrVkGpu*>(this->getGpu());
102 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698