author Wes Kocher <>
Wed, 10 May 2017 10:01:18 -0700
changeset 407965 ce2218406119c36a551e3faea4e192186ee46cc5
parent 407937 af6f19870b2a00759ac1d83dedc3db57213abfee
child 408167 0ded74baeaf23d7985401fe9bbabdb3d9385ac22
permissions -rw-r--r--
Backed out 9 changesets (bug 1340627) for graphical glitches a=backout Backed out changeset 0b1371055c7f (bug 1340627) Backed out changeset f152be1fadb7 (bug 1340627) Backed out changeset c691e2ab6a0c (bug 1340627) Backed out changeset 3cb4bceb8d79 (bug 1340627) Backed out changeset 026aadd76d06 (bug 1340627) Backed out changeset fdbd5d281287 (bug 1340627) Backed out changeset 75fb0d9858a9 (bug 1340627) Backed out changeset 0d4ec7d38a00 (bug 1340627) Backed out changeset af6f19870b2a (bug 1340627) MozReview-Commit-ID: 9dHr7xMZezY

 * Copyright 2006 The Android Open Source Project
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.

#ifndef SkOSWindow_Win_DEFINED
#define SkOSWindow_Win_DEFINED

#include "../private/SkTHash.h"
#include "SkWindow.h"
#include <functional>

#include "EGL/egl.h"

class SkOSWindow : public SkWindow {
    struct WindowInit {
        const TCHAR*    fClass;
        HINSTANCE       fInstance;

    SkOSWindow(const void* winInit);
    virtual ~SkOSWindow();

    static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);

    enum SkBackEndTypes {
#endif // SK_ANGLE
#endif // SK_SUPPORT_GPU

    bool attach(SkBackEndTypes attachType, int msaaSampleCount, bool deepColor, AttachmentInfo*);
    void release();
    void present();

    bool wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    static bool QuitOnDeactivate(HWND hWnd);

    enum {
        SK_WM_SkEvent = WM_APP + 1000,
        SK_WM_SkTimerID = 0xFFFF    // just need a non-zero value

    bool makeFullscreen();
    void setVsync(bool);
    void closeWindow();

    static SkOSWindow* GetOSWindowForHWND(void* hwnd) {
        SkOSWindow** win = gHwndToOSWindowMap.find(hwnd);
        if (!win) {
            return NULL;
        return *win;

    // Iterates f over all the SkOSWindows and their corresponding HWNDs.
    // The void* argument to f is a HWND.
    static void ForAllWindows(const std::function<void(void*, SkOSWindow**)>& f) {

    virtual bool quitOnDeactivate() { return true; }

    // overrides from SkWindow
    virtual void onHandleInval(const SkIRect&);
    // overrides from SkView
    virtual void onAddMenu(const SkOSMenu*);

    virtual void onSetTitle(const char title[]);

    static SkTHashMap<void*, SkOSWindow*> gHwndToOSWindowMap;

    WindowInit          fWinInit;
    void*               fHWND;

    void                doPaint(void* ctx);

    void*               fHGLRC;
    EGLDisplay                        fDisplay;
    EGLContext                        fContext;
    EGLSurface                        fSurface;
    EGLConfig                         fConfig;
    SkAutoTUnref<const GrGLInterface> fANGLEInterface;
#endif // SK_ANGLE
#endif // SK_SUPPORT_GPU

    bool                fFullscreen;
    struct SavedWindowState {
        bool fZoomed;
        LONG fStyle;
        LONG fExStyle;
        RECT fRect;
        LONG fScreenWidth;
        LONG fScreenHeight;
        LONG fScreenBits;
        void* fHWND;
    } fSavedWindowState;

    HMENU               fMBar;

    SkBackEndTypes      fAttached;

    void updateSize();
    bool attachGL(int msaaSampleCount, bool deepColor, AttachmentInfo* info);
    void detachGL();
    void presentGL();

    bool attachANGLE(int msaaSampleCount, AttachmentInfo* info);
    void detachANGLE();
    void presentANGLE();
#endif // SK_ANGLE

#endif // SK_SUPPORT_GPU

    typedef SkWindow INHERITED;