2010-12-22 21:39:39 +00:00
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrTexture_DEFINED
|
|
|
|
#define GrTexture_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
|
|
#include "include/gpu/GrSurface.h"
|
|
|
|
#include "include/private/GrTypesPriv.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
class GrTexturePriv;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2019-08-22 02:08:36 +00:00
|
|
|
class GrTexture : virtual public GrSurface {
|
2010-12-22 21:39:39 +00:00
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
GrTexture* asTexture() override { return this; }
|
|
|
|
const GrTexture* asTexture() const override { return this; }
|
2011-04-05 17:08:27 +00:00
|
|
|
|
2017-12-13 20:00:45 +00:00
|
|
|
virtual GrBackendTexture getBackendTexture() const = 0;
|
|
|
|
|
2014-05-09 18:02:51 +00:00
|
|
|
/**
|
2014-05-09 20:46:48 +00:00
|
|
|
* This function indicates that the texture parameters (wrap mode, filtering, ...) have been
|
|
|
|
* changed externally to Skia.
|
2014-05-09 18:02:51 +00:00
|
|
|
*/
|
2019-08-22 02:08:36 +00:00
|
|
|
SK_API virtual void textureParamsModified() = 0;
|
2014-05-09 20:46:48 +00:00
|
|
|
|
2017-10-12 19:44:50 +00:00
|
|
|
/**
|
|
|
|
* This function steals the backend texture from a uniquely owned GrTexture with no pending
|
|
|
|
* IO, passing it out to the caller. The GrTexture is deleted in the process.
|
2018-01-30 14:28:44 +00:00
|
|
|
*
|
2017-10-12 19:44:50 +00:00
|
|
|
* Note that if the GrTexture is not uniquely owned (no other refs), or has pending IO, this
|
|
|
|
* function will fail.
|
|
|
|
*/
|
2019-01-24 18:08:59 +00:00
|
|
|
static bool StealBackendTexture(sk_sp<GrTexture>,
|
2017-10-12 19:44:50 +00:00
|
|
|
GrBackendTexture*,
|
|
|
|
SkImage::BackendTextureReleaseProc*);
|
|
|
|
|
2019-03-08 18:25:19 +00:00
|
|
|
/** See addIdleProc. */
|
|
|
|
enum class IdleState {
|
|
|
|
kFlushed,
|
|
|
|
kFinished
|
|
|
|
};
|
2018-12-19 20:42:06 +00:00
|
|
|
/**
|
2019-03-08 18:25:19 +00:00
|
|
|
* Installs a proc on this texture. It will be called when the texture becomes "idle". There
|
|
|
|
* are two types of idle states as indicated by IdleState. For managed backends (e.g. GL where
|
|
|
|
* a driver typically handles CPU/GPU synchronization of resource access) there is no difference
|
|
|
|
* between the two. They both mean "all work related to the resource has been flushed to the
|
|
|
|
* backend API and the texture is not owned outside the resource cache".
|
|
|
|
*
|
|
|
|
* If the API is unmanaged (e.g. Vulkan) then kFinished has the additional constraint that the
|
|
|
|
* work flushed to the GPU is finished.
|
2018-12-19 20:42:06 +00:00
|
|
|
*/
|
2019-03-08 18:25:19 +00:00
|
|
|
virtual void addIdleProc(sk_sp<GrRefCntedCallback> idleProc, IdleState) {
|
|
|
|
// This is the default implementation for the managed case where the IdleState can be
|
|
|
|
// ignored. Unmanaged backends, e.g. Vulkan, must override this to consider IdleState.
|
|
|
|
fIdleProcs.push_back(std::move(idleProc));
|
|
|
|
}
|
|
|
|
/** Helper version of addIdleProc that creates the ref-counted wrapper. */
|
|
|
|
void addIdleProc(GrRefCntedCallback::Callback callback,
|
|
|
|
GrRefCntedCallback::Context context,
|
|
|
|
IdleState state) {
|
|
|
|
this->addIdleProc(sk_make_sp<GrRefCntedCallback>(callback, context), state);
|
2019-03-04 15:25:17 +00:00
|
|
|
}
|
2018-12-19 20:42:06 +00:00
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
/** Access methods that are only to be used within Skia code. */
|
|
|
|
inline GrTexturePriv texturePriv();
|
|
|
|
inline const GrTexturePriv texturePriv() const;
|
2012-06-04 20:05:28 +00:00
|
|
|
|
2011-04-05 21:16:14 +00:00
|
|
|
protected:
|
2020-01-22 21:53:38 +00:00
|
|
|
GrTexture(GrGpu*, const SkISize&, GrProtected, GrTextureType, GrMipMapsStatus);
|
2014-05-09 20:46:48 +00:00
|
|
|
|
2017-10-12 19:44:50 +00:00
|
|
|
virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0;
|
|
|
|
|
2019-03-08 18:25:19 +00:00
|
|
|
SkTArray<sk_sp<GrRefCntedCallback>> fIdleProcs;
|
2019-03-04 15:25:17 +00:00
|
|
|
|
2019-08-30 17:13:44 +00:00
|
|
|
void willRemoveLastRef() override {
|
2019-03-08 18:25:19 +00:00
|
|
|
// We're about to be idle in the resource cache. Do our part to trigger the idle callbacks.
|
|
|
|
fIdleProcs.reset();
|
2019-03-04 15:25:17 +00:00
|
|
|
}
|
2019-09-16 17:14:47 +00:00
|
|
|
void computeScratchKey(GrScratchKey*) const override;
|
2019-03-04 15:25:17 +00:00
|
|
|
|
2014-05-09 17:37:55 +00:00
|
|
|
private:
|
2015-03-26 01:17:31 +00:00
|
|
|
size_t onGpuMemorySize() const override;
|
2017-10-12 15:23:36 +00:00
|
|
|
void markMipMapsDirty();
|
|
|
|
void markMipMapsClean();
|
2014-05-09 20:46:48 +00:00
|
|
|
|
2018-07-30 14:24:13 +00:00
|
|
|
GrTextureType fTextureType;
|
2017-10-12 15:23:36 +00:00
|
|
|
GrMipMapsStatus fMipMapsStatus;
|
2016-11-08 22:08:54 +00:00
|
|
|
int fMaxMipMapLevel;
|
2014-09-30 19:18:44 +00:00
|
|
|
friend class GrTexturePriv;
|
2014-05-09 20:46:48 +00:00
|
|
|
|
2014-09-30 19:18:44 +00:00
|
|
|
typedef GrSurface INHERITED;
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|