• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2011 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #ifndef GrTexture_DEFINED
10 #define GrTexture_DEFINED
11 
12 #include "GrBackendSurface.h"
13 #include "GrSamplerState.h"
14 #include "GrSurface.h"
15 #include "SkImage.h"
16 #include "SkPoint.h"
17 #include "SkRefCnt.h"
18 #include "../private/GrTypesPriv.h"
19 
20 class GrTexturePriv;
21 
22 class SK_API GrTexture : virtual public GrSurface {
23 public:
asTexture()24     GrTexture* asTexture() override { return this; }
asTexture()25     const GrTexture* asTexture() const override { return this; }
26 
27     virtual GrBackendTexture getBackendTexture() const = 0;
28 
29     /**
30      * This function indicates that the texture parameters (wrap mode, filtering, ...) have been
31      * changed externally to Skia.
32      */
33     virtual void textureParamsModified() = 0;
34 
35     /**
36      * This function steals the backend texture from a uniquely owned GrTexture with no pending
37      * IO, passing it out to the caller. The GrTexture is deleted in the process.
38      *
39      * Note that if the GrTexture is not uniquely owned (no other refs), or has pending IO, this
40      * function will fail.
41      */
42     static bool StealBackendTexture(sk_sp<GrTexture>,
43                                     GrBackendTexture*,
44                                     SkImage::BackendTextureReleaseProc*);
45 
46 #ifdef SK_DEBUG
validate()47     void validate() const {
48         this->INHERITED::validate();
49     }
50 #endif
51 
52     virtual void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) = 0;
53 
54     // These match the definitions in SkImage, from whence they came.
55     // TODO: Either move Chrome over to new api or remove their need to call this on GrTexture
56     typedef void* ReleaseCtx;
57     typedef void (*ReleaseProc)(ReleaseCtx);
setRelease(ReleaseProc proc,ReleaseCtx ctx)58     void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
59         sk_sp<GrReleaseProcHelper> helper(new GrReleaseProcHelper(proc, ctx));
60         this->setRelease(std::move(helper));
61     }
62 
63     /**
64      * Installs a proc on this texture. It will be called when the texture becomes "idle". Idle is
65      * defined to mean that the texture has no refs or pending IOs and that GPU I/O operations on
66      * the texture are completed if the backend API disallows deletion of a texture before such
67      * operations occur (e.g. Vulkan). After the idle proc is called it is removed. The idle proc
68      * will always be called before the texture is destroyed, even in unusual shutdown scenarios
69      * (e.g. GrContext::abandonContext()).
70      */
71     using IdleProc = void(void*);
72     virtual void setIdleProc(IdleProc, void* context) = 0;
73     virtual void* idleContext() const = 0;
74 
75     /** Access methods that are only to be used within Skia code. */
76     inline GrTexturePriv texturePriv();
77     inline const GrTexturePriv texturePriv() const;
78 
79 protected:
80     GrTexture(GrGpu*, const GrSurfaceDesc&, GrTextureType, GrMipMapsStatus);
81 
82     virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0;
83 
84 private:
85     void computeScratchKey(GrScratchKey*) const override;
86     size_t onGpuMemorySize() const override;
87     void markMipMapsDirty();
88     void markMipMapsClean();
89 
90     GrTextureType                 fTextureType;
91     GrMipMapsStatus               fMipMapsStatus;
92     int                           fMaxMipMapLevel;
93     friend class GrTexturePriv;
94 
95     typedef GrSurface INHERITED;
96 };
97 
98 #endif
99