| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "Request.h" | 8 #include "Request.h" |
| 9 | 9 |
| 10 #include "SkPictureRecorder.h" | 10 #include "SkPictureRecorder.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 bounds = SkIRect::MakeWH(SkTMin(bounds.width(), kMaxWidth), | 154 bounds = SkIRect::MakeWH(SkTMin(bounds.width(), kMaxWidth), |
| 155 SkTMin(bounds.height(), kMaxHeight)); | 155 SkTMin(bounds.height(), kMaxHeight)); |
| 156 return bounds; | 156 return bounds; |
| 157 } | 157 } |
| 158 | 158 |
| 159 namespace { | 159 namespace { |
| 160 | 160 |
| 161 struct ColorAndProfile { | 161 struct ColorAndProfile { |
| 162 SkColorType fColorType; | 162 SkColorType fColorType; |
| 163 bool fSRGB; | 163 bool fSRGB; |
| 164 bool fGammaCorrect; | |
| 165 }; | 164 }; |
| 166 | 165 |
| 167 ColorAndProfile ColorModes[] = { | 166 ColorAndProfile ColorModes[] = { |
| 168 { kN32_SkColorType, false, false }, | 167 { kN32_SkColorType, false }, |
| 169 { kN32_SkColorType, true, true }, | 168 { kN32_SkColorType, true }, |
| 170 { kRGBA_F16_SkColorType, true, true }, | 169 { kRGBA_F16_SkColorType, true }, |
| 171 }; | 170 }; |
| 172 | 171 |
| 173 } | 172 } |
| 174 | 173 |
| 175 SkSurface* Request::createCPUSurface() { | 174 SkSurface* Request::createCPUSurface() { |
| 176 SkIRect bounds = this->getBounds(); | 175 SkIRect bounds = this->getBounds(); |
| 177 ColorAndProfile cap = ColorModes[fColorMode]; | 176 ColorAndProfile cap = ColorModes[fColorMode]; |
| 178 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 177 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 179 SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fC
olorType, | 178 SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fC
olorType, |
| 180 kPremul_SkAlphaType, cap.fSRGB ? srgbCo
lorSpace : nullptr); | 179 kPremul_SkAlphaType, cap.fSRGB ? srgbCo
lorSpace : nullptr); |
| 181 uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0; | 180 return SkSurface::MakeRaster(info).release(); |
| 182 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); | |
| 183 return SkSurface::MakeRaster(info, &props).release(); | |
| 184 } | 181 } |
| 185 | 182 |
| 186 SkSurface* Request::createGPUSurface() { | 183 SkSurface* Request::createGPUSurface() { |
| 187 GrContext* context = this->getContext(); | 184 GrContext* context = this->getContext(); |
| 188 SkIRect bounds = this->getBounds(); | 185 SkIRect bounds = this->getBounds(); |
| 189 ColorAndProfile cap = ColorModes[fColorMode]; | 186 ColorAndProfile cap = ColorModes[fColorMode]; |
| 190 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 187 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 191 SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fC
olorType, | 188 SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fC
olorType, |
| 192 kPremul_SkAlphaType, cap.fSRGB ? srgbCo
lorSpace : nullptr); | 189 kPremul_SkAlphaType, cap.fSRGB ? srgbCo
lorSpace : nullptr); |
| 193 uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0; | 190 SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, i
nfo).release(); |
| 194 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); | |
| 195 SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, i
nfo, 0, | |
| 196 &props).release(); | |
| 197 return surface; | 191 return surface; |
| 198 } | 192 } |
| 199 | 193 |
| 200 bool Request::setColorMode(int mode) { | 194 bool Request::setColorMode(int mode) { |
| 201 fColorMode = mode; | 195 fColorMode = mode; |
| 202 return enableGPU(fGPUEnabled); | 196 return enableGPU(fGPUEnabled); |
| 203 } | 197 } |
| 204 | 198 |
| 205 bool Request::enableGPU(bool enable) { | 199 bool Request::enableGPU(bool enable) { |
| 206 if (enable) { | 200 if (enable) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 SkASSERT(bitmap); | 294 SkASSERT(bitmap); |
| 301 | 295 |
| 302 // Convert to format suitable for inspection | 296 // Convert to format suitable for inspection |
| 303 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bitmap); | 297 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(*bitmap); |
| 304 SkASSERT(encodedBitmap.get()); | 298 SkASSERT(encodedBitmap.get()); |
| 305 | 299 |
| 306 const uint8_t* start = encodedBitmap->bytes() + ((y * bitmap->width() + x) *
4); | 300 const uint8_t* start = encodedBitmap->bytes() + ((y * bitmap->width() + x) *
4); |
| 307 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); | 301 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); |
| 308 return result; | 302 return result; |
| 309 } | 303 } |
| OLD | NEW |