diff options
author | 2016-05-20 06:01:06 -0700 | |
---|---|---|
committer | 2016-05-20 06:01:06 -0700 | |
commit | af236b5aa9e7d71d59bee6533d16deb76e9d098b (patch) | |
tree | f7eadc814062f1fc91325428c3ec604db64574a1 /tools/viewer/sk_app/VulkanWindowContext.cpp | |
parent | d88b0bec43fdd6ef2f32c6e5a3e834d708ce76a7 (diff) |
Add OpenGL context to Viewer.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1978573003
Committed: https://skia.googlesource.com/skia/+/56a11e4d6f3d436a3c2497c9c9e71a117d78a93f
Review-Url: https://codereview.chromium.org/1978573003
Diffstat (limited to 'tools/viewer/sk_app/VulkanWindowContext.cpp')
-rw-r--r-- | tools/viewer/sk_app/VulkanWindowContext.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp index 2570e826a3..bc200de427 100644 --- a/tools/viewer/sk_app/VulkanWindowContext.cpp +++ b/tools/viewer/sk_app/VulkanWindowContext.cpp @@ -7,6 +7,7 @@ */ #include "GrContext.h" +#include "GrRenderTarget.h" #include "SkSurface.h" #include "VulkanWindowContext.h" @@ -25,8 +26,12 @@ namespace sk_app { VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams& params) - : fSurface(VK_NULL_HANDLE) + : WindowContext() + , fSurface(VK_NULL_HANDLE) , fSwapchain(VK_NULL_HANDLE) + , fImages(nullptr) + , fImageLayouts(nullptr) + , fSurfaces(nullptr) , fCommandPool(VK_NULL_HANDLE) , fBackbuffers(nullptr) { @@ -250,6 +255,7 @@ void VulkanWindowContext::createBuffers(VkFormat format) { // set up initial image layouts and create surfaces fImageLayouts = new VkImageLayout[fImageCount]; + fRenderTargets = new sk_sp<GrRenderTarget>[fImageCount]; fSurfaces = new sk_sp<SkSurface>[fImageCount]; for (uint32_t i = 0; i < fImageCount; ++i) { fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; @@ -269,10 +275,9 @@ void VulkanWindowContext::createBuffers(VkFormat format) { desc.fSampleCnt = 0; desc.fStencilBits = 0; desc.fRenderTargetHandle = (GrBackendObject) &info; - SkSurfaceProps props(GrPixelConfigIsSRGB(fPixelConfig) - ? SkSurfaceProps::kGammaCorrect_Flag : 0, - kUnknown_SkPixelGeometry); - fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &props); + fRenderTargets[i].reset(fContext->textureProvider()->wrapBackendRenderTarget(desc)); + + fSurfaces[i] = this->createRenderSurface(fRenderTargets[i], 24); } // create the command pool for the command buffers @@ -361,8 +366,11 @@ void VulkanWindowContext::destroyBuffers() { delete[] fBackbuffers; fBackbuffers = nullptr; + // Does this actually free the surfaces? delete[] fSurfaces; fSurfaces = nullptr; + delete[] fRenderTargets; + fRenderTargets = nullptr; delete[] fImageLayouts; fImageLayouts = nullptr; delete[] fImages; @@ -398,7 +406,8 @@ void VulkanWindowContext::destroyContext() { fSurface = VK_NULL_HANDLE; } - delete fContext; + fContext->abandonContext(); + fContext->unref(); fBackendContext.reset(nullptr); } @@ -419,7 +428,7 @@ VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer return backbuffer; } -SkSurface* VulkanWindowContext::getBackbufferSurface() { +sk_sp<SkSurface> VulkanWindowContext::getBackbufferSurface() { BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); SkASSERT(backbuffer); @@ -510,14 +519,16 @@ SkSurface* VulkanWindowContext::getBackbufferSurface() { QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, backbuffer->fUsageFences[0])); - return fSurfaces[backbuffer->fImageIndex].get(); + return sk_ref_sp(fSurfaces[backbuffer->fImageIndex].get()); } - void VulkanWindowContext::swapBuffers() { BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; + this->presentRenderSurface(fSurfaces[backbuffer->fImageIndex], + fRenderTargets[backbuffer->fImageIndex], 24); + VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; |