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