| 1 | /* | 
|---|
| 2 | * Copyright 2011 Google Inc. | 
|---|
| 3 | * | 
|---|
| 4 | * Use of this source code is governed by a BSD-style license that can be | 
|---|
| 5 | * found in the LICENSE file. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef GrGLTexture_DEFINED | 
|---|
| 10 | #define GrGLTexture_DEFINED | 
|---|
| 11 |  | 
|---|
| 12 | #include "include/private/GrGLTypesPriv.h" | 
|---|
| 13 | #include "src/gpu/GrGpu.h" | 
|---|
| 14 | #include "src/gpu/GrTexture.h" | 
|---|
| 15 | #include "src/gpu/gl/GrGLUtil.h" | 
|---|
| 16 |  | 
|---|
| 17 | class GrGLGpu; | 
|---|
| 18 |  | 
|---|
| 19 | class GrGLTexture : public GrTexture { | 
|---|
| 20 | public: | 
|---|
| 21 | struct Desc { | 
|---|
| 22 | SkISize fSize                       = {-1, -1}; | 
|---|
| 23 | GrGLenum fTarget                    = 0; | 
|---|
| 24 | GrGLuint fID                        = 0; | 
|---|
| 25 | GrGLFormat fFormat                  = GrGLFormat::kUnknown; | 
|---|
| 26 | GrBackendObjectOwnership fOwnership = GrBackendObjectOwnership::kOwned; | 
|---|
| 27 | }; | 
|---|
| 28 |  | 
|---|
| 29 | static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget); | 
|---|
| 30 |  | 
|---|
| 31 | GrGLTexture(GrGLGpu*, SkBudgeted, const Desc&, GrMipmapStatus); | 
|---|
| 32 |  | 
|---|
| 33 | ~GrGLTexture() override {} | 
|---|
| 34 |  | 
|---|
| 35 | GrBackendTexture getBackendTexture() const override; | 
|---|
| 36 |  | 
|---|
| 37 | GrBackendFormat backendFormat() const override; | 
|---|
| 38 |  | 
|---|
| 39 | // TODO: Remove once clients are no longer calling this. | 
|---|
| 40 | void textureParamsModified() override { fParameters->invalidate(); } | 
|---|
| 41 |  | 
|---|
| 42 | GrGLTextureParameters* parameters() { return fParameters.get(); } | 
|---|
| 43 |  | 
|---|
| 44 | GrGLuint textureID() const { return fID; } | 
|---|
| 45 |  | 
|---|
| 46 | GrGLenum target() const; | 
|---|
| 47 |  | 
|---|
| 48 | GrGLFormat format() const { return fFormat; } | 
|---|
| 49 |  | 
|---|
| 50 | bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; } | 
|---|
| 51 | void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; } | 
|---|
| 52 |  | 
|---|
| 53 | static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, | 
|---|
| 54 | GrMipmapStatus, | 
|---|
| 55 | const Desc&, | 
|---|
| 56 | sk_sp<GrGLTextureParameters>, | 
|---|
| 57 | GrWrapCacheable, GrIOType); | 
|---|
| 58 |  | 
|---|
| 59 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; | 
|---|
| 60 |  | 
|---|
| 61 | protected: | 
|---|
| 62 | // Constructor for subclasses. | 
|---|
| 63 | GrGLTexture(GrGLGpu*, const Desc&, sk_sp<GrGLTextureParameters>, GrMipmapStatus); | 
|---|
| 64 |  | 
|---|
| 65 | // Constructor for instances wrapping backend objects. | 
|---|
| 66 | GrGLTexture(GrGLGpu*, | 
|---|
| 67 | const Desc&, | 
|---|
| 68 | GrMipmapStatus, | 
|---|
| 69 | sk_sp<GrGLTextureParameters>, | 
|---|
| 70 | GrWrapCacheable, | 
|---|
| 71 | GrIOType); | 
|---|
| 72 |  | 
|---|
| 73 | void init(const Desc&); | 
|---|
| 74 |  | 
|---|
| 75 | void onAbandon() override; | 
|---|
| 76 | void onRelease() override; | 
|---|
| 77 |  | 
|---|
| 78 | bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override; | 
|---|
| 79 |  | 
|---|
| 80 | private: | 
|---|
| 81 | sk_sp<GrGLTextureParameters> fParameters; | 
|---|
| 82 | GrGLuint fID; | 
|---|
| 83 | GrGLFormat fFormat; | 
|---|
| 84 | GrBackendObjectOwnership fTextureIDOwnership; | 
|---|
| 85 | bool fBaseLevelHasBeenBoundToFBO = false; | 
|---|
| 86 |  | 
|---|
| 87 | typedef GrTexture INHERITED; | 
|---|
| 88 | }; | 
|---|
| 89 |  | 
|---|
| 90 | #endif | 
|---|
| 91 |  | 
|---|