OLD | NEW |
(Empty) | |
| 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 GrTextureMaker_DEFINED |
| 9 #define GrTextureMaker_DEFINED |
| 10 |
| 11 #include "GrTextureParams.h" |
| 12 #include "GrResourceKey.h" |
| 13 |
| 14 class GrContext; |
| 15 class GrTexture; |
| 16 class GrTextureParams; |
| 17 class GrUniqueKey; |
| 18 class SkBitmap; |
| 19 |
| 20 /** |
| 21 * Different GPUs and API extensions have different requirements with respect to
what texture |
| 22 * sampling parameters may be used with textures of various types. This class fa
cilitates making |
| 23 * texture compatible with a given GrTextureParams. It abstracts the source of t
he original data |
| 24 * which may be an already existing texture, CPU pixels, a codec, ... so that va
rious sources can |
| 25 * be used with common code that scales or copies the data to make it compatible
with a |
| 26 * GrTextureParams. |
| 27 */ |
| 28 class GrTextureParamsAdjuster { |
| 29 public: |
| 30 struct CopyParams { |
| 31 GrTextureParams::FilterMode fFilter; |
| 32 int fWidth; |
| 33 int fHeight; |
| 34 }; |
| 35 |
| 36 GrTextureParamsAdjuster(int width, int height) : fWidth(width), fHeight(heig
ht) {} |
| 37 virtual ~GrTextureParamsAdjuster() {} |
| 38 |
| 39 int width() const { return fWidth; } |
| 40 int height() const { return fHeight; } |
| 41 |
| 42 /** Returns a texture that is safe for use with the params */ |
| 43 GrTexture* refTextureForParams(GrContext*, const GrTextureParams&); |
| 44 |
| 45 protected: |
| 46 /** If the original is a inherently texture that can be returned for "free"
then return it |
| 47 without ref'ing it. Otherwise, return null. */ |
| 48 virtual GrTexture* peekOriginalTexture() = 0; |
| 49 |
| 50 /** |
| 51 * Return the maker's "original" texture. It is the responsibility of the m
aker |
| 52 * to make this efficient ... if the texture is being generated, the maker
must handle |
| 53 * caching it (if desired). |
| 54 */ |
| 55 virtual GrTexture* refOriginalTexture(GrContext*) = 0; |
| 56 |
| 57 /** |
| 58 * If we need to copy the maker's original texture, the maker is asked to r
eturn a key |
| 59 * that identifies its original + the CopyParms parameter. If the maker doe
s not want to cache |
| 60 * the stretched version (e.g. the maker is volatile), this should simply r
eturn without |
| 61 * initializing the copyKey. |
| 62 */ |
| 63 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0; |
| 64 |
| 65 /** |
| 66 * Return a new (uncached) texture that is the stretch of the maker's origi
nal. |
| 67 * |
| 68 * The base-class handles general logic for this, and only needs access to
the following |
| 69 * methods: |
| 70 * - onRefOriginalTexture() |
| 71 * - onGetROBitmap() |
| 72 * |
| 73 * Subclass may override this if they can handle creating the texture more
directly than |
| 74 * by copying. |
| 75 */ |
| 76 virtual GrTexture* generateTextureForParams(GrContext*, const CopyParams&); |
| 77 |
| 78 /** |
| 79 * If a stretched version of the texture is generated, it may be cached (as
suming that |
| 80 * onMakeParamsKey() returns true). In that case, the maker is notified in
case it |
| 81 * wants to note that for when the maker is destroyed. |
| 82 */ |
| 83 virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0; |
| 84 |
| 85 /** |
| 86 * Some GPUs are unreliable w/ very small texture sizes. If we run into tha
t case, this |
| 87 * method will be called (in service of onGenerateParamsTexture) to return
a raster version |
| 88 * of the original texture. |
| 89 */ |
| 90 virtual bool getROBitmap(SkBitmap*) = 0; |
| 91 |
| 92 /** Helper for creating a key for a copy from an original key. */ |
| 93 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey, |
| 94 const CopyParams& copyParams, |
| 95 GrUniqueKey* copyKey) { |
| 96 SkASSERT(!copyKey->isValid()); |
| 97 if (origKey.isValid()) { |
| 98 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDoma
in(); |
| 99 GrUniqueKey::Builder builder(copyKey, origKey, kDomain, 3); |
| 100 builder[0] = copyParams.fFilter; |
| 101 builder[1] = copyParams.fWidth; |
| 102 builder[2] = copyParams.fHeight; |
| 103 } |
| 104 } |
| 105 |
| 106 private: |
| 107 const int fWidth; |
| 108 const int fHeight; |
| 109 }; |
| 110 |
| 111 #endif |
OLD | NEW |