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

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: Fixed compiler complaint 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
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(uint32_t pictureID, int layerID)
18 : fPictureID(pictureID)
19 , fLayerID(layerID) {
20 }
21
22 uint32_t pictureID() const { return fPictureID; }
23 int layerID() const { return fLayerID; }
24
25 uint32_t getHash() const { return (fPictureID << 16) | fLayerID; }
26
27 static bool LessThan(const GrAtlasedLayer& layer, const PictureLayerKey& key ) {
28 if (layer.pictureID() == key.pictureID()) {
29 return layer.layerID() < key.layerID();
30 }
31
32 return layer.pictureID() < key.pictureID();
33 }
34
35 static bool Equals(const GrAtlasedLayer& layer, const PictureLayerKey& key) {
36 return layer.pictureID() == key.pictureID() && layer.layerID() == key.la yerID();
37 }
38
39 private:
40 uint32_t fPictureID;
41 int fLayerID;
42 };
43
44 GrLayerCache::GrLayerCache(GrGpu* gpu)
45 : fGpu(SkRef(gpu))
46 , fLayerPool(16) { // TODO: may need to increase this later
47 }
48
49 GrLayerCache::~GrLayerCache() {
50 }
51
52 void GrLayerCache::init() {
53 static const int kAtlasTextureWidth = 1024;
54 static const int kAtlasTextureHeight = 1024;
55
56 SkASSERT(NULL == fAtlasMgr.get());
57
58 // The layer cache only gets 1 plot
59 SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight) ;
60 fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fGpu, kSkia8888_GrPixelConfig,
61 textureSize, 1, 1)));
62 }
63
64 void GrLayerCache::freeAll() {
65 fLayerHash.deleteAll();
66 fAtlasMgr.free();
67 }
68
69 GrAtlasedLayer* GrLayerCache::createLayer(SkPicture* picture, int layerID) {
70 GrAtlasedLayer* layer = fLayerPool.alloc();
71
72 SkASSERT(picture->getGenerationID() != SkPicture::kInvalidGenID);
73 layer->init(picture->getGenerationID(), layerID);
74 fLayerHash.insert(PictureLayerKey(picture->getGenerationID(), layerID), laye r);
75 return layer;
76 }
77
78
79 const GrAtlasedLayer* GrLayerCache::findLayerOrCreate(SkPicture* picture, int la yerID) {
80 SkASSERT(picture->getGenerationID() != SkPicture::kInvalidGenID);
81 GrAtlasedLayer* layer = fLayerHash.find(PictureLayerKey(picture->getGenerati onID(), layerID));
82 if (NULL == layer) {
83 layer = this->createLayer(picture, layerID);
84 }
85 return layer;
86 }
OLDNEW
« 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