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 | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 17 | if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); } |
| 18 | if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); } |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 19 | |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 20 | SWDst dst; |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 21 | dst.info = info; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 22 | return move_unique(dst); |
| 23 | } |
| 24 | |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 25 | Status draw(Src* src) override { |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 26 | auto size = src->size(); |
| 27 | surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height())); |
| 28 | return src->draw(surface->getCanvas()); |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 29 | } |
| 30 | |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 31 | sk_sp<SkImage> image() override { |
| 32 | return surface->makeImageSnapshot(); |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 33 | } |
| 34 | }; |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 35 | static Register sw{"sw", "draw with the software backend", SWDst::Create}; |
Mike Klein | 88f9c1e | 2017-03-27 12:43:44 -0400 | [diff] [blame] | 36 | |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 37 | static Register _565{"565", "alias for sw:ct=565", [](Options options) { |
Mike Klein | 88f9c1e | 2017-03-27 12:43:44 -0400 | [diff] [blame] | 38 | options["ct"] = "565"; |
| 39 | return SWDst::Create(options); |
| 40 | }}; |