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/gpu/ganesh/SkImageGanesh.h" 13 #include "src/gpu/ganesh/GrGpu.h" 14 #include "src/gpu/ganesh/GrTexture.h" 15 #include "src/gpu/ganesh/gl/GrGLTypesPriv.h" 16 #include "src/gpu/ganesh/gl/GrGLUtil.h" 17 18 class GrGLGpu; 19 20 class GrGLTexture : public GrTexture { 21 public: 22 struct Desc { 23 SkISize fSize = {-1, -1}; 24 GrGLenum fTarget = 0; 25 GrGLuint fID = 0; 26 GrGLFormat fFormat = GrGLFormat::kUnknown; 27 GrBackendObjectOwnership fOwnership = GrBackendObjectOwnership::kOwned; 28 skgpu::Protected fIsProtected = skgpu::Protected::kNo; 29 }; 30 31 static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget); 32 33 GrGLTexture(GrGLGpu*, skgpu::Budgeted, const Desc&, GrMipmapStatus, std::string_view label); 34 ~GrGLTexture()35 ~GrGLTexture() override {} 36 37 GrBackendTexture getBackendTexture() const override; 38 39 GrBackendFormat backendFormat() const override; 40 41 // TODO: Remove once clients are no longer calling this. textureParamsModified()42 void textureParamsModified() override { fParameters->invalidate(); } 43 parameters()44 GrGLTextureParameters* parameters() { return fParameters.get(); } 45 textureID()46 GrGLuint textureID() const { return fID; } 47 48 GrGLenum target() const; 49 format()50 GrGLFormat format() const { return fFormat; } 51 hasBaseLevelBeenBoundToFBO()52 bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; } baseLevelWasBoundToFBO()53 void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; } 54 55 static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, 56 GrMipmapStatus, 57 const Desc&, 58 sk_sp<GrGLTextureParameters>, 59 GrWrapCacheable, GrIOType, 60 std::string_view label); 61 62 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; 63 64 protected: 65 // Constructor for subclasses. 66 GrGLTexture(GrGLGpu*, 67 const Desc&, 68 sk_sp<GrGLTextureParameters>, 69 GrMipmapStatus, 70 std::string_view label); 71 72 // Constructor for instances wrapping backend objects. 73 GrGLTexture(GrGLGpu*, 74 const Desc&, 75 GrMipmapStatus, 76 sk_sp<GrGLTextureParameters>, 77 GrWrapCacheable, 78 GrIOType, 79 std::string_view label); 80 81 void init(const Desc&); 82 83 void onAbandon() override; 84 void onRelease() override; 85 86 bool onStealBackendTexture(GrBackendTexture*, SkImages::BackendTextureReleaseProc*) override; 87 88 void onSetLabel() override; 89 90 private: 91 sk_sp<GrGLTextureParameters> fParameters; 92 GrGLuint fID; 93 GrGLFormat fFormat; 94 GrBackendObjectOwnership fTextureIDOwnership; 95 bool fBaseLevelHasBeenBoundToFBO = false; 96 97 using INHERITED = GrTexture; 98 }; 99 100 #endif 101