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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 162643002: replace setConfig+allocPixels with single call (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | « tests/QuickRejectTest.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « tests/QuickRejectTest.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698