SW backend for viewer on Windows
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2182273002 Review-Url: https://codereview.chromium.org/2182273002
This commit is contained in:
parent
fc560e09b3
commit
ccde4ab8e6
@ -93,7 +93,7 @@ void GLWindowContext::swapBuffers() {
|
||||
this->onSwapBuffers();
|
||||
}
|
||||
|
||||
void GLWindowContext::resize(uint32_t w, uint32_t h) {
|
||||
void GLWindowContext::resize(int w, int h) {
|
||||
this->destroyContext();
|
||||
this->initializeContext();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
bool isValid() override { return SkToBool(fBackendContext.get()); }
|
||||
|
||||
void resize(uint32_t w, uint32_t h) override;
|
||||
void resize(int w, int h) override;
|
||||
void swapBuffers() override;
|
||||
|
||||
void setDisplayParams(const DisplayParams& params) override;
|
||||
|
@ -85,7 +85,7 @@ VulkanWindowContext::VulkanWindowContext(const DisplayParams& params,
|
||||
vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQueue);
|
||||
}
|
||||
|
||||
bool VulkanWindowContext::createSwapchain(uint32_t width, uint32_t height,
|
||||
bool VulkanWindowContext::createSwapchain(int width, int height,
|
||||
const DisplayParams& params) {
|
||||
// check for capabilities
|
||||
VkSurfaceCapabilitiesKHR caps;
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
|
||||
bool isValid() override { return SkToBool(fBackendContext.get()); }
|
||||
|
||||
void resize(uint32_t w, uint32_t h) override {
|
||||
void resize(int w, int h) override {
|
||||
this->createSwapchain(w, h, fDisplayParams);
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ private:
|
||||
};
|
||||
|
||||
BackbufferInfo* getAvailableBackbuffer();
|
||||
bool createSwapchain(uint32_t width, uint32_t height, const DisplayParams& params);
|
||||
bool createSwapchain(int width, int height, const DisplayParams& params);
|
||||
void createBuffers(VkFormat format);
|
||||
void destroyBuffers();
|
||||
|
||||
|
@ -88,7 +88,7 @@ void Window::onPaint() {
|
||||
}
|
||||
}
|
||||
|
||||
void Window::onResize(uint32_t w, uint32_t h) {
|
||||
void Window::onResize(int w, int h) {
|
||||
fWidth = w;
|
||||
fHeight = h;
|
||||
fWindowContext->resize(w, h);
|
||||
|
@ -156,7 +156,7 @@ public:
|
||||
bool onTouch(intptr_t owner, InputState state, float x, float y); // multi-owner = multi-touch
|
||||
void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
|
||||
void onPaint();
|
||||
void onResize(uint32_t width, uint32_t height);
|
||||
void onResize(int width, int height);
|
||||
|
||||
int width() { return fWidth; }
|
||||
int height() { return fHeight; }
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
|
||||
virtual bool isValid() = 0;
|
||||
|
||||
virtual void resize(uint32_t w, uint32_t h) = 0;
|
||||
virtual void resize(int w, int h) = 0;
|
||||
|
||||
const DisplayParams& getDisplayParams() { return fDisplayParams; }
|
||||
virtual void setDisplayParams(const DisplayParams& params) = 0;
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
void swapBuffers() override;
|
||||
|
||||
bool isValid() override { return SkToBool(fNativeWindow); }
|
||||
void resize(uint32_t w, uint32_t h) override;
|
||||
void resize(int w, int h) override;
|
||||
void setDisplayParams(const DisplayParams& params) override;
|
||||
|
||||
private:
|
||||
@ -63,7 +63,7 @@ void RasterWindowContext_android::setDisplayParams(const DisplayParams& params)
|
||||
this->setBuffersGeometry();
|
||||
}
|
||||
|
||||
void RasterWindowContext_android::resize(uint32_t w, uint32_t h) {
|
||||
void RasterWindowContext_android::resize(int w, int h) {
|
||||
fWidth = w;
|
||||
fHeight = h;
|
||||
this->setBuffersGeometry();
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
sk_sp<SkSurface> getBackbufferSurface() override;
|
||||
void swapBuffers() override;
|
||||
bool isValid() override { return SkToBool(fWindow); }
|
||||
void resize(uint32_t w, uint32_t h) override;
|
||||
void resize(int w, int h) override;
|
||||
void setDisplayParams(const DisplayParams& params) override;
|
||||
|
||||
protected:
|
||||
@ -49,7 +49,7 @@ void RasterWindowContext_xlib::setDisplayParams(const DisplayParams& params) {
|
||||
this->resize(attrs.width, attrs.height);
|
||||
}
|
||||
|
||||
void RasterWindowContext_xlib::resize(uint32_t w, uint32_t h) {
|
||||
void RasterWindowContext_xlib::resize(int w, int h) {
|
||||
SkImageInfo info = SkImageInfo::Make(w, h, fDisplayParams.fColorType, kPremul_SkAlphaType,
|
||||
fDisplayParams.fColorSpace);
|
||||
fBackbufferSurface = SkSurface::MakeRaster(info);
|
||||
|
96
tools/viewer/sk_app/win/RasterWindowContext_win.cpp
Normal file
96
tools/viewer/sk_app/win/RasterWindowContext_win.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "WindowContextFactory_win.h"
|
||||
#include "../RasterWindowContext.h"
|
||||
#include "SkSurface.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
using sk_app::RasterWindowContext;
|
||||
using sk_app::DisplayParams;
|
||||
|
||||
namespace {
|
||||
|
||||
class RasterWindowContext_win : public RasterWindowContext {
|
||||
public:
|
||||
RasterWindowContext_win(HWND, const DisplayParams&);
|
||||
|
||||
sk_sp<SkSurface> getBackbufferSurface() override;
|
||||
void swapBuffers() override;
|
||||
bool isValid() override { return SkToBool(fWnd); }
|
||||
void resize(int w, int h) override;
|
||||
void setDisplayParams(const DisplayParams& params) override;
|
||||
|
||||
protected:
|
||||
SkAutoMalloc fSurfaceMemory;
|
||||
sk_sp<SkSurface> fBackbufferSurface;
|
||||
HWND fWnd;
|
||||
};
|
||||
|
||||
RasterWindowContext_win::RasterWindowContext_win(HWND wnd, const DisplayParams& params)
|
||||
: fWnd(wnd) {
|
||||
fDisplayParams = params;
|
||||
RECT rect;
|
||||
GetWindowRect(wnd, &rect);
|
||||
this->resize(rect.right - rect.left, rect.bottom - rect.top);
|
||||
}
|
||||
|
||||
void RasterWindowContext_win::setDisplayParams(const DisplayParams& params) {
|
||||
fDisplayParams = params;
|
||||
RECT rect;
|
||||
GetWindowRect(fWnd, &rect);
|
||||
this->resize(rect.right - rect.left, rect.bottom - rect.top);
|
||||
}
|
||||
|
||||
void RasterWindowContext_win::resize(int w, int h) {
|
||||
fWidth = w;
|
||||
fHeight = h;
|
||||
fBackbufferSurface.reset();
|
||||
const size_t bmpSize = sizeof(BITMAPINFOHEADER) + w * h * sizeof(uint32_t);
|
||||
fSurfaceMemory.reset(bmpSize);
|
||||
BITMAPINFO* bmpInfo = reinterpret_cast<BITMAPINFO*>(fSurfaceMemory.get());
|
||||
ZeroMemory(bmpInfo, sizeof(BITMAPINFO));
|
||||
bmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmpInfo->bmiHeader.biWidth = w;
|
||||
bmpInfo->bmiHeader.biHeight = -h; // negative means top-down bitmap. Skia draws top-down.
|
||||
bmpInfo->bmiHeader.biPlanes = 1;
|
||||
bmpInfo->bmiHeader.biBitCount = 32;
|
||||
bmpInfo->bmiHeader.biCompression = BI_RGB;
|
||||
void* pixels = bmpInfo->bmiColors;
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(w, h, fDisplayParams.fColorType, kPremul_SkAlphaType,
|
||||
fDisplayParams.fColorSpace);
|
||||
fBackbufferSurface = SkSurface::MakeRasterDirect(info, pixels, sizeof(uint32_t) * w);
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> RasterWindowContext_win::getBackbufferSurface() { return fBackbufferSurface; }
|
||||
|
||||
void RasterWindowContext_win::swapBuffers() {
|
||||
BITMAPINFO* bmpInfo = reinterpret_cast<BITMAPINFO*>(fSurfaceMemory.get());
|
||||
HDC dc = GetDC(fWnd);
|
||||
StretchDIBits(dc, 0, 0, fWidth, fHeight, 0, 0, fWidth, fHeight, bmpInfo->bmiColors, bmpInfo,
|
||||
DIB_RGB_COLORS, SRCCOPY);
|
||||
ReleaseDC(fWnd, dc);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace sk_app {
|
||||
namespace window_context_factory {
|
||||
|
||||
WindowContext* NewRasterForWin(HWND wnd, const DisplayParams& params) {
|
||||
WindowContext* ctx = new RasterWindowContext_win(wnd, params);
|
||||
if (!ctx->isValid()) {
|
||||
delete ctx;
|
||||
ctx = nullptr;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
} // namespace window_context_factory
|
||||
} // namespace sk_app
|
@ -22,6 +22,8 @@ WindowContext* NewVulkanForWin(HWND, const DisplayParams&);
|
||||
|
||||
WindowContext* NewGLForWin(HWND, const DisplayParams&);
|
||||
|
||||
WindowContext* NewRasterForWin(HWND, const DisplayParams&);
|
||||
|
||||
} // namespace window_context_factory
|
||||
|
||||
} // namespace sk_app
|
||||
|
@ -270,9 +270,11 @@ void Window_win::show() {
|
||||
bool Window_win::attach(BackendType attachType, const DisplayParams& params) {
|
||||
switch (attachType) {
|
||||
case kNativeGL_BackendType:
|
||||
default:
|
||||
fWindowContext = window_context_factory::NewGLForWin(fHWnd, params);
|
||||
break;
|
||||
case kRaster_BackendType:
|
||||
fWindowContext = window_context_factory::NewRasterForWin(fHWnd, params);
|
||||
break;
|
||||
#ifdef SK_VULKAN
|
||||
case kVulkan_BackendType:
|
||||
fWindowContext = window_context_factory::NewVulkanForWin(fHWnd, params);
|
||||
|
Loading…
Reference in New Issue
Block a user