OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 | 779 |
780 SkBitmap alphaBitmap; | 780 SkBitmap alphaBitmap; |
781 alphaBitmap.allocN32Pixels(10, 10); | 781 alphaBitmap.allocN32Pixels(10, 10); |
782 for (int y = 0; y < alphaBitmap.height(); ++y) | 782 for (int y = 0; y < alphaBitmap.height(); ++y) |
783 for (int x = 0; x < alphaBitmap.width(); ++x) | 783 for (int x = 0; x < alphaBitmap.width(); ++x) |
784 *alphaBitmap.getAddr32(x, y) = 0x00000000; | 784 *alphaBitmap.getAddr32(x, y) = 0x00000000; |
785 | 785 |
786 SkPaint paint; | 786 SkPaint paint; |
787 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 787 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
788 | 788 |
789 context.writePixels(opaqueBitmap, 50, 50); | 789 { |
Stephen White
2014/10/16 21:48:33
Nit: maybe we should make writePixels a helper fun
f(malita)
2014/10/16 22:02:19
Thanks, done.
| |
790 SkAutoLockPixels locker(opaqueBitmap); | |
791 context.writePixels(opaqueBitmap.info(), opaqueBitmap.getPixels(), opaqu eBitmap.rowBytes(), | |
792 50, 50); | |
793 } | |
790 EXPECT_EQ_RECT(IntRect(50, 50, 10, 10), context.opaqueRegion().asRect()); | 794 EXPECT_EQ_RECT(IntRect(50, 50, 10, 10), context.opaqueRegion().asRect()); |
791 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); | 795 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); |
792 | 796 |
793 context.fillRect(FloatRect(10, 10, 90, 90), opaque, CompositeSourceOver); | 797 context.fillRect(FloatRect(10, 10, 90, 90), opaque, CompositeSourceOver); |
794 EXPECT_EQ_RECT(IntRect(10, 10, 90, 90), context.opaqueRegion().asRect()); | 798 EXPECT_EQ_RECT(IntRect(10, 10, 90, 90), context.opaqueRegion().asRect()); |
795 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); | 799 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); |
796 | 800 |
797 context.writePixels(alphaBitmap, 10, 0); | 801 { |
802 SkAutoLockPixels locker(alphaBitmap); | |
803 context.writePixels(alphaBitmap.info(), alphaBitmap.getPixels(), alphaBi tmap.rowBytes(), | |
804 10, 0); | |
805 } | |
798 EXPECT_EQ_RECT(IntRect(10, 10, 90, 90), context.opaqueRegion().asRect()); | 806 EXPECT_EQ_RECT(IntRect(10, 10, 90, 90), context.opaqueRegion().asRect()); |
799 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); | 807 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); |
800 | 808 |
801 context.writePixels(alphaBitmap, 10, 1); | 809 { |
810 SkAutoLockPixels locker(alphaBitmap); | |
811 context.writePixels(alphaBitmap.info(), alphaBitmap.getPixels(), alphaBi tmap.rowBytes(), | |
812 10, 1); | |
813 } | |
802 EXPECT_EQ_RECT(IntRect(10, 11, 90, 89), context.opaqueRegion().asRect()); | 814 EXPECT_EQ_RECT(IntRect(10, 11, 90, 89), context.opaqueRegion().asRect()); |
803 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); | 815 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); |
804 | 816 |
805 context.writePixels(alphaBitmap, 0, 10); | 817 { |
818 SkAutoLockPixels locker(alphaBitmap); | |
819 context.writePixels(alphaBitmap.info(), alphaBitmap.getPixels(), alphaBi tmap.rowBytes(), | |
820 0, 10); | |
821 } | |
806 EXPECT_EQ_RECT(IntRect(10, 11, 90, 89), context.opaqueRegion().asRect()); | 822 EXPECT_EQ_RECT(IntRect(10, 11, 90, 89), context.opaqueRegion().asRect()); |
807 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); | 823 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); |
808 | 824 |
809 context.writePixels(alphaBitmap, 1, 10); | 825 { |
826 SkAutoLockPixels locker(alphaBitmap); | |
827 context.writePixels(alphaBitmap.info(), alphaBitmap.getPixels(), alphaBi tmap.rowBytes(), | |
828 1, 10); | |
829 } | |
810 EXPECT_EQ_RECT(IntRect(11, 11, 89, 89), context.opaqueRegion().asRect()); | 830 EXPECT_EQ_RECT(IntRect(11, 11, 89, 89), context.opaqueRegion().asRect()); |
811 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); | 831 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); |
812 } | 832 } |
813 | 833 |
814 TEST(GraphicsContextTest, trackOpaqueDrawBitmapTest) | 834 TEST(GraphicsContextTest, trackOpaqueDrawBitmapTest) |
815 { | 835 { |
816 SkBitmap bitmap; | 836 SkBitmap bitmap; |
817 bitmap.allocN32Pixels(200, 200); | 837 bitmap.allocN32Pixels(200, 200); |
818 bitmap.eraseColor(0); | 838 bitmap.eraseColor(0); |
819 SkCanvas canvas(bitmap); | 839 SkCanvas canvas(bitmap); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1208 // endRecording finally makes the picture accessible | 1228 // endRecording finally makes the picture accessible |
1209 RefPtr<DisplayList> dl = context.endRecording(); | 1229 RefPtr<DisplayList> dl = context.endRecording(); |
1210 SkPicture* pic = dl->picture(); | 1230 SkPicture* pic = dl->picture(); |
1211 EXPECT_TRUE(pic); | 1231 EXPECT_TRUE(pic); |
1212 EXPECT_EQ(1, pic->getRefCnt()); | 1232 EXPECT_EQ(1, pic->getRefCnt()); |
1213 | 1233 |
1214 context.endRecording(); | 1234 context.endRecording(); |
1215 } | 1235 } |
1216 | 1236 |
1217 } // namespace | 1237 } // namespace |
OLD | NEW |