blob: 5b1058e3ee596bdcc47305d1654f4457402f3f77 [file] [log] [blame]
jvanvertha8d0d6c2016-05-05 12:32:03 -07001/*
2 * Copyright 2016 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#ifndef WindowContext_DEFINED
8#define WindowContext_DEFINED
9
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkRefCnt.h"
11#include "include/core/SkSurfaceProps.h"
12#include "include/gpu/GrContext.h"
13#include "include/gpu/GrTypes.h"
14#include "tools/sk_app/DisplayParams.h"
jvanvertha8d0d6c2016-05-05 12:32:03 -070015
16class SkSurface;
jvanverthaf236b52016-05-20 06:01:06 -070017class GrRenderTarget;
jvanvertha8d0d6c2016-05-05 12:32:03 -070018
19namespace sk_app {
20
jvanvertha8d0d6c2016-05-05 12:32:03 -070021class WindowContext {
22public:
Jim Van Verthfbdc0802017-05-02 16:15:53 -040023 WindowContext(const DisplayParams& params)
Brian Salomonbdecacf2018-02-02 20:32:49 -050024 : fContext(nullptr)
25 , fDisplayParams(params)
Brian Salomonbdecacf2018-02-02 20:32:49 -050026 , fSampleCount(1)
27 , fStencilBits(0) {}
jvanverthaf236b52016-05-20 06:01:06 -070028
jvanvertha8d0d6c2016-05-05 12:32:03 -070029 virtual ~WindowContext() {}
30
jvanverthaf236b52016-05-20 06:01:06 -070031 virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
jvanvertha8d0d6c2016-05-05 12:32:03 -070032
33 virtual void swapBuffers() = 0;
34
jvanvertha8d0d6c2016-05-05 12:32:03 -070035 virtual bool isValid() = 0;
36
bsalomonccde4ab2016-07-27 08:50:12 -070037 virtual void resize(int w, int h) = 0;
jvanvertha8d0d6c2016-05-05 12:32:03 -070038
jvanverthaf236b52016-05-20 06:01:06 -070039 const DisplayParams& getDisplayParams() { return fDisplayParams; }
brianosman05de2162016-05-06 13:28:57 -070040 virtual void setDisplayParams(const DisplayParams& params) = 0;
41
Greg Daniel02611d92017-07-25 10:05:01 -040042 GrContext* getGrContext() const { return fContext.get(); }
jvanverthaf236b52016-05-20 06:01:06 -070043
Christopher Dalton443ec1b2017-02-24 13:22:53 -070044 int width() const { return fWidth; }
45 int height() const { return fHeight; }
csmartdalton578f0642017-02-24 16:04:47 -070046 int sampleCount() const { return fSampleCount; }
47 int stencilBits() const { return fStencilBits; }
Christopher Dalton443ec1b2017-02-24 13:22:53 -070048
jvanverthaf236b52016-05-20 06:01:06 -070049protected:
50 virtual bool isGpuContext() { return true; }
51
Greg Daniel02611d92017-07-25 10:05:01 -040052 sk_sp<GrContext> fContext;
jvanverthaf236b52016-05-20 06:01:06 -070053
54 int fWidth;
55 int fHeight;
56 DisplayParams fDisplayParams;
csmartdalton578f0642017-02-24 16:04:47 -070057
58 // parameters obtained from the native window
59 // Note that the platform .cpp file is responsible for
60 // initializing fSampleCount and fStencilBits!
61 int fSampleCount;
62 int fStencilBits;
jvanvertha8d0d6c2016-05-05 12:32:03 -070063};
64
65} // namespace sk_app
66
67#endif