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.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); | 25 src.allocN32Pixels(size.width(), size.height()); |
26 src.allocPixels(); | |
27 src.eraseColor(SK_ColorBLACK); | 26 src.eraseColor(SK_ColorBLACK); |
28 size_t srcSize = src.getSize(); | 27 size_t srcSize = src.getSize(); |
29 | 28 |
30 size_t initialCacheSize = context->getGpuTextureCacheBytes(); | 29 size_t initialCacheSize = context->getGpuTextureCacheBytes(); |
31 | 30 |
32 int oldMaxNum; | 31 int oldMaxNum; |
33 size_t oldMaxBytes; | 32 size_t oldMaxBytes; |
34 context->getTextureCacheLimits(&oldMaxNum, &oldMaxBytes); | 33 context->getTextureCacheLimits(&oldMaxNum, &oldMaxBytes); |
35 | 34 |
36 // Set the cache limits so we can fit 10 "src" images and the | 35 // Set the cache limits so we can fit 10 "src" images and the |
37 // max number of textures doesn't matter | 36 // max number of textures doesn't matter |
38 size_t maxCacheSize = initialCacheSize + 10*srcSize; | 37 size_t maxCacheSize = initialCacheSize + 10*srcSize; |
39 context->setTextureCacheLimits(1000, maxCacheSize); | 38 context->setTextureCacheLimits(1000, maxCacheSize); |
40 | 39 |
41 SkBitmap readback; | 40 SkBitmap readback; |
42 readback.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height())
; | 41 readback.allocN32Pixels(size.width(), size.height()); |
43 readback.allocPixels(); | |
44 | 42 |
45 for (int i = 0; i < 100; ++i) { | 43 for (int i = 0; i < 100; ++i) { |
46 canvas->drawBitmap(src, 0, 0); | 44 canvas->drawBitmap(src, 0, 0); |
47 canvas->readPixels(size, &readback); | 45 canvas->readPixels(size, &readback); |
48 | 46 |
49 // "modify" the src texture | 47 // "modify" the src texture |
50 src.notifyPixelsChanged(); | 48 src.notifyPixelsChanged(); |
51 | 49 |
52 size_t curCacheSize = context->getGpuTextureCacheBytes(); | 50 size_t curCacheSize = context->getGpuTextureCacheBytes(); |
53 | 51 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (context, textu
re.get()))); | 196 SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (context, textu
re.get()))); |
199 SkCanvas canvas(device.get()); | 197 SkCanvas canvas(device.get()); |
200 | 198 |
201 test_cache(reporter, context, &canvas); | 199 test_cache(reporter, context, &canvas); |
202 test_purge_invalidated(reporter, context); | 200 test_purge_invalidated(reporter, context); |
203 test_cache_delete_on_destruction(reporter, context); | 201 test_cache_delete_on_destruction(reporter, context); |
204 } | 202 } |
205 } | 203 } |
206 | 204 |
207 #endif | 205 #endif |
OLD | NEW |