blob: f63009c349254d5540544331d8255a77af0dadf9 [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"
jvanvertha8d0d6c2016-05-05 12:32:03 -070011#include "GrTypes.h"
jvanverthaf236b52016-05-20 06:01:06 -070012#include "SkRefCnt.h"
13#include "SkSurfaceProps.h"
jvanvertha8d0d6c2016-05-05 12:32:03 -070014
jvanverthaf236b52016-05-20 06:01:06 -070015class GrContext;
jvanvertha8d0d6c2016-05-05 12:32:03 -070016class 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:
jvanverthaf236b52016-05-20 06:01:06 -070023 WindowContext() : fContext(nullptr)
24 , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) {}
25
jvanvertha8d0d6c2016-05-05 12:32:03 -070026 virtual ~WindowContext() {}
27
jvanverthaf236b52016-05-20 06:01:06 -070028 virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
jvanvertha8d0d6c2016-05-05 12:32:03 -070029
30 virtual void swapBuffers() = 0;
31
jvanvertha8d0d6c2016-05-05 12:32:03 -070032 virtual bool isValid() = 0;
33
bsalomonccde4ab2016-07-27 08:50:12 -070034 virtual void resize(int w, int h) = 0;
jvanvertha8d0d6c2016-05-05 12:32:03 -070035
jvanverthaf236b52016-05-20 06:01:06 -070036 const DisplayParams& getDisplayParams() { return fDisplayParams; }
brianosman05de2162016-05-06 13:28:57 -070037 virtual void setDisplayParams(const DisplayParams& params) = 0;
38
jvanverthaf236b52016-05-20 06:01:06 -070039 SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
40 void setSurfaceProps(const SkSurfaceProps& props) {
41 fSurfaceProps = props;
42 }
43
jvanvertha8d0d6c2016-05-05 12:32:03 -070044 virtual GrBackendContext getBackendContext() = 0;
djsollen7e731082016-06-09 13:07:13 -070045 GrContext* getGrContext() const { return fContext; }
jvanverthaf236b52016-05-20 06:01:06 -070046
liyuqian74959a12016-06-16 14:10:34 -070047 sk_sp<SkSurface> createOffscreenSurface(bool sRGB);
jvanverthaf236b52016-05-20 06:01:06 -070048 void presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<GrRenderTarget> rt,
49 int colorBits);
50
51protected:
52 virtual bool isGpuContext() { return true; }
53
bsalomonc7b4b282016-07-19 09:46:29 -070054 sk_sp<SkSurface> createRenderSurface(GrBackendRenderTargetDesc, int colorBits);
55
jvanverthaf236b52016-05-20 06:01:06 -070056 GrContext* fContext;
57
58 int fWidth;
59 int fHeight;
60 DisplayParams fDisplayParams;
61 GrPixelConfig fPixelConfig;
62 SkSurfaceProps fSurfaceProps;
liyuqian74959a12016-06-16 14:10:34 -070063
64private:
65 sk_sp<SkSurface> createSurface(
bsalomonc7b4b282016-07-19 09:46:29 -070066 GrBackendRenderTargetDesc*, int colorBits, bool offscreen, bool forceSRGB);
jvanvertha8d0d6c2016-05-05 12:32:03 -070067};
68
69} // namespace sk_app
70
71#endif