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

Side by Side Diff: tests/RecordTest.cpp

Issue 517073002: Align all SkRecord::alloc() calls up to at least a pointer size. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkAlignPtr Created 6 years, 3 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
« no previous file with comments | « src/core/SkRecord.h ('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 /* 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 "Test.h" 8 #include "Test.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 Stretch stretch; 71 Stretch stretch;
72 stretch.apply(&record); 72 stretch.apply(&record);
73 73
74 // Now its area should be 100 + 400. 74 // Now its area should be 100 + 400.
75 summer.apply(record); 75 summer.apply(record);
76 REPORTER_ASSERT(r, summer.area() == 500); 76 REPORTER_ASSERT(r, summer.area() == 500);
77 } 77 }
78 78
79 #undef APPEND 79 #undef APPEND
80 80
81 template <typename T>
82 static bool is_aligned(const T* p) {
83 return (((uintptr_t)p) & (sizeof(T) - 1)) == 0;
84 }
85
86 DEF_TEST(Record_Alignment, r) {
87 SkRecord record;
88
89 // Of course a byte's always aligned.
90 REPORTER_ASSERT(r, is_aligned(record.alloc<uint8_t>()));
91
92 // (If packed tightly, the rest below here would be off by one.)
93
94 // It happens that the first implementation always aligned to 4 bytes,
95 // so these two were always correct.
96 REPORTER_ASSERT(r, is_aligned(record.alloc<uint16_t>()));
97 REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>()));
98
99 // These two are regression tests (void* only on 64-bit machines).
100 REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>()));
101 REPORTER_ASSERT(r, is_aligned(record.alloc<void*>()));
102
103 // We're not testing beyond sizeof(void*), which is where the current implem entation will break.
104 }
105
OLDNEW
« no previous file with comments | « src/core/SkRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698