Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrTextureProvider.h
1 /*
2  * Copyright 2015 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 #ifndef GrTextureProvider_DEFINED
9 #define GrTextureProvider_DEFINED
10 
11 #include "GrTexture.h"
12 #include "GrTypes.h"
13 
14 class GrSingleOwner;
15 
16 class SK_API GrTextureProvider {
17 public:
19  // Textures
20 
30  GrTexture* createMipMappedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
31  const GrMipLevel* texels, int mipLevelCount);
32 
42  GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const void* srcData,
43  size_t rowBytes);
44 
46  GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted) {
47  return this->createTexture(desc, budgeted, nullptr, 0);
48  }
49 
52  void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) {
53  this->assignUniqueKeyToResource(key, texture);
54  }
55 
57  GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key);
58 
64  bool existsTextureWithUniqueKey(const GrUniqueKey& key) const {
65  return this->existsResourceWithUniqueKey(key);
66  }
67 
75  GrTexture* createApproxTexture(const GrSurfaceDesc&);
76 
79  kExact_ScratchTexMatch,
80  kApprox_ScratchTexMatch
81  };
82  GrTexture* refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMatch match) {
83  if (kApprox_ScratchTexMatch == match) {
84  return this->createApproxTexture(desc);
85  } else {
86  return this->createTexture(desc, SkBudgeted::kYes);
87  }
88  }
89 
91  // Wrapped Backend Surfaces
92 
101  GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc,
102  GrWrapOwnership = kBorrow_GrWrapOwnership);
103 
113  GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc);
114 
115 protected:
116  GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* singleOwner);
117 
122  void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*);
123 
129  GrGpuResource* findAndRefResourceByUniqueKey(const GrUniqueKey&);
130 
136  bool existsResourceWithUniqueKey(const GrUniqueKey& key) const;
137 
138  enum ScratchTextureFlags {
139  kExact_ScratchTextureFlag = 0x1,
140  kNoPendingIO_ScratchTextureFlag = 0x2, // (http://skbug.com/4156)
141  kNoCreate_ScratchTextureFlag = 0x4,
142  };
143 
145  GrTexture* internalCreateApproxTexture(const GrSurfaceDesc& desc, uint32_t scratchTextureFlags);
146 
147  GrTexture* refScratchTexture(const GrSurfaceDesc&, uint32_t scratchTextureFlags);
148 
149  void abandon() {
150  fCache = NULL;
151  fGpu = NULL;
152  }
153 
154  GrResourceCache* cache() { return fCache; }
155  const GrResourceCache* cache() const { return fCache; }
156 
157  GrGpu* gpu() { return fGpu; }
158  const GrGpu* gpu() const { return fGpu; }
159 
160  bool isAbandoned() const {
161  SkASSERT(SkToBool(fGpu) == SkToBool(fCache));
162  return !SkToBool(fCache);
163  }
164 
165 private:
166  GrResourceCache* fCache;
167  GrGpu* fGpu;
168 
169  // In debug builds we guard against improper thread handling
170  SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
171 };
172 
173 #endif
ScratchTexMatch
Legacy function that no longer should be used.
Definition: GrTextureProvider.h:78
Base class for objects that can be kept in the GrResourceCache.
Definition: GrGpuResource.h:140
Definition: GrTypes.h:557
Describes a surface to be created.
Definition: GrTypes.h:467
Definition: GrTextureProvider.h:16
bool existsTextureWithUniqueKey(const GrUniqueKey &key) const
Determines whether a texture is associated with the unique key.
Definition: GrTextureProvider.h:64
A key that allows for exclusive use of a resource for a use case (AKA "domain").
Definition: GrResourceKey.h:220
Gr can wrap an existing render target created by the client in the 3D API with a GrRenderTarget objec...
Definition: GrTypes.h:588
GrTexture * createTexture(const GrSurfaceDesc &desc, SkBudgeted budgeted)
Shortcut for creating a texture with no initial data to upload.
Definition: GrTextureProvider.h:46
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
void assignUniqueKeyToTexture(const GrUniqueKey &key, GrTexture *texture)
Assigns a unique key to the texture.
Definition: GrTextureProvider.h:52
Definition: GrTypes.h:459
GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
Definition: GrRenderTarget.h:26
Definition: GrTexture.h:19