| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 #if SK_SUPPORT_GPU | 96 #if SK_SUPPORT_GPU |
| 97 DEF_GPUTEST(Image_Encode_Gpu, reporter, factory) { | 97 DEF_GPUTEST(Image_Encode_Gpu, reporter, factory) { |
| 98 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); | 98 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); |
| 99 if (!ctx) { | 99 if (!ctx) { |
| 100 REPORTER_ASSERT(reporter, false); | 100 REPORTER_ASSERT(reporter, false); |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 test_encode(reporter, ctx); | 103 test_encode(reporter, ctx); |
| 104 } | 104 } |
| 105 #endif | 105 #endif |
| 106 |
| 107 DEF_TEST(Image_NewRasterCopy, reporter) { |
| 108 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); |
| 109 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); |
| 110 const SkPMColor blue = SkPackARGB32(0xFF, 0, 0, 0xFF); |
| 111 SkPMColor colors[] = { red, green, blue, 0 }; |
| 112 SkAutoTUnref<SkColorTable> ctable(SkNEW_ARGS(SkColorTable, (colors, SK_ARRAY
_COUNT(colors)))); |
| 113 // The colortable made a copy, so we can trash the original colors |
| 114 memset(colors, 0xFF, sizeof(colors)); |
| 115 |
| 116 const SkImageInfo srcInfo = SkImageInfo::Make(2, 2, kIndex_8_SkColorType, kP
remul_SkAlphaType); |
| 117 const size_t srcRowBytes = 2 * sizeof(uint8_t); |
| 118 uint8_t indices[] = { 0, 1, 2, 3 }; |
| 119 SkAutoTUnref<SkImage> image(SkImage::NewRasterCopy(srcInfo, indices, srcRowB
ytes, ctable)); |
| 120 // The image made a copy, so we can trash the original indices |
| 121 memset(indices, 0xFF, sizeof(indices)); |
| 122 |
| 123 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); |
| 124 const size_t dstRowBytes = 2 * sizeof(SkPMColor); |
| 125 SkPMColor pixels[4]; |
| 126 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect |
| 127 image->readPixels(dstInfo, pixels, dstRowBytes, 0, 0); |
| 128 REPORTER_ASSERT(reporter, red == pixels[0]); |
| 129 REPORTER_ASSERT(reporter, green == pixels[1]); |
| 130 REPORTER_ASSERT(reporter, blue == pixels[2]); |
| 131 REPORTER_ASSERT(reporter, 0 == pixels[3]); |
| 132 } |
| OLD | NEW |