| 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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkCanvasStateUtils.h" | 10 #include "SkCanvasStateUtils.h" |
| 11 #include "SkDrawFilter.h" | 11 #include "SkDrawFilter.h" |
| 12 #include "SkError.h" | 12 #include "SkError.h" |
| 13 #include "SkPaint.h" | 13 #include "SkPaint.h" |
| 14 #include "SkRRect.h" | 14 #include "SkRRect.h" |
| 15 #include "SkRect.h" | 15 #include "SkRect.h" |
| 16 #include "Test.h" | 16 #include "Test.h" |
| 17 | 17 |
| 18 static void test_complex_layers(skiatest::Reporter* reporter) { | 18 static void test_complex_layers(skiatest::Reporter* reporter) { |
| 19 const int WIDTH = 400; | 19 const int WIDTH = 400; |
| 20 const int HEIGHT = 400; | 20 const int HEIGHT = 400; |
| 21 const int SPACER = 10; | 21 const int SPACER = 10; |
| 22 | 22 |
| 23 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER), | 23 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(SPACER), SkIntToScalar(SPACER), |
| 24 SkIntToScalar(WIDTH-(2*SPACER)), | 24 SkIntToScalar(WIDTH-(2*SPACER)), |
| 25 SkIntToScalar((HEIGHT-(2*SPACER)) / 7)); | 25 SkIntToScalar((HEIGHT-(2*SPACER)) / 7)); |
| 26 | 26 |
| 27 const SkBitmap::Config configs[] = { SkBitmap::kRGB_565_Config, | 27 const SkColorType colorTypes[] = { |
| 28 SkBitmap::kARGB_8888_Config | 28 kRGB_565_SkColorType, kPMColor_SkColorType |
| 29 }; | 29 }; |
| 30 const int configCount = sizeof(configs) / sizeof(SkBitmap::Config); | 30 const int configCount = sizeof(colorTypes) / sizeof(SkBitmap::Config); |
| 31 | 31 |
| 32 const int layerAlpha[] = { 255, 255, 0 }; | 32 const int layerAlpha[] = { 255, 255, 0 }; |
| 33 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, | 33 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, |
| 34 SkCanvas::kARGB_ClipLayer_SaveFlag, | 34 SkCanvas::kARGB_ClipLayer_SaveFlag, |
| 35 SkCanvas::kARGB_NoClipLayer_SaveFlag | 35 SkCanvas::kARGB_NoClipLayer_SaveFlag |
| 36 }; | 36 }; |
| 37 REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); | 37 REPORTER_ASSERT(reporter, sizeof(layerAlpha) == sizeof(flags)); |
| 38 const int layerCombinations = sizeof(layerAlpha) / sizeof(int); | 38 const int layerCombinations = sizeof(layerAlpha) / sizeof(int); |
| 39 | 39 |
| 40 for (int i = 0; i < configCount; ++i) { | 40 for (int i = 0; i < configCount; ++i) { |
| 41 SkBitmap bitmaps[2]; | 41 SkBitmap bitmaps[2]; |
| 42 for (int j = 0; j < 2; ++j) { | 42 for (int j = 0; j < 2; ++j) { |
| 43 bitmaps[j].setConfig(configs[i], WIDTH, HEIGHT); | 43 bitmaps[j].allocPixels(SkImageInfo::Make(WIDTH, HEIGHT, |
| 44 bitmaps[j].allocPixels(); | 44 colorTypes[i], |
| 45 kPremul_SkAlphaType)); |
| 45 | 46 |
| 46 SkCanvas canvas(bitmaps[j]); | 47 SkCanvas canvas(bitmaps[j]); |
| 47 | 48 |
| 48 canvas.drawColor(SK_ColorRED); | 49 canvas.drawColor(SK_ColorRED); |
| 49 | 50 |
| 50 for (int k = 0; k < layerCombinations; ++k) { | 51 for (int k = 0; k < layerCombinations; ++k) { |
| 51 // draw a rect within the layer's bounds and again outside the l
ayer's bounds | 52 // draw a rect within the layer's bounds and again outside the l
ayer's bounds |
| 52 canvas.saveLayerAlpha(&rect, layerAlpha[k], flags[k]); | 53 canvas.saveLayerAlpha(&rect, layerAlpha[k], flags[k]); |
| 53 | 54 |
| 54 SkCanvasState* state = NULL; | 55 SkCanvasState* state = NULL; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 }; | 121 }; |
| 121 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, | 122 const SkCanvas::SaveFlags flags[] = { SkCanvas::kARGB_NoClipLayer_SaveFlag, |
| 122 SkCanvas::kARGB_ClipLayer_SaveFlag, | 123 SkCanvas::kARGB_ClipLayer_SaveFlag, |
| 123 SkCanvas::kARGB_NoClipLayer_SaveFlag, | 124 SkCanvas::kARGB_NoClipLayer_SaveFlag, |
| 124 }; | 125 }; |
| 125 REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); | 126 REPORTER_ASSERT(reporter, sizeof(clipOps) == sizeof(flags)); |
| 126 const int layerCombinations = sizeof(flags) / sizeof(SkCanvas::SaveFlags); | 127 const int layerCombinations = sizeof(flags) / sizeof(SkCanvas::SaveFlags); |
| 127 | 128 |
| 128 SkBitmap bitmaps[2]; | 129 SkBitmap bitmaps[2]; |
| 129 for (int i = 0; i < 2; ++i) { | 130 for (int i = 0; i < 2; ++i) { |
| 130 bitmaps[i].setConfig(SkBitmap::kARGB_8888_Config, WIDTH, HEIGHT); | 131 bitmaps[i].allocN32Pixels(WIDTH, HEIGHT); |
| 131 bitmaps[i].allocPixels(); | |
| 132 | 132 |
| 133 SkCanvas canvas(bitmaps[i]); | 133 SkCanvas canvas(bitmaps[i]); |
| 134 | 134 |
| 135 canvas.drawColor(SK_ColorRED); | 135 canvas.drawColor(SK_ColorRED); |
| 136 | 136 |
| 137 SkRegion localRegion = clipRegion; | 137 SkRegion localRegion = clipRegion; |
| 138 | 138 |
| 139 for (int j = 0; j < layerCombinations; ++j) { | 139 for (int j = 0; j < layerCombinations; ++j) { |
| 140 SkRect layerBounds = SkRect::Make(layerRect); | 140 SkRect layerBounds = SkRect::Make(layerRect); |
| 141 canvas.saveLayerAlpha(&layerBounds, 128, flags[j]); | 141 canvas.saveLayerAlpha(&layerBounds, 128, flags[j]); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); | 225 REPORTER_ASSERT(reporter, kInvalidOperation_SkError == SkGetLastError()); |
| 226 SkClearLastError(); | 226 SkClearLastError(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 DEF_TEST(CanvasState, reporter) { | 229 DEF_TEST(CanvasState, reporter) { |
| 230 test_complex_layers(reporter); | 230 test_complex_layers(reporter); |
| 231 test_complex_clips(reporter); | 231 test_complex_clips(reporter); |
| 232 test_draw_filters(reporter); | 232 test_draw_filters(reporter); |
| 233 test_soft_clips(reporter); | 233 test_soft_clips(reporter); |
| 234 } | 234 } |
| OLD | NEW |