| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 bitmaps[0].getSize())); | 87 bitmaps[0].getSize())); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
| 92 | 92 |
| 93 static void test_complex_clips(skiatest::Reporter* reporter) { | 93 static void test_complex_clips(skiatest::Reporter* reporter) { |
| 94 | 94 |
| 95 const int WIDTH = 400; | 95 const int WIDTH = 400; |
| 96 const int HEIGHT = 400; | 96 const int HEIGHT = 400; |
| 97 const SkScalar SPACER = SkIntToScalar(10); | 97 const int SPACER = 10; |
| 98 | 98 |
| 99 SkRect layerRect = SkRect::MakeWH(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT
/ 4)); | 99 SkIRect layerRect = SkIRect::MakeWH(WIDTH, HEIGHT / 4); |
| 100 layerRect.inset(2*SPACER, 2*SPACER); | 100 layerRect.inset(2*SPACER, 2*SPACER); |
| 101 | 101 |
| 102 SkRect clipRect = layerRect; | 102 SkIRect clipRect = layerRect; |
| 103 clipRect.fRight = clipRect.fLeft + (clipRect.width() / 2) - (2*SPACER); | 103 clipRect.fRight = clipRect.fLeft + (clipRect.width() / 2) - (2*SPACER); |
| 104 clipRect.outset(SPACER, SPACER); | 104 clipRect.outset(SPACER, SPACER); |
| 105 | 105 |
| 106 SkIRect regionBounds; | 106 SkIRect regionBounds = clipRect; |
| 107 clipRect.roundIn(®ionBounds); | |
| 108 regionBounds.offset(clipRect.width() + (2*SPACER), 0); | 107 regionBounds.offset(clipRect.width() + (2*SPACER), 0); |
| 109 | 108 |
| 110 SkIRect regionInterior = regionBounds; | 109 SkIRect regionInterior = regionBounds; |
| 111 regionInterior.inset(SPACER*3, SPACER*3); | 110 regionInterior.inset(SPACER*3, SPACER*3); |
| 112 | 111 |
| 113 SkRegion clipRegion; | 112 SkRegion clipRegion; |
| 114 clipRegion.setRect(regionBounds); | 113 clipRegion.setRect(regionBounds); |
| 115 clipRegion.op(regionInterior, SkRegion::kDifference_Op); | 114 clipRegion.op(regionInterior, SkRegion::kDifference_Op); |
| 116 | 115 |
| 117 | 116 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 131 bitmaps[i].setConfig(SkBitmap::kARGB_8888_Config, WIDTH, HEIGHT); | 130 bitmaps[i].setConfig(SkBitmap::kARGB_8888_Config, WIDTH, HEIGHT); |
| 132 bitmaps[i].allocPixels(); | 131 bitmaps[i].allocPixels(); |
| 133 | 132 |
| 134 SkCanvas canvas(bitmaps[i]); | 133 SkCanvas canvas(bitmaps[i]); |
| 135 | 134 |
| 136 canvas.drawColor(SK_ColorRED); | 135 canvas.drawColor(SK_ColorRED); |
| 137 | 136 |
| 138 SkRegion localRegion = clipRegion; | 137 SkRegion localRegion = clipRegion; |
| 139 | 138 |
| 140 for (int j = 0; j < layerCombinations; ++j) { | 139 for (int j = 0; j < layerCombinations; ++j) { |
| 141 canvas.saveLayerAlpha(&layerRect, 128, flags[j]); | 140 SkRect layerBounds = SkRect::Make(layerRect); |
| 141 canvas.saveLayerAlpha(&layerBounds, 128, flags[j]); |
| 142 | 142 |
| 143 SkCanvasState* state = NULL; | 143 SkCanvasState* state = NULL; |
| 144 SkCanvas* tmpCanvas = NULL; | 144 SkCanvas* tmpCanvas = NULL; |
| 145 if (i) { | 145 if (i) { |
| 146 state = SkCanvasStateUtils::CaptureCanvasState(&canvas); | 146 state = SkCanvasStateUtils::CaptureCanvasState(&canvas); |
| 147 REPORTER_ASSERT(reporter, state); | 147 REPORTER_ASSERT(reporter, state); |
| 148 tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); | 148 tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state); |
| 149 REPORTER_ASSERT(reporter, tmpCanvas); | 149 REPORTER_ASSERT(reporter, tmpCanvas); |
| 150 } else { | 150 } else { |
| 151 tmpCanvas = SkRef(&canvas); | 151 tmpCanvas = SkRef(&canvas); |
| 152 } | 152 } |
| 153 | 153 |
| 154 tmpCanvas->save(); | 154 tmpCanvas->save(); |
| 155 tmpCanvas->clipRect(clipRect, clipOps[j]); | 155 tmpCanvas->clipRect(SkRect::Make(clipRect), clipOps[j]); |
| 156 tmpCanvas->drawColor(SK_ColorBLUE); | 156 tmpCanvas->drawColor(SK_ColorBLUE); |
| 157 tmpCanvas->restore(); | 157 tmpCanvas->restore(); |
| 158 | 158 |
| 159 tmpCanvas->clipRegion(localRegion, clipOps[j]); | 159 tmpCanvas->clipRegion(localRegion, clipOps[j]); |
| 160 tmpCanvas->drawColor(SK_ColorBLUE); | 160 tmpCanvas->drawColor(SK_ColorBLUE); |
| 161 | 161 |
| 162 tmpCanvas->unref(); | 162 tmpCanvas->unref(); |
| 163 SkCanvasStateUtils::ReleaseCanvasState(state); | 163 SkCanvasStateUtils::ReleaseCanvasState(state); |
| 164 | 164 |
| 165 canvas.restore(); | 165 canvas.restore(); |
| 166 | 166 |
| 167 // translate the canvas and region for the next iteration | 167 // translate the canvas and region for the next iteration |
| 168 canvas.translate(0, 2*(layerRect.height() + SPACER)); | 168 canvas.translate(0, SkIntToScalar(2*(layerRect.height() + (SPACER)))
); |
| 169 localRegion.translate(0, 2*(layerRect.height() + SPACER)); | 169 localRegion.translate(0, 2*(layerRect.height() + SPACER)); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 // now we memcmp the two bitmaps | 173 // now we memcmp the two bitmaps |
| 174 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); | 174 REPORTER_ASSERT(reporter, bitmaps[0].getSize() == bitmaps[1].getSize()); |
| 175 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), | 175 REPORTER_ASSERT(reporter, !memcmp(bitmaps[0].getPixels(), |
| 176 bitmaps[1].getPixels(), | 176 bitmaps[1].getPixels(), |
| 177 bitmaps[0].getSize())); | 177 bitmaps[0].getSize())); |
| 178 } | 178 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 222 |
| 223 static void test_canvas_state_utils(skiatest::Reporter* reporter) { | 223 static void test_canvas_state_utils(skiatest::Reporter* reporter) { |
| 224 test_complex_layers(reporter); | 224 test_complex_layers(reporter); |
| 225 test_complex_clips(reporter); | 225 test_complex_clips(reporter); |
| 226 test_draw_filters(reporter); | 226 test_draw_filters(reporter); |
| 227 test_soft_clips(reporter); | 227 test_soft_clips(reporter); |
| 228 } | 228 } |
| 229 | 229 |
| 230 #include "TestClassDef.h" | 230 #include "TestClassDef.h" |
| 231 DEFINE_TESTCLASS("CanvasState", TestCanvasStateClass, test_canvas_state_utils) | 231 DEFINE_TESTCLASS("CanvasState", TestCanvasStateClass, test_canvas_state_utils) |
| OLD | NEW |