blob: 0624736338c96e345cc35375c4898c8481dd423a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrLayerCache_DEFINED
#define GrLayerCache_DEFINED
#include "GrAllocPool.h"
#include "GrTHashTable.h"
#include "GrPictureUtils.h"
#include "GrRect.h"
class GrAtlasMgr;
class GrGpu;
class GrPlot;
class SkPicture;
// GrAtlasLocation captures an atlased item's position in the atlas. This
// means the plot in which it resides and its bounds inside the plot.
// TODO: Make GrGlyph use one of these?
class GrAtlasLocation {
public:
GrAtlasLocation() : fPlot(NULL) {}
void set(GrPlot* plot, const GrIRect16& bounds) {
fPlot = plot;
fBounds = bounds;
}
const GrPlot* plot() const {
return fPlot;
}
const GrIRect16& bounds() const {
return fBounds;
}
private:
GrPlot* fPlot;
GrIRect16 fBounds; // only valid is fPlot != NULL
};
// A GrAtlasedLayer encapsulates the atlasing information for a single saveLayer.
// It is roughly equivalent to a GrGlyph in the font caching system
class GrAtlasedLayer {
public:
GrAtlasedLayer() : fPictureID(SK_InvalidGenID) { }
uint32_t pictureID() const { return fPictureID; }
int layerID() const { return fLayerID; }
void init(uint32_t pictureID, int layerID) {
fPictureID = pictureID;
fLayerID = layerID;
}
private:
uint32_t fPictureID;
int fLayerID; // only valid if fPicture != kInvalidGenID
GrAtlasLocation fLocation;
};
// The GrLayerCache caches pre-computed saveLayers for later rendering.
// Unlike the GrFontCache, this cache only has one GrAtlasMgr (for 8888)
// and one GrPlot (for the entire atlas). As such, the GrLayerCache
// roughly combines the functionality of the GrFontCache and GrTextStrike
// classes.
class GrLayerCache {
public:
GrLayerCache(GrGpu*);
~GrLayerCache();
void freeAll();
const GrAtlasedLayer* findLayerOrCreate(SkPicture* picture, int id);
private:
SkAutoTUnref<GrGpu> fGpu;
SkAutoTDelete<GrAtlasMgr> fAtlasMgr; // TODO: could lazily allocate
class PictureLayerKey;
GrTHashTable<GrAtlasedLayer, PictureLayerKey, 7> fLayerHash;
GrTAllocPool<GrAtlasedLayer> fLayerPool;
void init();
GrAtlasedLayer* createLayer(SkPicture* picture, int id);
};
#endif
|