007267bdb5
This reverts commit0db3a8846a
. Reason for revert: fuchsia change reverted Original change's description: > Reland "Make GrVkBackendContext no longer derive from SkRefCnt." > > This reverts commit059a9ab4bc
. > > Reason for revert: Fix landed in Fuchsia > > Original change's description: > > Revert "Make GrVkBackendContext no longer derive from SkRefCnt." > > > > This reverts commit93ae233773
. > > > > Reason for revert: <INSERT REASONING HERE> > > > > Original change's description: > > > Make GrVkBackendContext no longer derive from SkRefCnt. > > > > > > Also moves the helper Create functions to VkTestUtils since no clients > > > are using them anymore. > > > > > > Bug: skia: > > > Change-Id: I7e8e4912e7ef6fb00a7e2a00407aed5e83211799 > > > Reviewed-on: https://skia-review.googlesource.com/135323 > > > Reviewed-by: Jim Van Verth <jvanverth@google.com> > > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com > > > > # Not skipping CQ checks because original CL landed > 1 day ago. > > > > Bug: skia: > > Change-Id: If7201917631dc22753ea3fa6e9d2984463e38e4c > > Reviewed-on: https://skia-review.googlesource.com/137903 > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com > > # Not skipping CQ checks because original CL landed > 1 day ago. > > Bug: skia: > Change-Id: Ia4b7c0bb2c7b5dba809d85c69f0b41b473140526 > Reviewed-on: https://skia-review.googlesource.com/138181 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com Change-Id: I3f7bc4a5e4e09512fe165303685c123ec3527e58 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia: Reviewed-on: https://skia-review.googlesource.com/138422 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
119 lines
4.2 KiB
C++
119 lines
4.2 KiB
C++
|
|
/*
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
#ifndef VulkanWindowContext_DEFINED
|
|
#define VulkanWindowContext_DEFINED
|
|
|
|
#include "SkTypes.h" // required to pull in any SkUserConfig defines
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
#include "vk/GrVkBackendContext.h"
|
|
#include "WindowContext.h"
|
|
|
|
class GrRenderTarget;
|
|
|
|
namespace sk_app {
|
|
|
|
class VulkanWindowContext : public WindowContext {
|
|
public:
|
|
~VulkanWindowContext() override;
|
|
|
|
sk_sp<SkSurface> getBackbufferSurface() override;
|
|
void swapBuffers() override;
|
|
|
|
bool isValid() override { return SkToBool(fBackendContext.get()); }
|
|
|
|
void resize(int w, int h) override {
|
|
this->createSwapchain(w, h, fDisplayParams);
|
|
}
|
|
|
|
void setDisplayParams(const DisplayParams& params) override {
|
|
this->destroyContext();
|
|
fDisplayParams = params;
|
|
this->initializeContext();
|
|
}
|
|
|
|
/** Platform specific function that creates a VkSurfaceKHR for a window */
|
|
using CreateVkSurfaceFn = std::function<VkSurfaceKHR(VkInstance)>;
|
|
/** Platform specific function that determines whether presentation will succeed. */
|
|
using CanPresentFn = GrVkBackendContext::CanPresentFn;
|
|
|
|
VulkanWindowContext(const DisplayParams&, CreateVkSurfaceFn, CanPresentFn,
|
|
PFN_vkGetInstanceProcAddr, PFN_vkGetDeviceProcAddr);
|
|
|
|
private:
|
|
void initializeContext();
|
|
void destroyContext();
|
|
|
|
struct BackbufferInfo {
|
|
uint32_t fImageIndex; // image this is associated with
|
|
VkSemaphore fAcquireSemaphore; // we signal on this for acquisition of image
|
|
VkSemaphore fRenderSemaphore; // we wait on this for rendering to be done
|
|
VkCommandBuffer fTransitionCmdBuffers[2]; // to transition layout between present and render
|
|
VkFence fUsageFences[2]; // used to ensure this data is no longer used on GPU
|
|
};
|
|
|
|
BackbufferInfo* getAvailableBackbuffer();
|
|
bool createSwapchain(int width, int height, const DisplayParams& params);
|
|
void createBuffers(VkFormat format, SkColorType colorType);
|
|
void destroyBuffers();
|
|
|
|
sk_sp<const GrVkBackendContext> fBackendContext;
|
|
|
|
// simple wrapper class that exists only to initialize a pointer to NULL
|
|
template <typename FNPTR_TYPE> class VkPtr {
|
|
public:
|
|
VkPtr() : fPtr(NULL) {}
|
|
VkPtr operator=(FNPTR_TYPE ptr) { fPtr = ptr; return *this; }
|
|
operator FNPTR_TYPE() const { return fPtr; }
|
|
private:
|
|
FNPTR_TYPE fPtr;
|
|
};
|
|
|
|
// Create functions
|
|
CreateVkSurfaceFn fCreateVkSurfaceFn;
|
|
CanPresentFn fCanPresentFn;
|
|
|
|
// Vulkan GetProcAddr functions
|
|
VkPtr<PFN_vkGetInstanceProcAddr> fGetInstanceProcAddr;
|
|
VkPtr<PFN_vkGetDeviceProcAddr> fGetDeviceProcAddr;
|
|
|
|
// WSI interface functions
|
|
VkPtr<PFN_vkDestroySurfaceKHR> fDestroySurfaceKHR;
|
|
VkPtr<PFN_vkGetPhysicalDeviceSurfaceSupportKHR> fGetPhysicalDeviceSurfaceSupportKHR;
|
|
VkPtr<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR> fGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
|
VkPtr<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR> fGetPhysicalDeviceSurfaceFormatsKHR;
|
|
VkPtr<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR> fGetPhysicalDeviceSurfacePresentModesKHR;
|
|
|
|
VkPtr<PFN_vkCreateSwapchainKHR> fCreateSwapchainKHR;
|
|
VkPtr<PFN_vkDestroySwapchainKHR> fDestroySwapchainKHR;
|
|
VkPtr<PFN_vkGetSwapchainImagesKHR> fGetSwapchainImagesKHR;
|
|
VkPtr<PFN_vkAcquireNextImageKHR> fAcquireNextImageKHR;
|
|
VkPtr<PFN_vkQueuePresentKHR> fQueuePresentKHR;
|
|
VkPtr<PFN_vkGetDeviceQueue> fGetDeviceQueue;
|
|
|
|
VkSurfaceKHR fSurface;
|
|
VkSwapchainKHR fSwapchain;
|
|
uint32_t fPresentQueueIndex;
|
|
VkQueue fPresentQueue;
|
|
|
|
uint32_t fImageCount;
|
|
VkImage* fImages; // images in the swapchain
|
|
VkImageLayout* fImageLayouts; // layouts of these images when not color attachment
|
|
sk_sp<SkSurface>* fSurfaces; // surfaces client renders to (may not be based on rts)
|
|
VkCommandPool fCommandPool;
|
|
BackbufferInfo* fBackbuffers;
|
|
uint32_t fCurrentBackbufferIndex;
|
|
};
|
|
|
|
} // namespace sk_app
|
|
|
|
#endif // SK_VULKAN
|
|
|
|
#endif
|