skia2/tools/sk_app/WindowContext.h
Greg Daniel 9a7acd43c4 [graphite] Make Context no longer ref counted.
Bug: skia:12794
Change-Id: I445144f25e9573d0d9ec55d12c3a9d372772c3bd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/503348
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2022-02-03 17:18:40 +00:00

80 lines
2.0 KiB
C++

/*
* 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
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurfaceProps.h"
#include "include/gpu/GrTypes.h"
#include "tools/sk_app/DisplayParams.h"
class GrDirectContext;
class SkSurface;
#ifdef SK_GRAPHITE_ENABLED
namespace skgpu {
class Context;
class Recorder;
}
#endif
namespace sk_app {
class WindowContext {
public:
WindowContext(const DisplayParams&);
virtual ~WindowContext();
virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
virtual void swapBuffers() = 0;
virtual bool isValid() = 0;
virtual void resize(int w, int h) = 0;
virtual void activate(bool isActive) {}
const DisplayParams& getDisplayParams() { return fDisplayParams; }
virtual void setDisplayParams(const DisplayParams& params) = 0;
GrDirectContext* directContext() const { return fContext.get(); }
#ifdef SK_GRAPHITE_ENABLED
skgpu::Context* graphiteContext() const { return fGraphiteContext.get(); }
skgpu::Recorder* graphiteRecorder() const { return fGraphiteRecorder.get(); }
#endif
int width() const { return fWidth; }
int height() const { return fHeight; }
SkISize dimensions() const { return {fWidth, fHeight}; }
int sampleCount() const { return fSampleCount; }
int stencilBits() const { return fStencilBits; }
protected:
virtual bool isGpuContext() { return true; }
sk_sp<GrDirectContext> fContext;
#if SK_GRAPHITE_ENABLED
std::unique_ptr<skgpu::Context> fGraphiteContext;
std::unique_ptr<skgpu::Recorder> fGraphiteRecorder;
#endif
int fWidth;
int fHeight;
DisplayParams fDisplayParams;
// parameters obtained from the native window
// Note that the platform .cpp file is responsible for
// initializing fSampleCount and fStencilBits!
int fSampleCount = 1;
int fStencilBits = 0;
};
} // namespace sk_app
#endif