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

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

Issue 217343006: Add a GrLayerCache to GrContext (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrAtlas.h"
9 #include "GrGpu.h"
10 #include "GrLayerCache.h"
11
12 /**
13 * PictureLayerKey just wraps a saveLayer's id in the picture for GrTHashTable.
14 */
15 class GrLayerCache::PictureLayerKey {
16 public:
17 PictureLayerKey(SkPicture* picture, int id) : fPicture(picture), fID(id) {}
18
19 const SkPicture* picture() const { return fPicture; }
20 int id() const { return fID; }
21
22 uint32_t getHash() const { return ((int)fPicture) ^ fID; }
23
24 static bool LessThan(const GrAtlasedLayer& layer, const PictureLayerKey& key ) {
25 if (layer.picture() == key.picture()) {
26 return layer.id() < key.id();
27 }
28
29 return layer.picture() < key.picture();
30 }
31
32 static bool Equals(const GrAtlasedLayer& layer, const PictureLayerKey& key) {
33 return layer.picture() == key.picture() && layer.id() == key.id();
34 }
35
36 private:
37 SkPicture* fPicture;
38 int fID;
39 };
40
41 GrLayerCache::GrLayerCache(GrGpu* gpu)
42 : fGpu(SkRef(gpu))
43 , fLayerPool(16) { // TODO: may need to increase this later
44 }
45
46 GrLayerCache::~GrLayerCache() {
47 }
48
49 void GrLayerCache::init() {
50 static const int kAtlasTextureWidth = 1024;
51 static const int kAtlasTextureHeight = 1024;
52
53 SkASSERT(NULL == fAtlasMgr.get());
54
55 // The layer cache only gets 1 plot
56 fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fGpu, kSkia8888_GrPixelConfig,
57 kAtlasTextureWidth, kAtlasTextureHei ght,
58 1, 1)));
59 }
60
61 void GrLayerCache::freeAll() {
62 fLayerHash.deleteAll();
63 fAtlasMgr.free();
64 }
65
66 GrAtlasedLayer* GrLayerCache::createLayer(SkPicture* picture, int id) {
67 GrAtlasedLayer* layer = fLayerPool.alloc();
68
69 layer->init(picture, id);
70 fLayerHash.insert(PictureLayerKey(picture, id), layer);
71 return layer;
72 }
73
74
75 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.
76 GrAtlasedLayer* layer = fLayerHash.find(PictureLayerKey(picture, id));
77 if (NULL == layer) {
78 layer = this->createLayer(picture, id);
79 }
80 return layer;
81 }
OLDNEW
« src/gpu/GrLayerCache.h ('K') | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698