2019-01-30 18:08:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrContext_Base_DEFINED
|
|
|
|
#define GrContext_Base_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
2019-08-13 20:16:42 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
|
|
|
#include "include/gpu/GrTypes.h"
|
2019-01-30 18:08:28 +00:00
|
|
|
|
|
|
|
class GrBaseContextPriv;
|
2019-02-04 22:50:57 +00:00
|
|
|
class GrCaps;
|
2020-06-02 15:23:16 +00:00
|
|
|
class GrContextThreadSafeProxy;
|
2020-06-30 17:28:00 +00:00
|
|
|
class GrDirectContext;
|
2019-01-30 18:08:28 +00:00
|
|
|
class GrImageContext;
|
|
|
|
class GrRecordingContext;
|
|
|
|
|
2019-08-21 19:21:09 +00:00
|
|
|
class GrContext_Base : public SkRefCnt {
|
2019-01-30 18:08:28 +00:00
|
|
|
public:
|
2020-07-21 21:03:56 +00:00
|
|
|
~GrContext_Base() override;
|
2019-01-30 18:08:28 +00:00
|
|
|
|
2020-07-01 15:11:18 +00:00
|
|
|
/*
|
|
|
|
* Safely downcast to a GrDirectContext.
|
|
|
|
*/
|
|
|
|
virtual GrDirectContext* asDirectContext() { return nullptr; }
|
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
/*
|
|
|
|
* The 3D API backing this context
|
|
|
|
*/
|
2020-06-02 15:23:16 +00:00
|
|
|
SK_API GrBackendApi backend() const;
|
2019-01-30 18:08:28 +00:00
|
|
|
|
2019-08-13 20:16:42 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the default GrBackendFormat for a given SkColorType and renderability.
|
|
|
|
* It is guaranteed that this backend format will be the one used by the GrContext
|
|
|
|
* SkColorType and SkSurfaceCharacterization-based createBackendTexture methods.
|
|
|
|
*
|
|
|
|
* The caller should check that the returned format is valid.
|
|
|
|
*/
|
2019-08-21 19:21:09 +00:00
|
|
|
SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const;
|
2019-08-13 20:16:42 +00:00
|
|
|
|
2019-12-17 19:44:37 +00:00
|
|
|
SK_API GrBackendFormat compressedBackendFormat(SkImage::CompressionType) const;
|
|
|
|
|
2020-06-02 15:23:16 +00:00
|
|
|
// TODO: When the public version is gone, rename to refThreadSafeProxy and add raw ptr ver.
|
|
|
|
sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
|
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
// Provides access to functions that aren't part of the public API.
|
|
|
|
GrBaseContextPriv priv();
|
2020-08-07 17:05:14 +00:00
|
|
|
const GrBaseContextPriv priv() const; // NOLINT(readability-const-return-type)
|
2019-01-30 18:08:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class GrBaseContextPriv; // for hidden functions
|
|
|
|
|
2020-06-02 15:23:16 +00:00
|
|
|
GrContext_Base(sk_sp<GrContextThreadSafeProxy>);
|
2019-01-30 18:08:28 +00:00
|
|
|
|
2020-06-02 15:23:16 +00:00
|
|
|
virtual bool init();
|
2019-02-14 19:49:02 +00:00
|
|
|
|
2019-02-01 15:19:42 +00:00
|
|
|
/**
|
|
|
|
* An identifier for this context. The id is used by all compatible contexts. For example,
|
|
|
|
* if SkImages are created on one thread using an image creation context, then fed into a
|
|
|
|
* DDL Recorder on second thread (which has a recording context) and finally replayed on
|
|
|
|
* a third thread with a direct context, then all three contexts will report the same id.
|
|
|
|
* It is an error for an image to be used with contexts that report different ids.
|
|
|
|
*/
|
2020-06-02 15:23:16 +00:00
|
|
|
uint32_t contextID() const;
|
2019-02-01 15:19:42 +00:00
|
|
|
|
2019-02-07 18:25:07 +00:00
|
|
|
bool matches(GrContext_Base* candidate) const {
|
2020-07-10 18:33:22 +00:00
|
|
|
return candidate && candidate->contextID() == this->contextID();
|
2019-02-07 18:25:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 17:05:37 +00:00
|
|
|
/*
|
|
|
|
* The options in effect for this context
|
|
|
|
*/
|
2020-06-02 15:23:16 +00:00
|
|
|
const GrContextOptions& options() const;
|
2019-02-04 17:05:37 +00:00
|
|
|
|
2019-02-04 22:50:57 +00:00
|
|
|
const GrCaps* caps() const;
|
|
|
|
sk_sp<const GrCaps> refCaps() const;
|
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
virtual GrImageContext* asImageContext() { return nullptr; }
|
|
|
|
virtual GrRecordingContext* asRecordingContext() { return nullptr; }
|
2020-06-01 14:11:49 +00:00
|
|
|
|
|
|
|
sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy;
|
2019-01-30 18:08:28 +00:00
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = SkRefCnt;
|
2019-01-30 18:08:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|