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 <functional> | 8 #include <functional> |
9 #include <initializer_list> | 9 #include <initializer_list> |
10 #include "DMGpuSupport.h" | 10 #include "DMGpuSupport.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 SkPaint paint; | 60 SkPaint paint; |
61 paint.setColor(SK_ColorBLACK); | 61 paint.setColor(SK_ColorBLACK); |
62 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); | 62 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); |
63 } | 63 } |
64 static sk_sp<SkImage> create_image() { | 64 static sk_sp<SkImage> create_image() { |
65 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 65 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
66 auto surface(SkSurface::MakeRaster(info)); | 66 auto surface(SkSurface::MakeRaster(info)); |
67 draw_image_test_pattern(surface->getCanvas()); | 67 draw_image_test_pattern(surface->getCanvas()); |
68 return surface->makeImageSnapshot(); | 68 return surface->makeImageSnapshot(); |
69 } | 69 } |
| 70 |
| 71 static SkData* create_image_data(SkImageInfo* info) { |
| 72 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
| 73 const size_t rowBytes = info->minRowBytes(); |
| 74 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height()
)); |
| 75 { |
| 76 SkBitmap bm; |
| 77 bm.installPixels(*info, data->writable_data(), rowBytes); |
| 78 SkCanvas canvas(bm); |
| 79 draw_image_test_pattern(&canvas); |
| 80 } |
| 81 return data.release(); |
| 82 } |
| 83 static sk_sp<SkImage> create_data_image() { |
| 84 SkImageInfo info; |
| 85 sk_sp<SkData> data(create_image_data(&info)); |
| 86 return SkImage::MakeRasterData(info, data, info.minRowBytes()); |
| 87 } |
| 88 #if SK_SUPPORT_GPU // not gpu-specific but currently only used in GPU tests |
70 static sk_sp<SkImage> create_image_565() { | 89 static sk_sp<SkImage> create_image_565() { |
71 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp
aque_SkAlphaType); | 90 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp
aque_SkAlphaType); |
72 auto surface(SkSurface::MakeRaster(info)); | 91 auto surface(SkSurface::MakeRaster(info)); |
73 draw_image_test_pattern(surface->getCanvas()); | 92 draw_image_test_pattern(surface->getCanvas()); |
74 return surface->makeImageSnapshot(); | 93 return surface->makeImageSnapshot(); |
75 } | 94 } |
76 static sk_sp<SkImage> create_image_ct() { | 95 static sk_sp<SkImage> create_image_ct() { |
77 SkPMColor colors[] = { | 96 SkPMColor colors[] = { |
78 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), | 97 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), |
79 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF), | 98 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF), |
80 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB) | 99 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB) |
81 }; | 100 }; |
82 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN
T(colors))); | 101 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN
T(colors))); |
83 uint8_t data[] = { | 102 uint8_t data[] = { |
84 0, 0, 0, 0, 0, | 103 0, 0, 0, 0, 0, |
85 0, 1, 1, 1, 0, | 104 0, 1, 1, 1, 0, |
86 0, 1, 2, 1, 0, | 105 0, 1, 2, 1, 0, |
87 0, 1, 1, 1, 0, | 106 0, 1, 1, 1, 0, |
88 0, 0, 0, 0, 0 | 107 0, 0, 0, 0, 0 |
89 }; | 108 }; |
90 SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkA
lphaType); | 109 SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkA
lphaType); |
91 return SkImage::MakeRasterCopy(SkPixmap(info, data, 5, colorTable)); | 110 return SkImage::MakeRasterCopy(SkPixmap(info, data, 5, colorTable)); |
92 } | 111 } |
93 static SkData* create_image_data(SkImageInfo* info) { | |
94 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | |
95 const size_t rowBytes = info->minRowBytes(); | |
96 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height()
)); | |
97 { | |
98 SkBitmap bm; | |
99 bm.installPixels(*info, data->writable_data(), rowBytes); | |
100 SkCanvas canvas(bm); | |
101 draw_image_test_pattern(&canvas); | |
102 } | |
103 return data.release(); | |
104 } | |
105 static sk_sp<SkImage> create_data_image() { | |
106 SkImageInfo info; | |
107 sk_sp<SkData> data(create_image_data(&info)); | |
108 return SkImage::MakeRasterData(info, data, info.minRowBytes()); | |
109 } | |
110 #if SK_SUPPORT_GPU // not gpu-specific but currently only used in GPU tests | |
111 static sk_sp<SkImage> create_picture_image() { | 112 static sk_sp<SkImage> create_picture_image() { |
112 SkPictureRecorder recorder; | 113 SkPictureRecorder recorder; |
113 SkCanvas* canvas = recorder.beginRecording(10, 10); | 114 SkCanvas* canvas = recorder.beginRecording(10, 10); |
114 canvas->clear(SK_ColorCYAN); | 115 canvas->clear(SK_ColorCYAN); |
115 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize
::Make(10, 10), | 116 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize
::Make(10, 10), |
116 nullptr, nullptr); | 117 nullptr, nullptr); |
117 }; | 118 }; |
118 #endif | 119 #endif |
119 // Want to ensure that our Release is called when the owning image is destroyed | 120 // Want to ensure that our Release is called when the owning image is destroyed |
120 struct RasterDataHolder { | 121 struct RasterDataHolder { |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 otherContextInfo.fGrContext, buffer, budgeted)); | 891 otherContextInfo.fGrContext, buffer, budgeted)); |
891 REPORTER_ASSERT(reporter, !newImage2); | 892 REPORTER_ASSERT(reporter, !newImage2); |
892 glContext->makeCurrent(); | 893 glContext->makeCurrent(); |
893 } | 894 } |
894 } | 895 } |
895 sk_free(buffer); | 896 sk_free(buffer); |
896 } | 897 } |
897 } | 898 } |
898 } | 899 } |
899 #endif | 900 #endif |
OLD | NEW |