Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "ok.h" |
| 9 | #include "SkSurface.h" |
| 10 | |
| 11 | struct SWDst : Dst { |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 12 | SkImageInfo info; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 13 | sk_sp<SkSurface> surface; |
| 14 | |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 15 | static std::unique_ptr<Dst> Create(Options options) { |
| 16 | SkImageInfo info = SkImageInfo::MakeN32Premul(0,0); |
Mike Klein | 9a3478b | 2017-09-29 15:43:28 -0400 | [diff] [blame] | 17 | if (options("ct") == "a8") { info = info.makeColorType(kAlpha_8_SkColorType); } |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 18 | if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); } |
| 19 | if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); } |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 20 | |
Mike Klein | 16a6144 | 2017-05-02 21:04:34 -0400 | [diff] [blame] | 21 | if (options("cs") == "srgb") { |
| 22 | auto cs = info.colorType() == kRGBA_F16_SkColorType ? SkColorSpace::MakeSRGBLinear() |
| 23 | : SkColorSpace::MakeSRGB(); |
| 24 | info = info.makeColorSpace(std::move(cs)); |
| 25 | } |
| 26 | |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 27 | SWDst dst; |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 28 | dst.info = info; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 29 | return move_unique(dst); |
| 30 | } |
| 31 | |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 32 | Status draw(Src* src) override { |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 33 | auto size = src->size(); |
| 34 | surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height())); |
| 35 | return src->draw(surface->getCanvas()); |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 36 | } |
| 37 | |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 38 | sk_sp<SkImage> image() override { |
| 39 | return surface->makeImageSnapshot(); |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 40 | } |
| 41 | }; |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 42 | static Register sw{"sw", "draw with the software backend", SWDst::Create}; |
Mike Klein | a611be8 | 2017-06-13 07:56:40 -0400 | [diff] [blame] | 43 | static Register _8888{"8888", "alias for sw", SWDst::Create}; |
Mike Klein | 88f9c1e | 2017-03-27 12:43:44 -0400 | [diff] [blame] | 44 | |
Mike Klein | 9a3478b | 2017-09-29 15:43:28 -0400 | [diff] [blame] | 45 | static Register a8{"a8", "alias for sw:ct=a8", [](Options options) { |
| 46 | options["ct"] = "a8"; |
| 47 | return SWDst::Create(options); |
| 48 | }}; |
| 49 | |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 50 | static Register _565{"565", "alias for sw:ct=565", [](Options options) { |
Mike Klein | 88f9c1e | 2017-03-27 12:43:44 -0400 | [diff] [blame] | 51 | options["ct"] = "565"; |
| 52 | return SWDst::Create(options); |
| 53 | }}; |
Mike Klein | 16a6144 | 2017-05-02 21:04:34 -0400 | [diff] [blame] | 54 | |
| 55 | static Register srgb{"srgb", "alias for sw:cs=srgb", [](Options options) { |
| 56 | options["cs"] = "srgb"; |
| 57 | return SWDst::Create(options); |
| 58 | }}; |
| 59 | |
| 60 | static Register f16{"f16", "alias for sw:ct=f16,cs=srgb", [](Options options) { |
| 61 | options["ct"] = "f16"; |
| 62 | options["cs"] = "srgb"; |
| 63 | return SWDst::Create(options); |
| 64 | }}; |
Mike Klein | a611be8 | 2017-06-13 07:56:40 -0400 | [diff] [blame] | 65 | |
| 66 | extern bool gSkForceRasterPipelineBlitter; |
| 67 | static Register rp{"rp", "draw forcing SkRasterPipelineBlitter", [](Options options) { |
| 68 | gSkForceRasterPipelineBlitter = true; |
| 69 | return SWDst::Create(options); |
| 70 | }}; |