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

Side by Side Diff: tests/RecordTest.cpp

Issue 1461663003: Add SkRecord::defrag(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: simplify Created 5 years, 1 month 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
« no previous file with comments | « src/core/SkRecordOpts.cpp ('k') | tests/RecordTestUtils.h » ('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 2014 Google Inc. 2 * Copyright 2014 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 #include "RecordTestUtils.h"
9 #include "SkBitmap.h"
10 #include "SkImageInfo.h"
11 #include "SkRecord.h"
12 #include "SkRecords.h"
13 #include "SkShader.h"
8 #include "Test.h" 14 #include "Test.h"
9 15
10 #include "SkBitmap.h"
11 #include "SkImageInfo.h"
12 #include "SkShader.h"
13 #include "SkRecord.h"
14 #include "SkRecords.h"
15 16
16 // Sums the area of any DrawRect command it sees. 17 // Sums the area of any DrawRect command it sees.
17 class AreaSummer { 18 class AreaSummer {
18 public: 19 public:
19 AreaSummer() : fArea(0) {} 20 AreaSummer() : fArea(0) {}
20 21
21 template <typename T> void operator()(const T&) { } 22 template <typename T> void operator()(const T&) { }
22 23
23 void operator()(const SkRecords::DrawRect& draw) { 24 void operator()(const SkRecords::DrawRect& draw) {
24 fArea += (int)(draw.rect.width() * draw.rect.height()); 25 fArea += (int)(draw.rect.width() * draw.rect.height());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 70
70 // Scale 2x. 71 // Scale 2x.
71 Stretch stretch; 72 Stretch stretch;
72 stretch.apply(&record); 73 stretch.apply(&record);
73 74
74 // Now its area should be 100 + 400. 75 // Now its area should be 100 + 400.
75 summer.apply(record); 76 summer.apply(record);
76 REPORTER_ASSERT(r, summer.area() == 500); 77 REPORTER_ASSERT(r, summer.area() == 500);
77 } 78 }
78 79
80 DEF_TEST(Record_defrag, r) {
81 SkRecord record;
82 APPEND(record, SkRecords::Save);
83 APPEND(record, SkRecords::ClipRect);
84 APPEND(record, SkRecords::NoOp);
85 APPEND(record, SkRecords::DrawRect);
86 APPEND(record, SkRecords::NoOp);
87 APPEND(record, SkRecords::NoOp);
88 APPEND(record, SkRecords::Restore);
89 REPORTER_ASSERT(r, record.count() == 7);
90
91 record.defrag();
92 REPORTER_ASSERT(r, record.count() == 4);
93 assert_type<SkRecords::Save >(r, record, 0);
94 assert_type<SkRecords::ClipRect>(r, record, 1);
95 assert_type<SkRecords::DrawRect>(r, record, 2);
96 assert_type<SkRecords::Restore >(r, record, 3);
97 }
98
79 #undef APPEND 99 #undef APPEND
80 100
81 template <typename T> 101 template <typename T>
82 static bool is_aligned(const T* p) { 102 static bool is_aligned(const T* p) {
83 return (((uintptr_t)p) & (sizeof(T) - 1)) == 0; 103 return (((uintptr_t)p) & (sizeof(T) - 1)) == 0;
84 } 104 }
85 105
86 DEF_TEST(Record_Alignment, r) { 106 DEF_TEST(Record_Alignment, r) {
87 SkRecord record; 107 SkRecord record;
88 REPORTER_ASSERT(r, is_aligned(record.alloc<uint8_t>())); 108 REPORTER_ASSERT(r, is_aligned(record.alloc<uint8_t>()));
89 REPORTER_ASSERT(r, is_aligned(record.alloc<uint16_t>())); 109 REPORTER_ASSERT(r, is_aligned(record.alloc<uint16_t>()));
90 REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>())); 110 REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>()));
91 REPORTER_ASSERT(r, is_aligned(record.alloc<void*>())); 111 REPORTER_ASSERT(r, is_aligned(record.alloc<void*>()));
92 112
93 // It's not clear if we care that 8-byte values are aligned on 32-bit machin es. 113 // It's not clear if we care that 8-byte values are aligned on 32-bit machin es.
94 if (sizeof(void*) == 8) { 114 if (sizeof(void*) == 8) {
95 REPORTER_ASSERT(r, is_aligned(record.alloc<double>())); 115 REPORTER_ASSERT(r, is_aligned(record.alloc<double>()));
96 REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>())); 116 REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>()));
97 } 117 }
98 } 118 }
99 119
OLDNEW
« no previous file with comments | « src/core/SkRecordOpts.cpp ('k') | tests/RecordTestUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698