Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: src/gpu/GrLayerCache.h

Issue 384233002: Always have GrLayer's rect be valid (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix use of deprecated function Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrLayerCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrLayerCache_DEFINED 8 #ifndef GrLayerCache_DEFINED
9 #define GrLayerCache_DEFINED 9 #define GrLayerCache_DEFINED
10 10
11 #define USE_ATLAS 0 11 #define USE_ATLAS 0
12 12
13 #include "GrAllocPool.h" 13 #include "GrAllocPool.h"
14 #include "GrAtlas.h" 14 #include "GrAtlas.h"
15 #include "GrTHashTable.h" 15 #include "GrTHashTable.h"
16 #include "GrPictureUtils.h" 16 #include "GrPictureUtils.h"
17 #include "GrRect.h" 17 #include "GrRect.h"
18 18
19 class GrGpu; 19 class GrGpu;
20 class SkPicture; 20 class SkPicture;
21 21
22 // GrCachedLayer encapsulates the caching information for a single saveLayer. 22 // GrCachedLayer encapsulates the caching information for a single saveLayer.
23 // 23 //
24 // Atlased layers get a ref to their atlas GrTexture and 'fRect' contains 24 // Atlased layers get a ref to the backing GrTexture while non-atlased layers
25 // their absolute location in the backing texture. 25 // get a ref to the GrTexture in which they reside. In both cases 'fRect'
26 // 26 // contains the layer's extent in its texture.
27 // Non-atlased layers get a ref to the GrTexture in which they reside. Their
28 // 'fRect' will be empty.
29 // 27 //
30 // TODO: can we easily reuse the empty space in the non-atlased GrTexture's? 28 // TODO: can we easily reuse the empty space in the non-atlased GrTexture's?
31 struct GrCachedLayer { 29 struct GrCachedLayer {
32 public: 30 public:
33 GrCachedLayer(uint32_t pictureID, int layerID) { 31 GrCachedLayer(uint32_t pictureID, int layerID)
32 : fAtlased(false) {
34 fPictureID = pictureID; 33 fPictureID = pictureID;
35 fLayerID = layerID; 34 fLayerID = layerID;
36 fTexture = NULL; 35 fTexture = NULL;
37 fRect = GrIRect16::MakeEmpty(); 36 fRect = GrIRect16::MakeEmpty();
38 } 37 }
39 38
40 uint32_t pictureID() const { return fPictureID; } 39 uint32_t pictureID() const { return fPictureID; }
41 int layerID() const { return fLayerID; } 40 int layerID() const { return fLayerID; }
42 41
43 // This call takes over the caller's ref 42 // This call takes over the caller's ref
44 void setTexture(GrTexture* texture, const GrIRect16& rect) { 43 void setTexture(GrTexture* texture, const GrIRect16& rect) {
45 if (NULL != fTexture) { 44 if (NULL != fTexture) {
46 fTexture->unref(); 45 fTexture->unref();
47 } 46 }
48 47
49 fTexture = texture; // just take over caller's ref 48 fTexture = texture; // just take over caller's ref
50 fRect = rect; 49 fRect = rect;
51 } 50 }
52 GrTexture* texture() { return fTexture; } 51 GrTexture* texture() { return fTexture; }
53 const GrIRect16& rect() const { return fRect; } 52 const GrIRect16& rect() const { return fRect; }
54 53
54 void setAtlased(bool atlased) { fAtlased = atlased; }
55 bool isAtlased() const { return fAtlased; }
56
57 SkDEBUGCODE(void validate(GrTexture* backingTexture) const;)
58
55 private: 59 private:
60 // ID of the picture of which this layer is a part
56 uint32_t fPictureID; 61 uint32_t fPictureID;
62
57 // fLayerID is only valid when fPicture != kInvalidGenID in which case it 63 // fLayerID is only valid when fPicture != kInvalidGenID in which case it
58 // is the index of this layer in the picture (one of 0 .. #layers). 64 // is the index of this layer in the picture (one of 0 .. #layers).
59 int fLayerID; 65 int fLayerID;
60 66
61 // fTexture is a ref on the atlasing texture for atlased layers and a 67 // fTexture is a ref on the atlasing texture for atlased layers and a
62 // ref on a GrTexture for non-atlased textures. In both cases, if this is 68 // ref on a GrTexture for non-atlased textures. In both cases, if this is
63 // non-NULL, that means that the texture is locked in the texture cache. 69 // non-NULL, that means that the texture is locked in the texture cache.
64 GrTexture* fTexture; 70 GrTexture* fTexture;
65 71
66 // For non-atlased layers 'fRect' is empty otherwise it is the bound of 72 // True if this layer is in an atlas; false otherwise.
67 // the layer in the atlas. 73 bool fAtlased;
74
75 // For both atlased and non-atlased layers 'fRect' contains the bound of
76 // the layer in whichever texture it resides. It is empty when 'fTexture'
77 // is NULL.
68 GrIRect16 fRect; 78 GrIRect16 fRect;
69 }; 79 };
70 80
71 // The GrLayerCache caches pre-computed saveLayers for later rendering. 81 // The GrLayerCache caches pre-computed saveLayers for later rendering.
72 // Non-atlased layers are stored in their own GrTexture while the atlased 82 // Non-atlased layers are stored in their own GrTexture while the atlased
73 // layers share a single GrTexture. 83 // layers share a single GrTexture.
74 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlas (for 8888) 84 // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlas (for 8888)
75 // and one GrPlot (for the entire atlas). As such, the GrLayerCache 85 // and one GrPlot (for the entire atlas). As such, the GrLayerCache
76 // roughly combines the functionality of the GrFontCache and GrTextStrike 86 // roughly combines the functionality of the GrFontCache and GrTextStrike
77 // classes. 87 // classes.
(...skipping 14 matching lines...) Expand all
92 // If false is returned the caller should (re)render the layer into the 102 // If false is returned the caller should (re)render the layer into the
93 // newly acquired texture. 103 // newly acquired texture.
94 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc); 104 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc);
95 105
96 // Inform the cache that layer's cached image is not currently required 106 // Inform the cache that layer's cached image is not currently required
97 void unlock(GrCachedLayer* layer); 107 void unlock(GrCachedLayer* layer);
98 108
99 // Remove all the layers (and unlock any resources) associated with 'picture ' 109 // Remove all the layers (and unlock any resources) associated with 'picture '
100 void purge(const SkPicture* picture); 110 void purge(const SkPicture* picture);
101 111
112 SkDEBUGCODE(void validate() const;)
113
102 private: 114 private:
103 GrContext* fContext; // pointer back to owning context 115 GrContext* fContext; // pointer back to owning context
104 SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate 116 SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate
105 GrAtlas::ClientPlotUsage fPlotUsage; 117 GrAtlas::ClientPlotUsage fPlotUsage;
106 118
107 class PictureLayerKey; 119 class PictureLayerKey;
108 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash; 120 GrTHashTable<GrCachedLayer, PictureLayerKey, 7> fLayerHash;
109 121
110 void initAtlas(); 122 void initAtlas();
111 GrCachedLayer* createLayer(const SkPicture* picture, int layerID); 123 GrCachedLayer* createLayer(const SkPicture* picture, int layerID);
112 124
113 // for testing 125 // for testing
114 friend class GetNumLayers; 126 friend class GetNumLayers;
115 int numLayers() const { return fLayerHash.count(); } 127 int numLayers() const { return fLayerHash.count(); }
116 }; 128 };
117 129
118 #endif 130 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrLayerCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698