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

Side by Side Diff: skia/ext/analysis_canvas_unittest.cc

Issue 12388095: cc: Merge GatherPixelRefs and AnalyzeInRect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: junov's review Created 7 years, 9 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
« skia/ext/analysis_canvas.cc ('K') | « skia/ext/analysis_canvas.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "skia/ext/analysis_canvas.h" 6 #include "skia/ext/analysis_canvas.h"
7
8 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/skia/include/core/SkShader.h"
9 9
10 namespace { 10 namespace {
11 11
12 void solidColorFill(skia::AnalysisCanvas& canvas) { 12 void solidColorFill(skia::AnalysisCanvas& canvas) {
13 canvas.clear(SkColorSetARGB(255, 255, 255, 255)); 13 canvas.clear(SkColorSetARGB(255, 255, 255, 255));
14 } 14 }
15 15
16 void transparentFill(skia::AnalysisCanvas& canvas) { 16 void transparentFill(skia::AnalysisCanvas& canvas) {
17 canvas.clear(SkColorSetARGB(0, 0, 0, 0)); 17 canvas.clear(SkColorSetARGB(0, 0, 0, 0));
18 } 18 }
19 19
20 } // namespace 20 } // namespace
21 namespace skia { 21 namespace skia {
22 22
23 class TestPixelRef : public SkPixelRef {
24 public:
25 // Pure virtual implementation.
26 SkFlattenable::Factory getFactory() { return NULL; }
27 void* onLockPixels(SkColorTable**) { return NULL; }
28 void onUnlockPixels() {}
29 };
30
31 class TestLazyPixelRef : public LazyPixelRef {
32 public:
33 // Pure virtual implementation.
34 SkFlattenable::Factory getFactory() { return NULL; }
35 void* onLockPixels(SkColorTable**) { return NULL; }
36 void onUnlockPixels() {}
37 bool PrepareToDecode(const PrepareParams& params) { return true; }
38 void Decode() {}
39 };
40
41 class TestShader : public SkShader {
42 public:
43 TestShader(SkBitmap* bitmap)
44 : bitmap_(bitmap) {
45 }
46
47 SkShader::BitmapType asABitmap(SkBitmap* bitmap, SkMatrix*, TileMode xy[2]) co nst {
Sami 2013/03/18 12:14:33 Nit: line length.
48 *bitmap = *bitmap_;
49 return SkShader::kDefault_BitmapType;
50 }
51
52 // Pure virtual implementation.
53 void shadeSpan(int x, int y, SkPMColor[], int count) {}
54 SkFlattenable::Factory getFactory() { return NULL; }
55
56 private:
57
58 SkBitmap* bitmap_;
59 };
60
23 TEST(AnalysisCanvasTest, EmptyCanvas) { 61 TEST(AnalysisCanvasTest, EmptyCanvas) {
24 SkBitmap emptyBitmap; 62 SkBitmap emptyBitmap;
25 emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255); 63 emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
26 skia::AnalysisDevice device(emptyBitmap); 64 skia::AnalysisDevice device(emptyBitmap);
27 skia::AnalysisCanvas canvas(&device); 65 skia::AnalysisCanvas canvas(&device);
28 66
29 SkColor color; 67 SkColor color;
30 EXPECT_FALSE(canvas.getColorIfSolid(&color)); 68 EXPECT_FALSE(canvas.getColorIfSolid(&color));
31 EXPECT_FALSE(canvas.isTransparent()); 69 EXPECT_FALSE(canvas.isTransparent());
32 EXPECT_TRUE(canvas.isCheap()); 70 EXPECT_TRUE(canvas.isCheap());
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 341
304 transparentFill(canvas); 342 transparentFill(canvas);
305 EXPECT_FALSE(canvas.getColorIfSolid(&outputColor)); 343 EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
306 EXPECT_TRUE(canvas.isTransparent()); 344 EXPECT_TRUE(canvas.isTransparent());
307 345
308 solidColorFill(canvas); 346 solidColorFill(canvas);
309 EXPECT_TRUE(canvas.getColorIfSolid(&outputColor)); 347 EXPECT_TRUE(canvas.getColorIfSolid(&outputColor));
310 EXPECT_FALSE(canvas.isTransparent()); 348 EXPECT_FALSE(canvas.isTransparent());
311 } 349 }
312 350
351 TEST(AnalysisCanvasTest, LazyPixelRefs) {
352 // Set up two lazy and two non-lazy pixel refs and the corresponding bitmaps.
353 TestLazyPixelRef firstLazyPixelRef;
354 firstLazyPixelRef.setURI("lazy");
355 TestLazyPixelRef secondLazyPixelRef;
356 secondLazyPixelRef.setURI("lazy");
357
358 TestPixelRef firstNonLazyPixelRef;
359 TestPixelRef secondNonLazyPixelRef;
360 secondNonLazyPixelRef.setURI("notsolazy");
361
362 SkBitmap firstLazyBitmap;
363 firstLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
364 firstLazyBitmap.setPixelRef(&firstLazyPixelRef);
365 SkBitmap secondLazyBitmap;
366 secondLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
367 secondLazyBitmap.setPixelRef(&secondLazyPixelRef);
368
369 SkBitmap firstNonLazyBitmap;
370 firstNonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
371 SkBitmap secondNonLazyBitmap;
372 secondNonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
373 secondNonLazyBitmap.setPixelRef(&secondNonLazyPixelRef);
374
375 // The testcase starts here.
376 SkBitmap emptyBitmap;
377 emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
378 skia::AnalysisDevice device(emptyBitmap);
379 skia::AnalysisCanvas canvas(&device);
380
381 // This should be the first ref.
382 canvas.drawBitmap(firstLazyBitmap, 0, 0);
383 // The following will be ignored (non-lazy).
384 canvas.drawBitmap(firstNonLazyBitmap, 0, 0);
385 canvas.drawBitmap(firstNonLazyBitmap, 0, 0);
386 canvas.drawBitmap(secondNonLazyBitmap, 0, 0);
387 canvas.drawBitmap(secondNonLazyBitmap, 0, 0);
388 // This one will be ignored (already exists).
389 canvas.drawBitmap(firstLazyBitmap, 0, 0);
390 // This should be the second ref.
391 canvas.drawBitmap(secondLazyBitmap, 0, 0);
392
393 std::list<skia::LazyPixelRef*> pixelRefs;
394 canvas.consumeLazyPixelRefs(pixelRefs);
395
396 // We expect to get only lazy pixel refs and only unique results.
397 EXPECT_EQ(pixelRefs.size(), 2u);
398 if (!pixelRefs.empty()) {
399 EXPECT_EQ(pixelRefs.front(), static_cast<LazyPixelRef*>(&firstLazyPixelRef)) ;
Sami 2013/03/18 12:14:33 Nit: line length.
400 EXPECT_EQ(pixelRefs.back(), static_cast<LazyPixelRef*>(&secondLazyPixelRef)) ;
401 }
402 }
403
404 TEST(AnalysisCanvasTest, PixelRefsFromPaint) {
405 TestLazyPixelRef lazyPixelRef;
406 lazyPixelRef.setURI("lazy");
407
408 TestPixelRef nonLazyPixelRef;
409 nonLazyPixelRef.setURI("notsolazy");
410
411 SkBitmap lazyBitmap;
412 lazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
413 lazyBitmap.setPixelRef(&lazyPixelRef);
414
415 SkBitmap nonLazyBitmap;
416 nonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
417 nonLazyBitmap.setPixelRef(&nonLazyPixelRef);
418
419 TestShader lazyShader(&lazyBitmap);
420 TestShader nonLazyShader(&nonLazyBitmap);
421
422 SkPaint lazyPaint;
423 lazyPaint.setShader(&lazyShader);
424 SkPaint nonLazyPaint;
425 nonLazyPaint.setShader(&nonLazyShader);
426
427 SkBitmap emptyBitmap;
428 emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
429 skia::AnalysisDevice device(emptyBitmap);
430 skia::AnalysisCanvas canvas(&device);
431
432 canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
433 canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
434 canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
435 canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
436 canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
437 canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
438
439 std::list<skia::LazyPixelRef*> pixelRefs;
440 canvas.consumeLazyPixelRefs(pixelRefs);
441
442 // We expect to get only lazy pixel refs and only unique results.
443 EXPECT_EQ(pixelRefs.size(), 1u);
444 if (!pixelRefs.empty()) {
445 EXPECT_EQ(pixelRefs.front(), static_cast<LazyPixelRef*>(&lazyPixelRef));
446 }
447 }
448
313 } // namespace skia 449 } // namespace skia
OLDNEW
« skia/ext/analysis_canvas.cc ('K') | « skia/ext/analysis_canvas.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698