Home | History | Annotate | Download | only in tools
      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 {
     12     SkImageInfo      info;
     13     sk_sp<SkSurface> surface;
     14 
     15     static std::unique_ptr<Dst> Create(Options options) {
     16         SkImageInfo info = SkImageInfo::MakeN32Premul(0,0);
     17         if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
     18         if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
     19 
     20         SWDst dst;
     21         dst.info = info;
     22         return move_unique(dst);
     23     }
     24 
     25     bool draw(Src* src) override {
     26         auto size = src->size();
     27         surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
     28         return src->draw(surface->getCanvas());
     29     }
     30 
     31     sk_sp<SkImage> image() override {
     32         return surface->makeImageSnapshot();
     33     }
     34 };
     35 static Register sw{"sw", SWDst::Create};
     36 
     37 static Register _565{"565", [](Options options) {
     38     options["ct"] = "565";
     39     return SWDst::Create(options);
     40 }};
     41