Chromium Code Reviews| Index: src/gpu/GrLayerCache.cpp |
| =================================================================== |
| --- src/gpu/GrLayerCache.cpp (revision 0) |
| +++ src/gpu/GrLayerCache.cpp (revision 0) |
| @@ -0,0 +1,81 @@ |
| +/* |
| + * Copyright 2014 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "GrAtlas.h" |
| +#include "GrGpu.h" |
| +#include "GrLayerCache.h" |
| + |
| +/** |
| + * PictureLayerKey just wraps a saveLayer's id in the picture for GrTHashTable. |
| + */ |
| +class GrLayerCache::PictureLayerKey { |
| +public: |
| + PictureLayerKey(SkPicture* picture, int id) : fPicture(picture), fID(id) {} |
| + |
| + const SkPicture* picture() const { return fPicture; } |
| + int id() const { return fID; } |
| + |
| + uint32_t getHash() const { return ((int)fPicture) ^ fID; } |
| + |
| + static bool LessThan(const GrAtlasedLayer& layer, const PictureLayerKey& key) { |
| + if (layer.picture() == key.picture()) { |
| + return layer.id() < key.id(); |
| + } |
| + |
| + return layer.picture() < key.picture(); |
| + } |
| + |
| + static bool Equals(const GrAtlasedLayer& layer, const PictureLayerKey& key) { |
| + return layer.picture() == key.picture() && layer.id() == key.id(); |
| + } |
| + |
| +private: |
| + SkPicture* fPicture; |
| + int fID; |
| +}; |
| + |
| +GrLayerCache::GrLayerCache(GrGpu* gpu) |
| + : fGpu(SkRef(gpu)) |
| + , fLayerPool(16) { // TODO: may need to increase this later |
| +} |
| + |
| +GrLayerCache::~GrLayerCache() { |
| +} |
| + |
| +void GrLayerCache::init() { |
| + static const int kAtlasTextureWidth = 1024; |
| + static const int kAtlasTextureHeight = 1024; |
| + |
| + SkASSERT(NULL == fAtlasMgr.get()); |
| + |
| + // The layer cache only gets 1 plot |
| + fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fGpu, kSkia8888_GrPixelConfig, |
| + kAtlasTextureWidth, kAtlasTextureHeight, |
| + 1, 1))); |
| +} |
| + |
| +void GrLayerCache::freeAll() { |
| + fLayerHash.deleteAll(); |
| + fAtlasMgr.free(); |
| +} |
| + |
| +GrAtlasedLayer* GrLayerCache::createLayer(SkPicture* picture, int id) { |
| + GrAtlasedLayer* layer = fLayerPool.alloc(); |
| + |
| + layer->init(picture, id); |
| + fLayerHash.insert(PictureLayerKey(picture, id), layer); |
| + return layer; |
| +} |
| + |
| + |
| +const GrAtlasedLayer* GrLayerCache::findLayer(SkPicture* picture, int id) { |
|
bsalomon
2014/04/01 15:26:35
Seems like this should be named something like fin
robertphillips
2014/04/01 16:51:49
Done.
|
| + GrAtlasedLayer* layer = fLayerHash.find(PictureLayerKey(picture, id)); |
| + if (NULL == layer) { |
| + layer = this->createLayer(picture, id); |
| + } |
| + return layer; |
| +} |
| Property changes on: src\gpu\GrLayerCache.cpp |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |