Flutter Engine
The Flutter Engine
ANGLEWindowContext_win.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
10
13
14namespace {
15
16class ANGLEWindowContext_win : public ANGLEWindowContext {
17public:
18 ANGLEWindowContext_win(HWND, const DisplayParams&);
19
20protected:
21 EGLDisplay onGetEGLDisplay(
22 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT) const override;
23 NativeWindowType onGetNativeWindow() const override;
24 SkISize onGetSize() const override;
25 int onGetStencilBits() const override;
26
27private:
28 HWND fHWND;
29 HDC fHDC;
30};
31
32ANGLEWindowContext_win::ANGLEWindowContext_win(HWND wnd, const DisplayParams& params)
33 : ANGLEWindowContext(params), fHWND(wnd), fHDC(GetDC(fHWND)) {
34 this->initializeContext();
35}
36
37EGLDisplay ANGLEWindowContext_win::onGetEGLDisplay(
38 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT) const {
39 // We currently only support D3D11 ANGLE.
40 static constexpr EGLint kType = EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE;
41 static constexpr EGLint attribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, kType, EGL_NONE};
42 return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, fHDC, attribs);
43}
44
45NativeWindowType ANGLEWindowContext_win::onGetNativeWindow() const { return fHWND; }
46
47int ANGLEWindowContext_win::onGetStencilBits() const {
48 // use DescribePixelFormat to get the stencil depth.
49 int pixelFormat = GetPixelFormat(fHDC);
50 PIXELFORMATDESCRIPTOR pfd;
51 DescribePixelFormat(fHDC, pixelFormat, sizeof(pfd), &pfd);
52 return pfd.cStencilBits;
53}
54
55SkISize ANGLEWindowContext_win::onGetSize() const {
56 RECT rect;
57 GetClientRect(fHWND, &rect);
58 return SkISize::Make(rect.right - rect.left, rect.bottom - rect.top);
59}
60
61} // anonymous namespace
62
63namespace skwindow {
64
65std::unique_ptr<WindowContext> MakeANGLEForWin(HWND wnd, const DisplayParams& params) {
66 std::unique_ptr<WindowContext> ctx(new ANGLEWindowContext_win(wnd, params));
67 if (!ctx->isValid()) {
68 return nullptr;
69 }
70 return ctx;
71}
72
73} // namespace skwindow
#define EGL_PLATFORM_ANGLE_TYPE_ANGLE
#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE
#define EGL_PLATFORM_ANGLE_ANGLE
virtual SkISize onGetSize() const =0
virtual int onGetStencilBits() const =0
virtual EGLDisplay onGetEGLDisplay(PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT) const =0
virtual NativeWindowType onGetNativeWindow() const =0
const EmbeddedViewParams * params
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
std::unique_ptr< WindowContext > MakeANGLEForWin(HWND wnd, const DisplayParams &params)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20