blob: 71c21ac089132c7933ddc211b4cd6e51b96dff0c [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
brianosman05de2162016-05-06 13:28:57 -070010#include "DisplayParams.h"
Greg Daniel02611d92017-07-25 10:05:01 -040011#include "GrContext.h"
jvanvertha8d0d6c2016-05-05 12:32:03 -070012#include "GrTypes.h"
jvanverthaf236b52016-05-20 06:01:06 -070013#include "SkRefCnt.h"
14#include "SkSurfaceProps.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)
26 , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
27 , fSampleCount(1)
28 , fStencilBits(0) {}
jvanverthaf236b52016-05-20 06:01:06 -070029
jvanvertha8d0d6c2016-05-05 12:32:03 -070030 virtual ~WindowContext() {}
31
jvanverthaf236b52016-05-20 06:01:06 -070032 virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
jvanvertha8d0d6c2016-05-05 12:32:03 -070033
34 virtual void swapBuffers() = 0;
35
jvanvertha8d0d6c2016-05-05 12:32:03 -070036 virtual bool isValid() = 0;
37
bsalomonccde4ab2016-07-27 08:50:12 -070038 virtual void resize(int w, int h) = 0;
jvanvertha8d0d6c2016-05-05 12:32:03 -070039
jvanverthaf236b52016-05-20 06:01:06 -070040 const DisplayParams& getDisplayParams() { return fDisplayParams; }
brianosman05de2162016-05-06 13:28:57 -070041 virtual void setDisplayParams(const DisplayParams& params) = 0;
42
jvanverthaf236b52016-05-20 06:01:06 -070043 SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
44 void setSurfaceProps(const SkSurfaceProps& props) {
45 fSurfaceProps = props;
46 }
47
jvanvertha8d0d6c2016-05-05 12:32:03 -070048 virtual GrBackendContext getBackendContext() = 0;
Greg Daniel02611d92017-07-25 10:05:01 -040049 GrContext* getGrContext() const { return fContext.get(); }
jvanverthaf236b52016-05-20 06:01:06 -070050
Christopher Dalton443ec1b2017-02-24 13:22:53 -070051 int width() const { return fWidth; }
52 int height() const { return fHeight; }
csmartdalton578f0642017-02-24 16:04:47 -070053 int sampleCount() const { return fSampleCount; }
54 int stencilBits() const { return fStencilBits; }
Christopher Dalton443ec1b2017-02-24 13:22:53 -070055
jvanverthaf236b52016-05-20 06:01:06 -070056protected:
57 virtual bool isGpuContext() { return true; }
58
Greg Daniel02611d92017-07-25 10:05:01 -040059 sk_sp<GrContext> fContext;
jvanverthaf236b52016-05-20 06:01:06 -070060
61 int fWidth;
62 int fHeight;
63 DisplayParams fDisplayParams;
jvanverthaf236b52016-05-20 06:01:06 -070064 SkSurfaceProps fSurfaceProps;
csmartdalton578f0642017-02-24 16:04:47 -070065
66 // parameters obtained from the native window
67 // Note that the platform .cpp file is responsible for
68 // initializing fSampleCount and fStencilBits!
69 int fSampleCount;
70 int fStencilBits;
jvanvertha8d0d6c2016-05-05 12:32:03 -070071};
72
73} // namespace sk_app
74
75#endif