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/GrTexture.h" 13 #include "include/private/GrGLTypesPriv.h" 14 #include "src/gpu/GrGpu.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 GrPixelConfig fConfig = kUnknown_GrPixelConfig; 27 GrBackendObjectOwnership fOwnership = GrBackendObjectOwnership::kOwned; 28 }; 29 30 static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget); 31 32 GrGLTexture(GrGLGpu*, SkBudgeted, const Desc&, GrMipMapsStatus); 33 ~GrGLTexture()34 ~GrGLTexture() override {} 35 36 GrBackendTexture getBackendTexture() const override; 37 38 GrBackendFormat backendFormat() const override; 39 40 // TODO: Remove once clients are no longer calling this. textureParamsModified()41 void textureParamsModified() override { fParameters->invalidate(); } 42 parameters()43 GrGLTextureParameters* parameters() { return fParameters.get(); } 44 textureID()45 GrGLuint textureID() const { return fID; } 46 47 GrGLenum target() const; 48 format()49 GrGLFormat format() const { return fFormat; } 50 hasBaseLevelBeenBoundToFBO()51 bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; } baseLevelWasBoundToFBO()52 void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; } 53 54 static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, 55 GrMipMapsStatus, 56 const Desc&, 57 sk_sp<GrGLTextureParameters>, 58 GrWrapCacheable, GrIOType); 59 60 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; 61 62 protected: 63 // Constructor for subclasses. 64 GrGLTexture(GrGLGpu*, const Desc&, sk_sp<GrGLTextureParameters>, GrMipMapsStatus); 65 66 // Constructor for instances wrapping backend objects. 67 GrGLTexture(GrGLGpu*, 68 const Desc&, 69 GrMipMapsStatus, 70 sk_sp<GrGLTextureParameters>, 71 GrWrapCacheable, 72 GrIOType); 73 74 void init(const Desc&); 75 76 void onAbandon() override; 77 void onRelease() override; 78 79 bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override; 80 81 private: 82 sk_sp<GrGLTextureParameters> fParameters; 83 GrGLuint fID; 84 GrGLFormat fFormat; 85 GrBackendObjectOwnership fTextureIDOwnership; 86 bool fBaseLevelHasBeenBoundToFBO = false; 87 88 typedef GrTexture INHERITED; 89 }; 90 91 #endif 92