OLD | NEW |
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 "CanvasStateHelpers.h" | 8 #include "CanvasStateHelpers.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCanvasStateUtils.h" | 10 #include "SkCanvasStateUtils.h" |
11 #include "SkCommandLineFlags.h" | 11 #include "SkCommandLineFlags.h" |
12 #include "SkDrawFilter.h" | 12 #include "SkDrawFilter.h" |
13 #include "SkError.h" | 13 #include "SkError.h" |
14 #include "SkPaint.h" | 14 #include "SkPaint.h" |
15 #include "SkRRect.h" | 15 #include "SkRRect.h" |
16 #include "SkRect.h" | 16 #include "SkRect.h" |
| 17 #include "SkTLazy.h" |
17 #include "Test.h" | 18 #include "Test.h" |
18 | 19 |
19 // dlopen and the library flag are only used for tests which require this flag. | 20 // dlopen and the library flag are only used for tests which require this flag. |
20 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 21 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
21 #include <dlfcn.h> | 22 #include <dlfcn.h> |
22 | 23 |
23 DEFINE_string(library, "", "Support library to use for CanvasState test. If empt
y (the default), " | 24 DEFINE_string(library, "", "Support library to use for CanvasState test. If empt
y (the default), " |
24 "the test will be run without crossing a library boun
dary. Otherwise, " | 25 "the test will be run without crossing a library boun
dary. Otherwise, " |
25 "it is expected to be a full path to a shared library
file, which will" | 26 "it is expected to be a full path to a shared library
file, which will" |
26 " be dynamically loaded. Functions from the library w
ill be called to " | 27 " be dynamically loaded. Functions from the library w
ill be called to " |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 65 |
65 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER), | 66 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER), |
66 SkIntToScalar(WIDTH-(2*SPACER)), | 67 SkIntToScalar(WIDTH-(2*SPACER)), |
67 SkIntToScalar((HEIGHT-(2*SPACER)) / 7)); | 68 SkIntToScalar((HEIGHT-(2*SPACER)) / 7)); |
68 | 69 |
69 const SkColorType colorTypes[] = { | 70 const SkColorType colorTypes[] = { |
70 kRGB_565_SkColorType, kN32_SkColorType | 71 kRGB_565_SkColorType, kN32_SkColorType |
71 }; | 72 }; |
72 | 73 |
73 const int layerAlpha[] = { 255, 255, 0 }; | 74 const int layerAlpha[] = { 255, 255, 0 }; |
74 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, | 75 const SkCanvas::SaveLayerFlags flags[] = { |
75 SkCanvas::kARGB_ClipLayer_SaveFlag, | 76 static_cast<SkCanvas::SaveLayerFlags>(SkCanvas::kDontClipToLayer_Legacy_
SaveLayerFlag), |
76 SkCanvas::kARGB_NoClipLayer_SaveFlag | 77 0, |
| 78 static_cast<SkCanvas::SaveLayerFlags>(SkCanvas::kDontClipToLayer_Legacy_
SaveLayerFlag), |
77 }; | 79 }; |
78 REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); | 80 REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); |
79 | 81 |
80 bool (*drawFn)(SkCanvasState* state, float l, float t, | 82 bool (*drawFn)(SkCanvasState* state, float l, float t, |
81 float r, float b, int32_t s); | 83 float r, float b, int32_t s); |
82 | 84 |
83 OpenLibResult openLibResult(reporter); | 85 OpenLibResult openLibResult(reporter); |
84 if (openLibResult.handle() != nullptr) { | 86 if (openLibResult.handle() != nullptr) { |
85 *(void**) (&drawFn) = dlsym(openLibResult.handle(), | 87 *(void**) (&drawFn) = dlsym(openLibResult.handle(), |
86 "complex_layers_draw_from_canvas_state"); | 88 "complex_layers_draw_from_canvas_state"); |
(...skipping 11 matching lines...) Expand all Loading... |
98 for (int j = 0; j < 2; ++j) { | 100 for (int j = 0; j < 2; ++j) { |
99 bitmaps[j].allocPixels(SkImageInfo::Make(WIDTH, HEIGHT, | 101 bitmaps[j].allocPixels(SkImageInfo::Make(WIDTH, HEIGHT, |
100 colorTypes[i], | 102 colorTypes[i], |
101 kPremul_SkAlphaType)); | 103 kPremul_SkAlphaType)); |
102 | 104 |
103 SkCanvas canvas(bitmaps[j]); | 105 SkCanvas canvas(bitmaps[j]); |
104 | 106 |
105 canvas.drawColor(SK_ColorRED); | 107 canvas.drawColor(SK_ColorRED); |
106 | 108 |
107 for (size_t k = 0; k < SK_ARRAY_COUNT(layerAlpha); ++k) { | 109 for (size_t k = 0; k < SK_ARRAY_COUNT(layerAlpha); ++k) { |
| 110 SkTLazy<SkPaint> paint; |
| 111 if (layerAlpha[k] != 0xFF) { |
| 112 paint.init()->setAlpha(layerAlpha[k]); |
| 113 } |
| 114 |
108 // draw a rect within the layer's bounds and again outside the l
ayer's bounds | 115 // draw a rect within the layer's bounds and again outside the l
ayer's bounds |
109 canvas.saveLayerAlpha(&rect, layerAlpha[k], flags[k]); | 116 canvas.saveLayer(SkCanvas::SaveLayerRec(&rect, paint.getMaybeNul
l(), flags[k])); |
110 | 117 |
111 if (j) { | 118 if (j) { |
112 // Capture from the first Skia. | 119 // Capture from the first Skia. |
113 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasStat
e(&canvas); | 120 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasStat
e(&canvas); |
114 REPORTER_ASSERT(reporter, state); | 121 REPORTER_ASSERT(reporter, state); |
115 | 122 |
116 // And draw to it in the second Skia. | 123 // And draw to it in the second Skia. |
117 bool success = complex_layers_draw_from_canvas_state(state, | 124 bool success = complex_layers_draw_from_canvas_state(state, |
118 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, SP
ACER); | 125 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, SP
ACER); |
119 REPORTER_ASSERT(reporter, success); | 126 REPORTER_ASSERT(reporter, success); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 172 |
166 SkRegion clipRegion; | 173 SkRegion clipRegion; |
167 clipRegion.setRect(regionBounds); | 174 clipRegion.setRect(regionBounds); |
168 clipRegion.op(regionInterior, SkRegion::kDifference_Op); | 175 clipRegion.op(regionInterior, SkRegion::kDifference_Op); |
169 | 176 |
170 | 177 |
171 const SkRegion::Op clipOps[] = { SkRegion::kIntersect_Op, | 178 const SkRegion::Op clipOps[] = { SkRegion::kIntersect_Op, |
172 SkRegion::kIntersect_Op, | 179 SkRegion::kIntersect_Op, |
173 SkRegion::kReplace_Op, | 180 SkRegion::kReplace_Op, |
174 }; | 181 }; |
175 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, | 182 const SkCanvas::SaveLayerFlags flags[] = { |
176 SkCanvas::kARGB_ClipLayer_SaveFlag, | 183 static_cast<SkCanvas::SaveLayerFlags>(SkCanvas::kDontClipToLayer_Legacy_
SaveLayerFlag), |
177 SkCanvas::kARGB_NoClipLayer_SaveFlag, | 184 0, |
| 185 static_cast<SkCanvas::SaveLayerFlags>(SkCanvas::kDontClipToLayer_Legacy_
SaveLayerFlag), |
178 }; | 186 }; |
179 REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); | 187 REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); |
180 | 188 |
181 bool (*drawFn)(SkCanvasState* state, int32_t l, int32_t t, | 189 bool (*drawFn)(SkCanvasState* state, int32_t l, int32_t t, |
182 int32_t r, int32_t b, int32_t clipOp, | 190 int32_t r, int32_t b, int32_t clipOp, |
183 int32_t regionRects, int32_t* rectCoords); | 191 int32_t regionRects, int32_t* rectCoords); |
184 | 192 |
185 OpenLibResult openLibResult(reporter); | 193 OpenLibResult openLibResult(reporter); |
186 if (openLibResult.handle() != nullptr) { | 194 if (openLibResult.handle() != nullptr) { |
187 *(void**) (&drawFn) = dlsym(openLibResult.handle(), | 195 *(void**) (&drawFn) = dlsym(openLibResult.handle(), |
(...skipping 10 matching lines...) Expand all Loading... |
198 SkBitmap bitmaps[2]; | 206 SkBitmap bitmaps[2]; |
199 for (int i = 0; i < 2; ++i) { | 207 for (int i = 0; i < 2; ++i) { |
200 bitmaps[i].allocN32Pixels(WIDTH, HEIGHT); | 208 bitmaps[i].allocN32Pixels(WIDTH, HEIGHT); |
201 | 209 |
202 SkCanvas canvas(bitmaps[i]); | 210 SkCanvas canvas(bitmaps[i]); |
203 | 211 |
204 canvas.drawColor(SK_ColorRED); | 212 canvas.drawColor(SK_ColorRED); |
205 | 213 |
206 SkRegion localRegion = clipRegion; | 214 SkRegion localRegion = clipRegion; |
207 | 215 |
| 216 SkPaint paint; |
| 217 paint.setAlpha(128); |
208 for (size_t j = 0; j < SK_ARRAY_COUNT(flags); ++j) { | 218 for (size_t j = 0; j < SK_ARRAY_COUNT(flags); ++j) { |
209 SkRect layerBounds = SkRect::Make(layerRect); | 219 SkRect layerBounds = SkRect::Make(layerRect); |
210 canvas.saveLayerAlpha(&layerBounds, 128, flags[j]); | 220 canvas.saveLayer(SkCanvas::SaveLayerRec(&layerBounds, &paint, flags[
j])); |
211 | 221 |
212 if (i) { | 222 if (i) { |
213 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&c
anvas); | 223 SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&c
anvas); |
214 REPORTER_ASSERT(reporter, state); | 224 REPORTER_ASSERT(reporter, state); |
215 | 225 |
216 SkRegion::Iterator iter(localRegion); | 226 SkRegion::Iterator iter(localRegion); |
217 SkTDArray<int32_t> rectCoords; | 227 SkTDArray<int32_t> rectCoords; |
218 for (; !iter.done(); iter.next()) { | 228 for (; !iter.done(); iter.next()) { |
219 const SkIRect& rect = iter.rect(); | 229 const SkIRect& rect = iter.rect(); |
220 *rectCoords.append() = rect.fLeft; | 230 *rectCoords.append() = rect.fLeft; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 321 |
312 SkBitmap bitmap; | 322 SkBitmap bitmap; |
313 bitmap.allocN32Pixels(WIDTH, HEIGHT); | 323 bitmap.allocN32Pixels(WIDTH, HEIGHT); |
314 SkCanvas canvas(bitmap); | 324 SkCanvas canvas(bitmap); |
315 | 325 |
316 SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAY
ER_HEIGHT)); | 326 SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAY
ER_HEIGHT)); |
317 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)))
; | 327 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)))
; |
318 | 328 |
319 // Check that saveLayer without the kClipToLayer_SaveFlag leaves the | 329 // Check that saveLayer without the kClipToLayer_SaveFlag leaves the |
320 // clip stack unchanged. | 330 // clip stack unchanged. |
321 canvas.saveLayer(&bounds, nullptr, SkCanvas::kARGB_NoClipLayer_SaveFlag); | 331 canvas.saveLayer(SkCanvas::SaveLayerRec(&bounds, |
| 332 nullptr, |
| 333 SkCanvas::kDontClipToLayer_Legacy_Sa
veLayerFlag)); |
322 SkRect clipStackBounds; | 334 SkRect clipStackBounds; |
323 SkClipStack::BoundsType boundsType; | 335 SkClipStack::BoundsType boundsType; |
324 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); | 336 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); |
325 // The clip stack will return its bounds, or it may be "full" : i.e. empty +
inside_out. | 337 // The clip stack will return its bounds, or it may be "full" : i.e. empty +
inside_out. |
326 // Either result is consistent with this test, since the canvas' size is WID
TH/HEIGHT | 338 // Either result is consistent with this test, since the canvas' size is WID
TH/HEIGHT |
327 if (SkClipStack::kInsideOut_BoundsType == boundsType) { | 339 if (SkClipStack::kInsideOut_BoundsType == boundsType) { |
328 REPORTER_ASSERT(reporter, clipStackBounds.isEmpty()); | 340 REPORTER_ASSERT(reporter, clipStackBounds.isEmpty()); |
329 } else { | 341 } else { |
330 REPORTER_ASSERT(reporter, clipStackBounds.width() == WIDTH); | 342 REPORTER_ASSERT(reporter, clipStackBounds.width() == WIDTH); |
331 REPORTER_ASSERT(reporter, clipStackBounds.height() == HEIGHT); | 343 REPORTER_ASSERT(reporter, clipStackBounds.height() == HEIGHT); |
332 } | 344 } |
333 canvas.restore(); | 345 canvas.restore(); |
334 | 346 |
335 // Check that saveLayer with the kClipToLayer_SaveFlag sets the clip | 347 // Check that saveLayer with the kClipToLayer_SaveFlag sets the clip |
336 // stack to the layer bounds. | 348 // stack to the layer bounds. |
337 canvas.saveLayer(&bounds, nullptr, SkCanvas::kARGB_ClipLayer_SaveFlag); | 349 canvas.saveLayer(&bounds, nullptr); |
338 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); | 350 canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType); |
339 REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH); | 351 REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH); |
340 REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); | 352 REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT); |
341 | 353 |
342 canvas.restore(); | 354 canvas.restore(); |
343 } | 355 } |
344 #endif | 356 #endif |
OLD | NEW |