Flutter Engine
The Flutter Engine
WindowContext.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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
12#include "include/gpu/GrTypes.h"
14
15class GrDirectContext;
16class SkSurface;
17#if defined(SK_GRAPHITE)
18namespace skgpu::graphite {
19class Context;
20class Recorder;
21}
22#endif
23
24namespace skwindow {
25
27public:
29
30 virtual ~WindowContext();
31
33
34 void swapBuffers();
35
36 virtual bool isValid() = 0;
37
38 virtual void resize(int w, int h) = 0;
39
40 virtual void activate(bool isActive) {}
41
43 virtual void setDisplayParams(const DisplayParams& params) = 0;
44
46#if defined(SK_GRAPHITE)
47 skgpu::graphite::Context* graphiteContext() const { return fGraphiteContext.get(); }
48 skgpu::graphite::Recorder* graphiteRecorder() const { return fGraphiteRecorder.get(); }
49 void snapRecordingAndSubmit();
50#endif
51
52 int width() const { return fWidth; }
53 int height() const { return fHeight; }
54 SkISize dimensions() const { return {fWidth, fHeight}; }
55 int sampleCount() const { return fSampleCount; }
56 int stencilBits() const { return fStencilBits; }
57
58protected:
59 virtual bool isGpuContext() { return true; }
60
61 virtual void onSwapBuffers() = 0;
62
64#if defined(SK_GRAPHITE)
65 std::unique_ptr<skgpu::graphite::Context> fGraphiteContext;
66 std::unique_ptr<skgpu::graphite::Recorder> fGraphiteRecorder;
67#endif
68
69 int fWidth;
72
73 // parameters obtained from the native window
74 // Note that the platform .cpp file is responsible for
75 // initializing fSampleCount and fStencilBits!
76 int fSampleCount = 1;
77 int fStencilBits = 0;
78};
79
80} // namespace skwindow
81
82#endif
T * get() const
Definition: SkRefCnt.h:303
sk_sp< GrDirectContext > fContext
Definition: WindowContext.h:63
virtual bool isValid()=0
DisplayParams fDisplayParams
Definition: WindowContext.h:71
virtual sk_sp< SkSurface > getBackbufferSurface()=0
virtual void setDisplayParams(const DisplayParams &params)=0
const DisplayParams & getDisplayParams()
Definition: WindowContext.h:42
WindowContext(const DisplayParams &)
SkISize dimensions() const
Definition: WindowContext.h:54
virtual bool isGpuContext()
Definition: WindowContext.h:59
GrDirectContext * directContext() const
Definition: WindowContext.h:45
virtual void resize(int w, int h)=0
virtual void onSwapBuffers()=0
virtual void activate(bool isActive)
Definition: WindowContext.h:40
const EmbeddedViewParams * params
SkScalar w
SkScalar h
Definition: SkSize.h:16