1cb93a386Sopenharmony_ci
2cb93a386Sopenharmony_ci/*
3cb93a386Sopenharmony_ci * Copyright 2016 Google Inc.
4cb93a386Sopenharmony_ci *
5cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
6cb93a386Sopenharmony_ci * found in the LICENSE file.
7cb93a386Sopenharmony_ci */
8cb93a386Sopenharmony_ci#ifndef GLWindowContext_DEFINED
9cb93a386Sopenharmony_ci#define GLWindowContext_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ci#include "include/gpu/gl/GrGLInterface.h"
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h"
15cb93a386Sopenharmony_ci#include "include/core/SkSurface.h"
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_ci#include "tools/sk_app/WindowContext.h"
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_cinamespace sk_app {
20cb93a386Sopenharmony_ci
21cb93a386Sopenharmony_ciclass GLWindowContext : public WindowContext {
22cb93a386Sopenharmony_cipublic:
23cb93a386Sopenharmony_ci    sk_sp<SkSurface> getBackbufferSurface() override;
24cb93a386Sopenharmony_ci
25cb93a386Sopenharmony_ci    bool isValid() override { return SkToBool(fBackendContext.get()); }
26cb93a386Sopenharmony_ci
27cb93a386Sopenharmony_ci    void resize(int w, int h) override;
28cb93a386Sopenharmony_ci    void swapBuffers() override;
29cb93a386Sopenharmony_ci
30cb93a386Sopenharmony_ci    void setDisplayParams(const DisplayParams& params) override;
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_ciprotected:
33cb93a386Sopenharmony_ci    GLWindowContext(const DisplayParams&);
34cb93a386Sopenharmony_ci    // This should be called by subclass constructor. It is also called when window/display
35cb93a386Sopenharmony_ci    // parameters change. This will in turn call onInitializeContext().
36cb93a386Sopenharmony_ci    void initializeContext();
37cb93a386Sopenharmony_ci    virtual sk_sp<const GrGLInterface> onInitializeContext() = 0;
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ci    // This should be called by subclass destructor. It is also called when window/display
40cb93a386Sopenharmony_ci    // parameters change prior to initializing a new GL context. This will in turn call
41cb93a386Sopenharmony_ci    // onDestroyContext().
42cb93a386Sopenharmony_ci    void destroyContext();
43cb93a386Sopenharmony_ci    virtual void onDestroyContext() = 0;
44cb93a386Sopenharmony_ci
45cb93a386Sopenharmony_ci    virtual void onSwapBuffers() = 0;
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_ci    sk_sp<const GrGLInterface> fBackendContext;
48cb93a386Sopenharmony_ci    sk_sp<SkSurface>           fSurface;
49cb93a386Sopenharmony_ci};
50cb93a386Sopenharmony_ci
51cb93a386Sopenharmony_ci}   // namespace sk_app
52cb93a386Sopenharmony_ci
53cb93a386Sopenharmony_ci#endif
54