blob: fdd847445c25df03d250f10d96f34fe71c03b5fe [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
47 sk_sp<SkSurface> createRenderSurface(sk_sp<GrRenderTarget>, int colorBits);
48 void presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<GrRenderTarget> rt,
49 int colorBits);
50
51protected:
52 virtual bool isGpuContext() { return true; }
53
54 GrContext* fContext;
55
56 int fWidth;
57 int fHeight;
58 DisplayParams fDisplayParams;
59 GrPixelConfig fPixelConfig;
60 SkSurfaceProps fSurfaceProps;
jvanvertha8d0d6c2016-05-05 12:32:03 -070061};
62
63} // namespace sk_app
64
65#endif