blob: 2c526a4bfe0d176c35536e221021e6f39ada9d2b [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
34 virtual void resize(uint32_t w, uint32_t h) = 0;
35
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 sk_sp<SkSurface> createRenderSurface(sk_sp<GrRenderTarget>, int colorBits);
49 void presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<GrRenderTarget> rt,
50 int colorBits);
51
52protected:
53 virtual bool isGpuContext() { return true; }
54
55 GrContext* fContext;
56
57 int fWidth;
58 int fHeight;
59 DisplayParams fDisplayParams;
60 GrPixelConfig fPixelConfig;
61 SkSurfaceProps fSurfaceProps;
liyuqian74959a12016-06-16 14:10:34 -070062
63private:
64 sk_sp<SkSurface> createSurface(
65 sk_sp<GrRenderTarget>, int colorBits, bool offscreen, bool forceSRGB);
jvanvertha8d0d6c2016-05-05 12:32:03 -070066};
67
68} // namespace sk_app
69
70#endif