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

Side by Side Diff: tests/LayerDrawLooperTest.cpp

Issue 2488523003: Make SkSmallAllocator obey the RAII invariants and be expandable (Closed)
Patch Set: Strip pointer to make correct type Created 4 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/SkSmallAllocator.h ('k') | tests/SmallAllocatorTest.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 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 layerInfo.fOffset.set(10.0f, 20.0f); 53 layerInfo.fOffset.set(10.0f, 20.0f);
54 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; 54 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
55 SkPaint* layerPaint = looperBuilder.addLayer(layerInfo); 55 SkPaint* layerPaint = looperBuilder.addLayer(layerInfo);
56 layerPaint->setBlendMode(SkBlendMode::kSrc); 56 layerPaint->setBlendMode(SkBlendMode::kSrc);
57 57
58 FakeDevice device; 58 FakeDevice device;
59 SkCanvas canvas(&device); 59 SkCanvas canvas(&device);
60 SkPaint paint; 60 SkPaint paint;
61 auto looper(looperBuilder.detach()); 61 auto looper(looperBuilder.detach());
62 SkSmallAllocator<1, 32> allocator; 62 SkSmallAllocator<1, 32> allocator;
63 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ()); 63 SkDrawLooper::Context* context = allocator.createWithIniter(
64 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); 64 looper->contextSize(),
65 [&](void* buffer) {
66 return looper->createContext(&canvas, buffer);
67 });
65 68
66 // The back layer should come first. 69 // The back layer should come first.
67 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 70 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
68 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc); 71 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
69 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 72 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
70 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); 73 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
71 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); 74 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
72 paint.reset(); 75 paint.reset();
73 76
74 // Then the front layer. 77 // Then the front layer.
(...skipping 18 matching lines...) Expand all
93 layerInfo.fOffset.set(10.0f, 20.0f); 96 layerInfo.fOffset.set(10.0f, 20.0f);
94 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; 97 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
95 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); 98 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo);
96 layerPaint->setBlendMode(SkBlendMode::kSrc); 99 layerPaint->setBlendMode(SkBlendMode::kSrc);
97 100
98 FakeDevice device; 101 FakeDevice device;
99 SkCanvas canvas(&device); 102 SkCanvas canvas(&device);
100 SkPaint paint; 103 SkPaint paint;
101 auto looper(looperBuilder.detach()); 104 auto looper(looperBuilder.detach());
102 SkSmallAllocator<1, 32> allocator; 105 SkSmallAllocator<1, 32> allocator;
103 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ()); 106 SkDrawLooper::Context* context = allocator.createWithIniter(
104 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); 107 looper->contextSize(),
108 [&](void* buffer) {
109 return looper->createContext(&canvas, buffer);
110 });
105 111
106 // The back layer should come first. 112 // The back layer should come first.
107 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 113 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
108 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver); 114 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
109 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 115 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
110 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); 116 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
111 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); 117 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
112 paint.reset(); 118 paint.reset();
113 119
114 // Then the front layer. 120 // Then the front layer.
(...skipping 18 matching lines...) Expand all
133 layerInfo.fOffset.set(10.0f, 20.0f); 139 layerInfo.fOffset.set(10.0f, 20.0f);
134 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit; 140 layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
135 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo); 141 SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo);
136 layerPaint->setBlendMode(SkBlendMode::kSrc); 142 layerPaint->setBlendMode(SkBlendMode::kSrc);
137 143
138 FakeDevice device; 144 FakeDevice device;
139 SkCanvas canvas(&device); 145 SkCanvas canvas(&device);
140 SkPaint paint; 146 SkPaint paint;
141 sk_sp<SkDrawLooper> looper(looperBuilder.detach()); 147 sk_sp<SkDrawLooper> looper(looperBuilder.detach());
142 SkSmallAllocator<1, 32> allocator; 148 SkSmallAllocator<1, 32> allocator;
143 void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize ()); 149 SkDrawLooper::Context* context = allocator.createWithIniter(
144 SkDrawLooper::Context* context = looper->createContext(&canvas, buffer); 150 looper->contextSize(),
151 [&](void* buffer) {
152 return looper->createContext(&canvas, buffer);
153 });
145 154
146 // The back layer should come first. 155 // The back layer should come first.
147 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 156 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
148 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver); 157 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
149 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 158 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
150 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX()); 159 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
151 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY()); 160 REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
152 paint.reset(); 161 paint.reset();
153 162
154 // Then the front layer. 163 // Then the front layer.
155 REPORTER_ASSERT(reporter, context->next(&canvas, &paint)); 164 REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
156 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc); 165 REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
157 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint); 166 canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
158 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX()); 167 REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
159 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY()); 168 REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
160 169
161 // Only two layers were added, so that should be the end. 170 // Only two layers were added, so that should be the end.
162 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint)); 171 REPORTER_ASSERT(reporter, !context->next(&canvas, &paint));
163 } 172 }
164 173
165 DEF_TEST(LayerDrawLooper, reporter) { 174 DEF_TEST(LayerDrawLooper, reporter) {
166 test_frontToBack(reporter); 175 test_frontToBack(reporter);
167 test_backToFront(reporter); 176 test_backToFront(reporter);
168 test_mixed(reporter); 177 test_mixed(reporter);
169 } 178 }
OLDNEW
« no previous file with comments | « src/core/SkSmallAllocator.h ('k') | tests/SmallAllocatorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698