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

Unified Diff: src/gpu/GrLayerCache.cpp

Issue 217343006: Add a GrLayerCache to GrContext (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fixed compiler complaint Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrLayerCache.cpp
===================================================================
--- src/gpu/GrLayerCache.cpp (revision 0)
+++ src/gpu/GrLayerCache.cpp (revision 0)
@@ -0,0 +1,86 @@
+/*
+ * 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(uint32_t pictureID, int layerID)
+ : fPictureID(pictureID)
+ , fLayerID(layerID) {
+ }
+
+ uint32_t pictureID() const { return fPictureID; }
+ int layerID() const { return fLayerID; }
+
+ uint32_t getHash() const { return (fPictureID << 16) | fLayerID; }
+
+ static bool LessThan(const GrAtlasedLayer& layer, const PictureLayerKey& key) {
+ if (layer.pictureID() == key.pictureID()) {
+ return layer.layerID() < key.layerID();
+ }
+
+ return layer.pictureID() < key.pictureID();
+ }
+
+ static bool Equals(const GrAtlasedLayer& layer, const PictureLayerKey& key) {
+ return layer.pictureID() == key.pictureID() && layer.layerID() == key.layerID();
+ }
+
+private:
+ uint32_t fPictureID;
+ int fLayerID;
+};
+
+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
+ SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight);
+ fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fGpu, kSkia8888_GrPixelConfig,
+ textureSize, 1, 1)));
+}
+
+void GrLayerCache::freeAll() {
+ fLayerHash.deleteAll();
+ fAtlasMgr.free();
+}
+
+GrAtlasedLayer* GrLayerCache::createLayer(SkPicture* picture, int layerID) {
+ GrAtlasedLayer* layer = fLayerPool.alloc();
+
+ SkASSERT(picture->getGenerationID() != SkPicture::kInvalidGenID);
+ layer->init(picture->getGenerationID(), layerID);
+ fLayerHash.insert(PictureLayerKey(picture->getGenerationID(), layerID), layer);
+ return layer;
+}
+
+
+const GrAtlasedLayer* GrLayerCache::findLayerOrCreate(SkPicture* picture, int layerID) {
+ SkASSERT(picture->getGenerationID() != SkPicture::kInvalidGenID);
+ GrAtlasedLayer* layer = fLayerHash.find(PictureLayerKey(picture->getGenerationID(), layerID));
+ if (NULL == layer) {
+ layer = this->createLayer(picture, layerID);
+ }
+ return layer;
+}
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698