blob: 8d3085b4e610062877a9c0266b3239127c23fe04 [file] [log] [blame]
jvanverthaf236b52016-05-20 06:01:06 -07001
2/*
3 * Copyright 2016 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#ifndef GLWindowContext_DEFINED
9#define GLWindowContext_DEFINED
10
11
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/gpu/gl/GrGLInterface.h"
jvanverthaf236b52016-05-20 06:01:06 -070013
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/core/SkRefCnt.h"
15#include "include/core/SkSurface.h"
jvanverthaf236b52016-05-20 06:01:06 -070016
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "tools/sk_app/WindowContext.h"
jvanverthaf236b52016-05-20 06:01:06 -070018
19class GrContext;
20
21namespace sk_app {
22
23class GLWindowContext : public WindowContext {
24public:
jvanverthaf236b52016-05-20 06:01:06 -070025 sk_sp<SkSurface> getBackbufferSurface() override;
26
27 bool isValid() override { return SkToBool(fBackendContext.get()); }
28
bsalomonccde4ab2016-07-27 08:50:12 -070029 void resize(int w, int h) override;
jvanverthaf236b52016-05-20 06:01:06 -070030 void swapBuffers() override;
31
32 void setDisplayParams(const DisplayParams& params) override;
33
jvanverthaf236b52016-05-20 06:01:06 -070034protected:
bsalomond1bdd1f2016-07-26 12:02:50 -070035 GLWindowContext(const DisplayParams&);
36 // This should be called by subclass constructor. It is also called when window/display
37 // parameters change. This will in turn call onInitializeContext().
38 void initializeContext();
Brian Salomon194db172017-08-17 14:37:06 -040039 virtual sk_sp<const GrGLInterface> onInitializeContext() = 0;
bsalomond1bdd1f2016-07-26 12:02:50 -070040
41 // This should be called by subclass destructor. It is also called when window/display
42 // parameters change prior to initializing a new GL context. This will in turn call
43 // onDestroyContext().
jvanverthaf236b52016-05-20 06:01:06 -070044 void destroyContext();
45 virtual void onDestroyContext() = 0;
bsalomond1bdd1f2016-07-26 12:02:50 -070046
jvanverthaf236b52016-05-20 06:01:06 -070047 virtual void onSwapBuffers() = 0;
48
Hal Canary1b612a82016-11-03 16:26:13 -040049 sk_sp<const GrGLInterface> fBackendContext;
50 sk_sp<SkSurface> fSurface;
jvanverthaf236b52016-05-20 06:01:06 -070051};
52
53} // namespace sk_app
54
55#endif