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
|
|
|
|
|
2017-10-12 19:44:50 +00:00
|
|
|
#include "GrBackendSurface.h"
|
2017-09-07 16:36:34 +00:00
|
|
|
#include "GrSamplerState.h"
|
2012-06-21 21:09:06 +00:00
|
|
|
#include "GrSurface.h"
|
2017-10-12 19:44:50 +00:00
|
|
|
#include "SkImage.h"
|
2014-07-25 14:32:33 +00:00
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkRefCnt.h"
|
2017-10-12 15:23:36 +00:00
|
|
|
#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
|
|
|
|
2014-11-03 16:47:23 +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
|
|
|
*/
|
2014-05-09 20:46:48 +00:00
|
|
|
virtual void textureParamsModified() = 0;
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static bool StealBackendTexture(sk_sp<GrTexture>&&,
|
|
|
|
GrBackendTexture*,
|
|
|
|
SkImage::BackendTextureReleaseProc*);
|
|
|
|
|
2013-08-28 14:17:03 +00:00
|
|
|
#ifdef SK_DEBUG
|
2010-12-22 21:39:39 +00:00
|
|
|
void validate() const {
|
|
|
|
this->INHERITED::validate();
|
|
|
|
}
|
|
|
|
#endif
|
2013-10-02 16:42:21 +00:00
|
|
|
|
2018-01-30 14:28:44 +00:00
|
|
|
virtual void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) = 0;
|
|
|
|
|
|
|
|
// These match the definitions in SkImage, from whence they came.
|
|
|
|
// TODO: Either move Chrome over to new api or remove their need to call this on GrTexture
|
2017-04-21 15:52:27 +00:00
|
|
|
typedef void* ReleaseCtx;
|
|
|
|
typedef void (*ReleaseProc)(ReleaseCtx);
|
2018-01-30 14:28:44 +00:00
|
|
|
void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
|
|
|
|
sk_sp<GrReleaseProcHelper> helper(new GrReleaseProcHelper(proc, ctx));
|
|
|
|
this->setRelease(std::move(helper));
|
|
|
|
}
|
2017-04-21 15:52:27 +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:
|
2016-11-07 14:53:44 +00:00
|
|
|
GrTexture(GrGpu*, const GrSurfaceDesc&, GrSLType samplerType,
|
2017-10-12 15:23:36 +00:00
|
|
|
GrSamplerState::Filter highestFilterMode, GrMipMapsStatus);
|
2014-05-09 20:46:48 +00:00
|
|
|
|
2017-10-12 19:44:50 +00:00
|
|
|
virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0;
|
|
|
|
|
2014-05-09 17:37:55 +00:00
|
|
|
private:
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
void computeScratchKey(GrScratchKey*) const override;
|
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
|
|
|
|
2016-11-08 22:08:54 +00:00
|
|
|
GrSLType fSamplerType;
|
2017-09-07 16:36:34 +00:00
|
|
|
GrSamplerState::Filter fHighestFilterMode;
|
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
|