• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/gpu/ganesh/GrGLTypesPriv.h"
13 #include "src/gpu/ganesh/GrGpu.h"
14 #include "src/gpu/ganesh/GrTexture.h"
15 #include "src/gpu/ganesh/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*, skgpu::Budgeted, const Desc&, GrMipmapStatus, std::string_view label);
32 
~GrGLTexture()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.
textureParamsModified()40     void textureParamsModified() override { fParameters->invalidate(); }
41 
parameters()42     GrGLTextureParameters* parameters() { return fParameters.get(); }
43 
textureID()44     GrGLuint textureID() const { return fID; }
45 
46     GrGLenum target() const;
47 
format()48     GrGLFormat format() const { return fFormat; }
49 
hasBaseLevelBeenBoundToFBO()50     bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; }
baseLevelWasBoundToFBO()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                                           std::string_view label);
59 
60     void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
61 
62 protected:
63     // Constructor for subclasses.
64     GrGLTexture(GrGLGpu*,
65                 const Desc&,
66                 sk_sp<GrGLTextureParameters>,
67                 GrMipmapStatus,
68                 std::string_view label);
69 
70     // Constructor for instances wrapping backend objects.
71     GrGLTexture(GrGLGpu*,
72                 const Desc&,
73                 GrMipmapStatus,
74                 sk_sp<GrGLTextureParameters>,
75                 GrWrapCacheable,
76                 GrIOType,
77                 std::string_view label);
78 
79     void init(const Desc&);
80 
81     void onAbandon() override;
82     void onRelease() override;
83 
84     bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override;
85 
86     void onSetLabel() override;
87 
88 private:
89     sk_sp<GrGLTextureParameters> fParameters;
90     GrGLuint fID;
91     GrGLFormat fFormat;
92     GrBackendObjectOwnership fTextureIDOwnership;
93     bool fBaseLevelHasBeenBoundToFBO = false;
94 
95     using INHERITED = GrTexture;
96 };
97 
98 #endif
99