2016-05-05 19:32:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#ifndef WindowContext_DEFINED
|
|
|
|
#define WindowContext_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSurfaceProps.h"
|
|
|
|
#include "include/gpu/GrTypes.h"
|
|
|
|
#include "tools/sk_app/DisplayParams.h"
|
2016-05-05 19:32:03 +00:00
|
|
|
|
2020-07-10 17:55:21 +00:00
|
|
|
class GrDirectContext;
|
2016-05-05 19:32:03 +00:00
|
|
|
class SkSurface;
|
2021-09-30 20:27:30 +00:00
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
|
|
|
namespace skgpu {
|
|
|
|
class Context;
|
2022-01-14 18:41:29 +00:00
|
|
|
class Recorder;
|
2021-09-30 20:27:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-05-05 19:32:03 +00:00
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
|
|
|
|
class WindowContext {
|
|
|
|
public:
|
2020-07-10 17:55:21 +00:00
|
|
|
WindowContext(const DisplayParams&);
|
2016-05-20 13:01:06 +00:00
|
|
|
|
2020-07-10 17:55:21 +00:00
|
|
|
virtual ~WindowContext();
|
2016-05-05 19:32:03 +00:00
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
|
2016-05-05 19:32:03 +00:00
|
|
|
|
|
|
|
virtual void swapBuffers() = 0;
|
|
|
|
|
|
|
|
virtual bool isValid() = 0;
|
|
|
|
|
2016-07-27 15:50:12 +00:00
|
|
|
virtual void resize(int w, int h) = 0;
|
2016-05-05 19:32:03 +00:00
|
|
|
|
2020-11-16 16:06:58 +00:00
|
|
|
virtual void activate(bool isActive) {}
|
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
const DisplayParams& getDisplayParams() { return fDisplayParams; }
|
2016-05-06 20:28:57 +00:00
|
|
|
virtual void setDisplayParams(const DisplayParams& params) = 0;
|
|
|
|
|
2020-07-10 17:55:21 +00:00
|
|
|
GrDirectContext* directContext() const { return fContext.get(); }
|
2021-09-30 20:27:30 +00:00
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
|
|
|
skgpu::Context* graphiteContext() const { return fGraphiteContext.get(); }
|
2022-01-14 18:41:29 +00:00
|
|
|
skgpu::Recorder* graphiteRecorder() const { return fGraphiteRecorder.get(); }
|
2021-09-30 20:27:30 +00:00
|
|
|
#endif
|
2016-05-20 13:01:06 +00:00
|
|
|
|
2017-02-24 20:22:53 +00:00
|
|
|
int width() const { return fWidth; }
|
|
|
|
int height() const { return fHeight; }
|
2022-01-14 18:41:29 +00:00
|
|
|
SkISize dimensions() const { return {fWidth, fHeight}; }
|
2017-02-24 23:04:47 +00:00
|
|
|
int sampleCount() const { return fSampleCount; }
|
|
|
|
int stencilBits() const { return fStencilBits; }
|
2017-02-24 20:22:53 +00:00
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
protected:
|
|
|
|
virtual bool isGpuContext() { return true; }
|
|
|
|
|
2020-07-10 17:55:21 +00:00
|
|
|
sk_sp<GrDirectContext> fContext;
|
2021-09-30 20:27:30 +00:00
|
|
|
#if SK_GRAPHITE_ENABLED
|
|
|
|
sk_sp<skgpu::Context> fGraphiteContext;
|
2022-01-14 18:41:29 +00:00
|
|
|
std::unique_ptr<skgpu::Recorder> fGraphiteRecorder;
|
2021-09-30 20:27:30 +00:00
|
|
|
#endif
|
2016-05-20 13:01:06 +00:00
|
|
|
|
|
|
|
int fWidth;
|
|
|
|
int fHeight;
|
|
|
|
DisplayParams fDisplayParams;
|
2017-02-24 23:04:47 +00:00
|
|
|
|
|
|
|
// parameters obtained from the native window
|
|
|
|
// Note that the platform .cpp file is responsible for
|
|
|
|
// initializing fSampleCount and fStencilBits!
|
2021-09-30 20:27:30 +00:00
|
|
|
int fSampleCount = 1;
|
|
|
|
int fStencilBits = 0;
|
2016-05-05 19:32:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sk_app
|
|
|
|
|
|
|
|
#endif
|