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

Unified Diff: src/gpu/vk/GrVkStencilAttachment.cpp

Issue 1718693002: Add vulkan files into skia repo. (Closed) Base URL: https://skia.googlesource.com/skia.git@merge
Patch Set: fix path Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/vk/GrVkStencilAttachment.h ('k') | src/gpu/vk/GrVkTexture.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkStencilAttachment.cpp
diff --git a/src/gpu/vk/GrVkStencilAttachment.cpp b/src/gpu/vk/GrVkStencilAttachment.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0b234f2a9b458fd705ffa84a7d8bed89ca55d827
--- /dev/null
+++ b/src/gpu/vk/GrVkStencilAttachment.cpp
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrVkStencilAttachment.h"
+#include "GrVkGpu.h"
+#include "GrVkImage.h"
+#include "GrVkImageView.h"
+#include "GrVkUtil.h"
+
+#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
+
+GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu,
+ GrGpuResource::LifeCycle lifeCycle,
+ const Format& format,
+ const GrVkImage::ImageDesc& desc,
+ const GrVkImage::Resource* imageResource,
+ const GrVkImageView* stencilView)
+ : INHERITED(gpu, lifeCycle, desc.fWidth, desc.fHeight, format.fStencilBits, desc.fSamples)
+ , fFormat(format)
+ , fImageResource(imageResource)
+ , fStencilView(stencilView) {
+ this->registerWithCache();
+ imageResource->ref();
+ stencilView->ref();
+}
+
+GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu,
+ GrGpuResource::LifeCycle lifeCycle,
+ int width,
+ int height,
+ int sampleCnt,
+ const Format& format) {
+ GrVkImage::ImageDesc imageDesc;
+ imageDesc.fImageType = VK_IMAGE_TYPE_2D;
+ imageDesc.fFormat = format.fInternalFormat;
+ imageDesc.fWidth = width;
+ imageDesc.fHeight = height;
+ imageDesc.fLevels = 1;
+ imageDesc.fSamples = sampleCnt;
+ imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
+ imageDesc.fUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
+ imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
+
+ const GrVkImage::Resource* imageResource = GrVkImage::CreateResource(gpu, imageDesc);
+ if (!imageResource) {
+ return nullptr;
+ }
+
+ const GrVkImageView* imageView = GrVkImageView::Create(gpu, imageResource->fImage,
+ format.fInternalFormat,
+ GrVkImageView::kStencil_Type);
+ if (!imageView) {
+ imageResource->unref(gpu);
+ return nullptr;
+ }
+
+ GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, lifeCycle, format, imageDesc,
+ imageResource, imageView);
+ imageResource->unref(gpu);
+ imageView->unref(gpu);
+
+ return stencil;
+}
+
+GrVkStencilAttachment::~GrVkStencilAttachment() {
+ // should have been released or abandoned first
+ SkASSERT(!fImageResource);
+ SkASSERT(!fStencilView);
+}
+
+size_t GrVkStencilAttachment::onGpuMemorySize() const {
+ uint64_t size = this->width();
+ size *= this->height();
+ size *= fFormat.fTotalBits;
+ size *= SkTMax(1,this->numSamples());
+ return static_cast<size_t>(size / 8);
+}
+
+void GrVkStencilAttachment::onRelease() {
+ GrVkGpu* gpu = this->getVkGpu();
+
+ fImageResource->unref(gpu);
+ fImageResource = nullptr;
+
+ fStencilView->unref(gpu);
+ fStencilView = nullptr;
+ INHERITED::onRelease();
+}
+
+void GrVkStencilAttachment::onAbandon() {
+ fImageResource->unrefAndAbandon();
+ fImageResource = nullptr;
+ fStencilView->unrefAndAbandon();
+ fStencilView = nullptr;
+ INHERITED::onAbandon();
+}
+
+GrVkGpu* GrVkStencilAttachment::getVkGpu() const {
+ SkASSERT(!this->wasDestroyed());
+ return static_cast<GrVkGpu*>(this->getGpu());
+}
« no previous file with comments | « src/gpu/vk/GrVkStencilAttachment.h ('k') | src/gpu/vk/GrVkTexture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698