OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #if SK_SUPPORT_GPU | 8 #if SK_SUPPORT_GPU |
9 | 9 |
10 #include "GrContextFactory.h" | 10 #include "GrContextFactory.h" |
11 #include "GrResourceCache.h" | 11 #include "GrResourceCache.h" |
12 #include "SkGpuDevice.h" | 12 #include "SkGpuDevice.h" |
13 #include "Test.h" | 13 #include "Test.h" |
14 | 14 |
15 static const int gWidth = 640; | 15 static const int gWidth = 640; |
16 static const int gHeight = 480; | 16 static const int gHeight = 480; |
17 | 17 |
18 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
19 static void test_cache(skiatest::Reporter* reporter, | 19 static void test_cache(skiatest::Reporter* reporter, |
20 GrContext* context, | 20 GrContext* context, |
21 SkCanvas* canvas) { | 21 SkCanvas* canvas) { |
22 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); | 22 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
23 | 23 |
24 SkBitmap src; | 24 SkBitmap src; |
25 src.allocN32Pixels(size.width(), size.height()); | 25 src.allocN32Pixels(size.width(), size.height()); |
26 src.eraseColor(SK_ColorBLACK); | 26 src.eraseColor(SK_ColorBLACK); |
27 size_t srcSize = src.getSize(); | 27 size_t srcSize = src.getSize(); |
28 | 28 |
29 size_t initialCacheSize = context->getGpuTextureCacheBytes(); | 29 size_t initialCacheSize; |
| 30 context->getResourceCacheUsage(NULL, &initialCacheSize); |
30 | 31 |
31 int oldMaxNum; | 32 int oldMaxNum; |
32 size_t oldMaxBytes; | 33 size_t oldMaxBytes; |
33 context->getTextureCacheLimits(&oldMaxNum, &oldMaxBytes); | 34 context->getResourceCacheLimits(&oldMaxNum, &oldMaxBytes); |
34 | 35 |
35 // Set the cache limits so we can fit 10 "src" images and the | 36 // Set the cache limits so we can fit 10 "src" images and the |
36 // max number of textures doesn't matter | 37 // max number of textures doesn't matter |
37 size_t maxCacheSize = initialCacheSize + 10*srcSize; | 38 size_t maxCacheSize = initialCacheSize + 10*srcSize; |
38 context->setTextureCacheLimits(1000, maxCacheSize); | 39 context->setResourceCacheLimits(1000, maxCacheSize); |
39 | 40 |
40 SkBitmap readback; | 41 SkBitmap readback; |
41 readback.allocN32Pixels(size.width(), size.height()); | 42 readback.allocN32Pixels(size.width(), size.height()); |
42 | 43 |
43 for (int i = 0; i < 100; ++i) { | 44 for (int i = 0; i < 100; ++i) { |
44 canvas->drawBitmap(src, 0, 0); | 45 canvas->drawBitmap(src, 0, 0); |
45 canvas->readPixels(size, &readback); | 46 canvas->readPixels(size, &readback); |
46 | 47 |
47 // "modify" the src texture | 48 // "modify" the src texture |
48 src.notifyPixelsChanged(); | 49 src.notifyPixelsChanged(); |
49 | 50 |
50 size_t curCacheSize = context->getGpuTextureCacheBytes(); | 51 size_t curCacheSize; |
| 52 context->getResourceCacheUsage(NULL, &curCacheSize); |
51 | 53 |
52 // we should never go over the size limit | 54 // we should never go over the size limit |
53 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); | 55 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); |
54 } | 56 } |
55 | 57 |
56 context->setTextureCacheLimits(oldMaxNum, oldMaxBytes); | 58 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); |
57 } | 59 } |
58 | 60 |
59 class TestResource : public GrCacheable { | 61 class TestResource : public GrCacheable { |
60 static const size_t kDefaultSize = 100; | 62 static const size_t kDefaultSize = 100; |
61 | 63 |
62 public: | 64 public: |
63 SK_DECLARE_INST_COUNT(TestResource); | 65 SK_DECLARE_INST_COUNT(TestResource); |
64 TestResource(size_t size = kDefaultSize) | 66 TestResource(size_t size = kDefaultSize) |
65 : fCache(NULL) | 67 : fCache(NULL) |
66 , fToDelete(NULL) | 68 , fToDelete(NULL) |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 SkCanvas canvas(device.get()); | 301 SkCanvas canvas(device.get()); |
300 | 302 |
301 test_cache(reporter, context, &canvas); | 303 test_cache(reporter, context, &canvas); |
302 test_purge_invalidated(reporter, context); | 304 test_purge_invalidated(reporter, context); |
303 test_cache_delete_on_destruction(reporter, context); | 305 test_cache_delete_on_destruction(reporter, context); |
304 test_resource_size_changed(reporter, context); | 306 test_resource_size_changed(reporter, context); |
305 } | 307 } |
306 } | 308 } |
307 | 309 |
308 #endif | 310 #endif |
OLD | NEW |