OLD | NEW |
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 #include "GrAtlas.h" | 8 #include "GrAtlas.h" |
9 #include "GrGpu.h" | 9 #include "GrGpu.h" |
10 #include "GrLayerCache.h" | 10 #include "GrLayerCache.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 static bool Equals(const GrCachedLayer& layer, const PictureLayerKey& key) { | 35 static bool Equals(const GrCachedLayer& layer, const PictureLayerKey& key) { |
36 return layer.pictureID() == key.pictureID() && layer.layerID() == key.la
yerID(); | 36 return layer.pictureID() == key.pictureID() && layer.layerID() == key.la
yerID(); |
37 } | 37 } |
38 | 38 |
39 private: | 39 private: |
40 uint32_t fPictureID; | 40 uint32_t fPictureID; |
41 int fLayerID; | 41 int fLayerID; |
42 }; | 42 }; |
43 | 43 |
44 GrLayerCache::GrLayerCache(GrGpu* gpu) | 44 GrLayerCache::GrLayerCache(GrContext* context) |
45 : fGpu(SkRef(gpu)) | 45 : fContext(context) |
46 , fLayerPool(16) { // TODO: may need to increase this later | 46 , fLayerPool(16) { // TODO: may need to increase this later |
47 } | 47 } |
48 | 48 |
49 GrLayerCache::~GrLayerCache() { | 49 GrLayerCache::~GrLayerCache() { |
50 } | 50 } |
51 | 51 |
52 void GrLayerCache::init() { | 52 void GrLayerCache::init() { |
53 static const int kAtlasTextureWidth = 1024; | 53 static const int kAtlasTextureWidth = 1024; |
54 static const int kAtlasTextureHeight = 1024; | 54 static const int kAtlasTextureHeight = 1024; |
55 | 55 |
56 SkASSERT(NULL == fAtlasMgr.get()); | 56 SkASSERT(NULL == fAtlasMgr.get()); |
57 | 57 |
58 // The layer cache only gets 1 plot | 58 // The layer cache only gets 1 plot |
59 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight)
; | 59 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight)
; |
60 fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fGpu, kSkia8888_GrPixelConfig, | 60 fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fContext->getGpu(), kSkia8888_GrPixe
lConfig, |
61 textureSize, 1, 1, false))); | 61 textureSize, 1, 1, false))); |
62 } | 62 } |
63 | 63 |
64 void GrLayerCache::freeAll() { | 64 void GrLayerCache::freeAll() { |
65 fLayerHash.deleteAll(); | 65 fLayerHash.deleteAll(); |
66 fAtlasMgr.free(); | 66 fAtlasMgr.free(); |
67 } | 67 } |
68 | 68 |
69 GrCachedLayer* GrLayerCache::createLayer(const SkPicture* picture, int layerID)
{ | 69 GrCachedLayer* GrLayerCache::createLayer(const SkPicture* picture, int layerID)
{ |
70 GrCachedLayer* layer = fLayerPool.alloc(); | 70 GrCachedLayer* layer = fLayerPool.alloc(); |
71 | 71 |
72 SkASSERT(picture->uniqueID() != SK_InvalidGenID); | 72 SkASSERT(picture->uniqueID() != SK_InvalidGenID); |
73 layer->init(picture->uniqueID(), layerID); | 73 layer->init(picture->uniqueID(), layerID); |
74 fLayerHash.insert(PictureLayerKey(picture->uniqueID(), layerID), layer); | 74 fLayerHash.insert(PictureLayerKey(picture->uniqueID(), layerID), layer); |
75 return layer; | 75 return layer; |
76 } | 76 } |
77 | 77 |
| 78 GrCachedLayer* GrLayerCache::findLayer(const SkPicture* picture, int layerID) { |
| 79 SkASSERT(picture->uniqueID() != SK_InvalidGenID); |
| 80 return fLayerHash.find(PictureLayerKey(picture->uniqueID(), layerID)); |
| 81 } |
78 | 82 |
79 GrCachedLayer* GrLayerCache::findLayerOrCreate(const SkPicture* picture, int lay
erID) { | 83 GrCachedLayer* GrLayerCache::findLayerOrCreate(const SkPicture* picture, int lay
erID) { |
80 SkASSERT(picture->uniqueID() != SK_InvalidGenID); | 84 SkASSERT(picture->uniqueID() != SK_InvalidGenID); |
81 GrCachedLayer* layer = fLayerHash.find(PictureLayerKey(picture->uniqueID(),
layerID)); | 85 GrCachedLayer* layer = fLayerHash.find(PictureLayerKey(picture->uniqueID(),
layerID)); |
82 if (NULL == layer) { | 86 if (NULL == layer) { |
83 layer = this->createLayer(picture, layerID); | 87 layer = this->createLayer(picture, layerID); |
84 } | 88 } |
| 89 |
85 return layer; | 90 return layer; |
86 } | 91 } |
| 92 |
| 93 bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) { |
| 94 SkASSERT(NULL == layer->getTexture()); |
| 95 |
| 96 // This just uses scratch textures and doesn't cache the texture. |
| 97 // This can yield a lot of re-rendering |
| 98 layer->setTexture(fContext->lockAndRefScratchTexture(desc, GrContext::kAppro
x_ScratchTexMatch)); |
| 99 return false; |
| 100 } |
| 101 |
| 102 void GrLayerCache::unlock(GrCachedLayer* layer) { |
| 103 if (NULL == layer || NULL == layer->getTexture()) { |
| 104 return; |
| 105 } |
| 106 |
| 107 fContext->unlockScratchTexture(layer->getTexture()); |
| 108 layer->setTexture(NULL); |
| 109 } |
OLD | NEW |