| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkColor.h" | 10 #include "SkColor.h" |
| 11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
| 12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
| 13 #include "SkRect.h" | 13 #include "SkRect.h" |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 #include "Test.h" | 15 #include "Test.h" |
| 16 | 16 |
| 17 static const SkColor bgColor = SK_ColorWHITE; | 17 static const SkColor bgColor = SK_ColorWHITE; |
| 18 | 18 |
| 19 static void create(SkBitmap* bm, SkIRect bound, SkBitmap::Config config) { | 19 static void create(SkBitmap* bm, SkIRect bound) { |
| 20 bm->setConfig(config, bound.width(), bound.height()); | 20 bm->allocN32Pixels(bound.width(), bound.height()); |
| 21 bm->allocPixels(); | |
| 22 } | 21 } |
| 23 | 22 |
| 24 static void drawBG(SkCanvas* canvas) { | 23 static void drawBG(SkCanvas* canvas) { |
| 25 canvas->drawColor(bgColor); | 24 canvas->drawColor(bgColor); |
| 26 } | 25 } |
| 27 | 26 |
| 28 /** Assumes that the ref draw was completely inside ref canvas -- | 27 /** Assumes that the ref draw was completely inside ref canvas -- |
| 29 implies that everything outside is "bgColor". | 28 implies that everything outside is "bgColor". |
| 30 Checks that all overlap is the same and that all non-overlap on the | 29 Checks that all overlap is the same and that all non-overlap on the |
| 31 ref is "bgColor". | 30 ref is "bgColor". |
| (...skipping 28 matching lines...) Expand all Loading... |
| 60 return true; | 59 return true; |
| 61 } | 60 } |
| 62 | 61 |
| 63 DEF_TEST(DrawText, reporter) { | 62 DEF_TEST(DrawText, reporter) { |
| 64 SkPaint paint; | 63 SkPaint paint; |
| 65 paint.setColor(SK_ColorGRAY); | 64 paint.setColor(SK_ColorGRAY); |
| 66 paint.setTextSize(SkIntToScalar(20)); | 65 paint.setTextSize(SkIntToScalar(20)); |
| 67 | 66 |
| 68 SkIRect drawTextRect = SkIRect::MakeWH(64, 64); | 67 SkIRect drawTextRect = SkIRect::MakeWH(64, 64); |
| 69 SkBitmap drawTextBitmap; | 68 SkBitmap drawTextBitmap; |
| 70 create(&drawTextBitmap, drawTextRect, SkBitmap::kARGB_8888_Config); | 69 create(&drawTextBitmap, drawTextRect); |
| 71 SkCanvas drawTextCanvas(drawTextBitmap); | 70 SkCanvas drawTextCanvas(drawTextBitmap); |
| 72 | 71 |
| 73 SkIRect drawPosTextRect = SkIRect::MakeWH(64, 64); | 72 SkIRect drawPosTextRect = SkIRect::MakeWH(64, 64); |
| 74 SkBitmap drawPosTextBitmap; | 73 SkBitmap drawPosTextBitmap; |
| 75 create(&drawPosTextBitmap, drawPosTextRect, SkBitmap::kARGB_8888_Config); | 74 create(&drawPosTextBitmap, drawPosTextRect); |
| 76 SkCanvas drawPosTextCanvas(drawPosTextBitmap); | 75 SkCanvas drawPosTextCanvas(drawPosTextBitmap); |
| 77 | 76 |
| 78 for (float offsetY = 0.0f; offsetY < 1.0f; offsetY += (1.0f / 16.0f)) { | 77 for (float offsetY = 0.0f; offsetY < 1.0f; offsetY += (1.0f / 16.0f)) { |
| 79 for (float offsetX = 0.0f; offsetX < 1.0f; offsetX += (1.0f / 16.0f)) { | 78 for (float offsetX = 0.0f; offsetX < 1.0f; offsetX += (1.0f / 16.0f)) { |
| 80 SkPoint point = SkPoint::Make(25.0f + offsetX, | 79 SkPoint point = SkPoint::Make(25.0f + offsetX, |
| 81 25.0f + offsetY); | 80 25.0f + offsetY); |
| 82 | 81 |
| 83 for (int align = 0; align < SkPaint::kAlignCount; ++align) { | 82 for (int align = 0; align < SkPaint::kAlignCount; ++align) { |
| 84 paint.setTextAlign(static_cast<SkPaint::Align>(align)); | 83 paint.setTextAlign(static_cast<SkPaint::Align>(align)); |
| 85 | 84 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 100 drawPosTextCanvas.drawPosText("A", 1, &point, paint); | 99 drawPosTextCanvas.drawPosText("A", 1, &point, paint); |
| 101 | 100 |
| 102 REPORTER_ASSERT(reporter, | 101 REPORTER_ASSERT(reporter, |
| 103 compare(drawTextBitmap, drawTextRect, | 102 compare(drawTextBitmap, drawTextRect, |
| 104 drawPosTextBitmap, drawPosTextRect)); | 103 drawPosTextBitmap, drawPosTextRect)); |
| 105 } | 104 } |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 } | 107 } |
| 109 } | 108 } |
| OLD | NEW |