tools/sk_app: fWindowContext is unique_ptr<>
Change-Id: I828f298e336da22756588d981481c76b890af2ee Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231648 Commit-Queue: Ben Wagner <bungeman@google.com> Auto-Submit: Hal Canary <halcanary@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
788967eb37
commit
149f3f1978
@ -15,10 +15,9 @@ namespace sk_app {
|
||||
|
||||
Window::Window() {}
|
||||
|
||||
void Window::detach() {
|
||||
delete fWindowContext;
|
||||
fWindowContext = nullptr;
|
||||
}
|
||||
Window::~Window() {}
|
||||
|
||||
void Window::detach() { fWindowContext = nullptr; }
|
||||
|
||||
void Window::visitLayers(std::function<void(Layer*)> visitor) {
|
||||
for (int i = 0; i < fLayers.count(); ++i) {
|
||||
|
@ -28,7 +28,7 @@ class Window {
|
||||
public:
|
||||
static Window* CreateNativeWindow(void* platformData);
|
||||
|
||||
virtual ~Window() { this->detach(); }
|
||||
virtual ~Window();
|
||||
|
||||
virtual void setTitle(const char*) = 0;
|
||||
virtual void show() = 0;
|
||||
@ -182,7 +182,7 @@ protected:
|
||||
SkTDArray<Layer*> fLayers;
|
||||
DisplayParams fRequestedDisplayParams;
|
||||
|
||||
WindowContext* fWindowContext = nullptr;
|
||||
std::unique_ptr<WindowContext> fWindowContext;
|
||||
|
||||
virtual void onInval() = 0;
|
||||
|
||||
|
@ -144,10 +144,10 @@ void GLWindowContext_android::onSwapBuffers() {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewGLForAndroid(ANativeWindow* window, const DisplayParams& params) {
|
||||
WindowContext* ctx = new GLWindowContext_android(window, params);
|
||||
std::unique_ptr<WindowContext> MakeGLForAndroid(ANativeWindow* window,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new GLWindowContext_android(window, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -95,10 +95,10 @@ void RasterWindowContext_android::swapBuffers() {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewRasterForAndroid(ANativeWindow* window, const DisplayParams& params) {
|
||||
WindowContext* ctx = new RasterWindowContext_android(window, params);
|
||||
std::unique_ptr<WindowContext> MakeRasterForAndroid(ANativeWindow* window,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new RasterWindowContext_android(window, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -18,7 +18,8 @@ namespace sk_app {
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewVulkanForAndroid(ANativeWindow* window, const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> MakeVulkanForAndroid(ANativeWindow* window,
|
||||
const DisplayParams& params) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
@ -48,10 +49,9 @@ WindowContext* NewVulkanForAndroid(ANativeWindow* window, const DisplayParams& p
|
||||
|
||||
auto canPresent = [](VkInstance, VkPhysicalDevice, uint32_t) { return true; };
|
||||
|
||||
WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent,
|
||||
instProc, devProc);
|
||||
std::unique_ptr<WindowContext> ctx(
|
||||
new VulkanWindowContext(params, createVkSurface, canPresent, instProc, devProc));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include <android/native_window_jni.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
@ -19,11 +20,11 @@ struct DisplayParams;
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewVulkanForAndroid(ANativeWindow*, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeVulkanForAndroid(ANativeWindow*, const DisplayParams&);
|
||||
|
||||
WindowContext* NewGLForAndroid(ANativeWindow*, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeGLForAndroid(ANativeWindow*, const DisplayParams&);
|
||||
|
||||
WindowContext* NewRasterForAndroid(ANativeWindow*, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeRasterForAndroid(ANativeWindow*, const DisplayParams&);
|
||||
|
||||
} // namespace window_context_factory
|
||||
|
||||
|
@ -49,17 +49,17 @@ void Window_android::initDisplay(ANativeWindow* window) {
|
||||
switch (fBackendType) {
|
||||
case kNativeGL_BackendType:
|
||||
default:
|
||||
fWindowContext = window_context_factory::NewGLForAndroid(window,
|
||||
fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeGLForAndroid(window, fRequestedDisplayParams);
|
||||
break;
|
||||
case kRaster_BackendType:
|
||||
fWindowContext = window_context_factory::NewRasterForAndroid(window,
|
||||
fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeRasterForAndroid(window, fRequestedDisplayParams);
|
||||
break;
|
||||
#ifdef SK_VULKAN
|
||||
case kVulkan_BackendType:
|
||||
fWindowContext = window_context_factory::NewVulkanForAndroid(window,
|
||||
fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeVulkanForAndroid(window, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
@ -83,10 +83,10 @@ void GLWindowContext_ios::onSwapBuffers() {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewGLForIOS(const IOSWindowInfo& info, const DisplayParams& params) {
|
||||
WindowContext* ctx = new GLWindowContext_ios(info, params);
|
||||
std::unique_ptr<WindowContext> MakeGLForIOS(const IOSWindowInfo& info,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new GLWindowContext_ios(info, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -116,10 +116,10 @@ void RasterWindowContext_ios::onSwapBuffers() {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewRasterForIOS(const IOSWindowInfo& info, const DisplayParams& params) {
|
||||
WindowContext* ctx = new RasterWindowContext_ios(info, params);
|
||||
std::unique_ptr<WindowContext> MakeRasterForIOS(const IOSWindowInfo& info,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new RasterWindowContext_ios(info, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -11,9 +11,12 @@
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#include "tools/sk_app/WindowContext.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class WindowContext;
|
||||
struct DisplayParams;
|
||||
|
||||
namespace window_context_factory {
|
||||
@ -23,14 +26,14 @@ struct IOSWindowInfo {
|
||||
SDL_GLContext fGLContext;
|
||||
};
|
||||
|
||||
inline WindowContext* NewVulkanForIOS(const IOSWindowInfo&, const DisplayParams&) {
|
||||
inline std::unique_ptr<WindowContext> MakeVulkanForIOS(const IOSWindowInfo&, const DisplayParams&) {
|
||||
// No Vulkan support on iOS.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WindowContext* NewGLForIOS(const IOSWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeGLForIOS(const IOSWindowInfo&, const DisplayParams&);
|
||||
|
||||
WindowContext* NewRasterForIOS(const IOSWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeRasterForIOS(const IOSWindowInfo&, const DisplayParams&);
|
||||
|
||||
} // namespace window_context_factory
|
||||
|
||||
|
@ -262,12 +262,12 @@ bool Window_ios::attach(BackendType attachType) {
|
||||
info.fGLContext = fGLContext;
|
||||
switch (attachType) {
|
||||
case kRaster_BackendType:
|
||||
fWindowContext = NewRasterForIOS(info, fRequestedDisplayParams);
|
||||
fWindowContext = MakeRasterForIOS(info, fRequestedDisplayParams);
|
||||
break;
|
||||
|
||||
case kNativeGL_BackendType:
|
||||
default:
|
||||
fWindowContext = NewGLForIOS(info, fRequestedDisplayParams);
|
||||
fWindowContext = MakeGLForIOS(info, fRequestedDisplayParams);
|
||||
break;
|
||||
}
|
||||
this->onBackendCreated();
|
||||
|
@ -161,10 +161,10 @@ void GLWindowContext_mac::resize(int w, int h) {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewGLForMac(const MacWindowInfo& info, const DisplayParams& params) {
|
||||
WindowContext* ctx = new GLWindowContext_mac(info, params);
|
||||
std::unique_ptr<WindowContext> MakeGLForMac(const MacWindowInfo& info,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new GLWindowContext_mac(info, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -87,10 +87,10 @@ void MetalWindowContext_mac::resize(int w, int h) {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewMetalForMac(const MacWindowInfo& info, const DisplayParams& params) {
|
||||
WindowContext* ctx = new MetalWindowContext_mac(info, params);
|
||||
std::unique_ptr<WindowContext> MakeMetalForMac(const MacWindowInfo& info,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new MetalWindowContext_mac(info, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -174,10 +174,10 @@ void RasterWindowContext_mac::resize(int w, int h) {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewRasterForMac(const MacWindowInfo& info, const DisplayParams& params) {
|
||||
WindowContext* ctx = new RasterWindowContext_mac(info, params);
|
||||
std::unique_ptr<WindowContext> MakeRasterForMac(const MacWindowInfo& info,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new RasterWindowContext_mac(info, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -68,7 +68,8 @@ void VulkanWindowContext_mac::resize(int w, int h) {
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewVulkanForMac(const MacWindowInfo& info, const DisplayParams& displayParams) {
|
||||
std::unique_ptr<WindowContext> MakeVulkanForMac(const MacWindowInfo& info,
|
||||
const DisplayParams& displayParams) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
@ -138,15 +139,15 @@ WindowContext* NewVulkanForMac(const MacWindowInfo& info, const DisplayParams& d
|
||||
auto canPresent = [](VkInstance instance, VkPhysicalDevice physDev, uint32_t queueFamilyIndex) {
|
||||
return true;
|
||||
};
|
||||
WindowContext* context = new VulkanWindowContext_mac(mtkView, displayParams, createVkSurface,
|
||||
canPresent, instProc, devProc);
|
||||
if (!context->isValid()) {
|
||||
delete context;
|
||||
std::unique_ptr<WindowContext> ctx(new VulkanWindowContext_mac(
|
||||
mtkView, displayParams, createVkSurface, canPresent, instProc, devProc));
|
||||
if (!ctx->isValid()) {
|
||||
ctx = nullptr;
|
||||
[mtkView removeFromSuperview];
|
||||
[mtkView release];
|
||||
return nullptr;
|
||||
}
|
||||
return context;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
} // namespace VulkanWindowContextFactory
|
||||
|
@ -9,11 +9,14 @@
|
||||
#ifndef WindowContextFactory_mac_DEFINED
|
||||
#define WindowContextFactory_mac_DEFINED
|
||||
|
||||
#include "tools/sk_app/WindowContext.h"
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class WindowContext;
|
||||
struct DisplayParams;
|
||||
|
||||
namespace window_context_factory {
|
||||
@ -23,19 +26,19 @@ struct MacWindowInfo {
|
||||
};
|
||||
|
||||
#ifdef SK_VULKAN
|
||||
WindowContext* NewVulkanForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeVulkanForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
#else
|
||||
inline WindowContext* NewVulkanForMac(const MacWindowInfo&, const DisplayParams&) {
|
||||
inline std::unique_ptr<WindowContext> MakeVulkanForMac(const MacWindowInfo&, const DisplayParams&) {
|
||||
// No Vulkan support on Mac.
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
WindowContext* NewGLForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeGLForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
|
||||
WindowContext* NewRasterForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeRasterForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
#ifdef SK_METAL
|
||||
WindowContext* NewMetalForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeMetalForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
#endif
|
||||
|
||||
} // namespace window_context_factory
|
||||
|
@ -120,21 +120,21 @@ bool Window_mac::attach(BackendType attachType) {
|
||||
info.fMainView = [fWindow contentView];
|
||||
switch (attachType) {
|
||||
case kRaster_BackendType:
|
||||
fWindowContext = NewRasterForMac(info, fRequestedDisplayParams);
|
||||
fWindowContext = MakeRasterForMac(info, fRequestedDisplayParams);
|
||||
break;
|
||||
#ifdef SK_VULKAN
|
||||
case kVulkan_BackendType:
|
||||
fWindowContext = NewVulkanForMac(info, fRequestedDisplayParams);
|
||||
fWindowContext = MakeVulkanForMac(info, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
#ifdef SK_METAL
|
||||
case kMetal_BackendType:
|
||||
fWindowContext = NewMetalForMac(info, fRequestedDisplayParams);
|
||||
fWindowContext = MakeMetalForMac(info, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
case kNativeGL_BackendType:
|
||||
default:
|
||||
fWindowContext = NewGLForMac(info, fRequestedDisplayParams);
|
||||
fWindowContext = MakeGLForMac(info, fRequestedDisplayParams);
|
||||
break;
|
||||
}
|
||||
this->onBackendCreated();
|
||||
|
@ -182,10 +182,10 @@ namespace sk_app {
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewGLForXlib(const XlibWindowInfo& winInfo, const DisplayParams& params) {
|
||||
WindowContext* ctx = new GLWindowContext_xlib(winInfo, params);
|
||||
std::unique_ptr<WindowContext> MakeGLForXlib(const XlibWindowInfo& winInfo,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new GLWindowContext_xlib(winInfo, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -90,11 +90,11 @@ void RasterWindowContext_xlib::swapBuffers() {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewRasterForXlib(const XlibWindowInfo& info, const DisplayParams& params) {
|
||||
WindowContext* ctx = new RasterWindowContext_xlib(info.fDisplay, info.fWindow, info.fWidth,
|
||||
info.fHeight, params);
|
||||
std::unique_ptr<WindowContext> MakeRasterForXlib(const XlibWindowInfo& info,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new RasterWindowContext_xlib(
|
||||
info.fDisplay, info.fWindow, info.fWidth, info.fHeight, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
ctx = nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -22,7 +22,8 @@ namespace sk_app {
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewVulkanForXlib(const XlibWindowInfo& info, const DisplayParams& displayParams) {
|
||||
std::unique_ptr<WindowContext> MakeVulkanForXlib(const XlibWindowInfo& info,
|
||||
const DisplayParams& displayParams) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
@ -73,13 +74,12 @@ WindowContext* NewVulkanForXlib(const XlibWindowInfo& info, const DisplayParams&
|
||||
visualID);
|
||||
return (VK_FALSE != check);
|
||||
};
|
||||
WindowContext* context = new VulkanWindowContext(displayParams, createVkSurface, canPresent,
|
||||
instProc, devProc);
|
||||
if (!context->isValid()) {
|
||||
delete context;
|
||||
std::unique_ptr<WindowContext> ctx(
|
||||
new VulkanWindowContext(displayParams, createVkSurface, canPresent, instProc, devProc));
|
||||
if (!ctx->isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
return context;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
} // namespace VulkanWindowContextFactory
|
||||
|
@ -15,6 +15,9 @@
|
||||
#endif
|
||||
#include <X11/Xlib.h>
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
typedef Window XWindow;
|
||||
|
||||
namespace sk_app {
|
||||
@ -33,11 +36,11 @@ struct XlibWindowInfo {
|
||||
int fHeight;
|
||||
};
|
||||
|
||||
WindowContext* NewVulkanForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeVulkanForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
|
||||
WindowContext* NewGLForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeGLForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
|
||||
WindowContext* NewRasterForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeRasterForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
|
||||
} // namespace window_context_factory
|
||||
|
||||
|
@ -360,16 +360,17 @@ bool Window_unix::attach(BackendType attachType) {
|
||||
switch (attachType) {
|
||||
#ifdef SK_VULKAN
|
||||
case kVulkan_BackendType:
|
||||
fWindowContext = window_context_factory::NewVulkanForXlib(winInfo,
|
||||
fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeVulkanForXlib(winInfo, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
case kNativeGL_BackendType:
|
||||
fWindowContext = window_context_factory::NewGLForXlib(winInfo, fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeGLForXlib(winInfo, fRequestedDisplayParams);
|
||||
break;
|
||||
case kRaster_BackendType:
|
||||
fWindowContext = window_context_factory::NewRasterForXlib(winInfo,
|
||||
fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeRasterForXlib(winInfo, fRequestedDisplayParams);
|
||||
break;
|
||||
}
|
||||
this->onBackendCreated();
|
||||
|
@ -167,10 +167,9 @@ void ANGLEGLWindowContext_win::onSwapBuffers() {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewANGLEForWin(HWND wnd, const DisplayParams& params) {
|
||||
ANGLEGLWindowContext_win* ctx = new ANGLEGLWindowContext_win(wnd, params);
|
||||
std::unique_ptr<WindowContext> MakeANGLEForWin(HWND wnd, const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new ANGLEGLWindowContext_win(wnd, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -22,7 +22,7 @@ using sk_app::DisplayParams;
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewGLForWin(HWND, const DisplayParams&) { return nullptr; }
|
||||
std::unique_ptr<WindowContext> MakeGLForWin(HWND, const DisplayParams&) { return nullptr; }
|
||||
|
||||
} // namespace window_context_factory
|
||||
} // namespace sk_app
|
||||
@ -146,10 +146,9 @@ void GLWindowContext_win::onSwapBuffers() {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewGLForWin(HWND wnd, const DisplayParams& params) {
|
||||
GLWindowContext_win* ctx = new GLWindowContext_win(wnd, params);
|
||||
std::unique_ptr<WindowContext> MakeGLForWin(HWND wnd, const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new GLWindowContext_win(wnd, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -87,10 +87,9 @@ void RasterWindowContext_win::swapBuffers() {
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewRasterForWin(HWND wnd, const DisplayParams& params) {
|
||||
WindowContext* ctx = new RasterWindowContext_win(wnd, params);
|
||||
std::unique_ptr<WindowContext> MakeRasterForWin(HWND wnd, const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new RasterWindowContext_win(wnd, params));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
ctx = nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -23,7 +23,7 @@
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewVulkanForWin(HWND hwnd, const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> MakeVulkanForWin(HWND hwnd, const DisplayParams& params) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
@ -69,10 +69,9 @@ WindowContext* NewVulkanForWin(HWND hwnd, const DisplayParams& params) {
|
||||
return (VK_FALSE != check);
|
||||
};
|
||||
|
||||
WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent,
|
||||
instProc, devProc);
|
||||
std::unique_ptr<WindowContext> ctx(
|
||||
new VulkanWindowContext(params, createVkSurface, canPresent, instProc, devProc));
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class WindowContext;
|
||||
@ -18,13 +20,13 @@ struct DisplayParams;
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewVulkanForWin(HWND, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeVulkanForWin(HWND, const DisplayParams&);
|
||||
|
||||
WindowContext* NewGLForWin(HWND, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeGLForWin(HWND, const DisplayParams&);
|
||||
|
||||
WindowContext* NewANGLEForWin(HWND, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeANGLEForWin(HWND, const DisplayParams&);
|
||||
|
||||
WindowContext* NewRasterForWin(HWND, const DisplayParams&);
|
||||
std::unique_ptr<WindowContext> MakeRasterForWin(HWND, const DisplayParams&);
|
||||
|
||||
} // namespace window_context_factory
|
||||
|
||||
|
@ -351,21 +351,22 @@ bool Window_win::attach(BackendType attachType) {
|
||||
|
||||
switch (attachType) {
|
||||
case kNativeGL_BackendType:
|
||||
fWindowContext = window_context_factory::NewGLForWin(fHWnd, fRequestedDisplayParams);
|
||||
fWindowContext = window_context_factory::MakeGLForWin(fHWnd, fRequestedDisplayParams);
|
||||
break;
|
||||
#if SK_ANGLE
|
||||
case kANGLE_BackendType:
|
||||
fWindowContext = window_context_factory::NewANGLEForWin(fHWnd, fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeANGLEForWin(fHWnd, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
case kRaster_BackendType:
|
||||
fWindowContext = window_context_factory::NewRasterForWin(fHWnd,
|
||||
fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeRasterForWin(fHWnd, fRequestedDisplayParams);
|
||||
break;
|
||||
#ifdef SK_VULKAN
|
||||
case kVulkan_BackendType:
|
||||
fWindowContext = window_context_factory::NewVulkanForWin(fHWnd,
|
||||
fRequestedDisplayParams);
|
||||
fWindowContext =
|
||||
window_context_factory::MakeVulkanForWin(fHWnd, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
@ -385,7 +386,7 @@ void Window_win::setRequestedDisplayParams(const DisplayParams& params, bool all
|
||||
// Need to change these early, so attach() creates the window context correctly
|
||||
fRequestedDisplayParams = params;
|
||||
|
||||
delete fWindowContext;
|
||||
fWindowContext = nullptr;
|
||||
this->closeWindow();
|
||||
this->init(fHInstance);
|
||||
this->attach(fBackend);
|
||||
|
Loading…
Reference in New Issue
Block a user