skia2/tools/ok_dsts.cpp
Mike Klein 0222e709a3 ok: refactor Src/Dst interactions
This makes everything a lot more like DM, for the same reason:
it's the best way to make Vias work.

Instead of exposing a canvas, Dsts take a Src to draw.  Vias still are
Dsts that wrap Dsts.  They do their internal work in draw() then pass a
proxy Src encapsulating that work to the next Dst's draw().

A little refactoring in ok.cpp allows arbitrary chains of Vias.

I removed the guarantee that Src methods are called in strict order.
It's easy enough to make each Src initialize itself as needed.

I moved the .png encoding back to ok.cpp.  It seemed weird for Dsts to
have to think about files and paths.  One day Dst will want a data()
method for non-image output (.pdf, .skp), and then we'll want ok.cpp to
be the one to coordinate what to write where.

Change-Id: Id4a3674b2d05aef2b5f10e0077df0a8407c07b61
Reviewed-on: https://skia-review.googlesource.com/10175
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
2017-03-25 20:43:01 +00:00

36 lines
985 B
C++

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "ok.h"
#include "SkSurface.h"
struct SWDst : Dst {
SkImageInfo info;
sk_sp<SkSurface> surface;
static std::unique_ptr<Dst> Create(Options options) {
SkImageInfo info = SkImageInfo::MakeN32Premul(0,0);
if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
SWDst dst;
dst.info = info;
return move_unique(dst);
}
bool draw(Src* src) override {
auto size = src->size();
surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
return src->draw(surface->getCanvas());
}
sk_sp<SkImage> image() override {
return surface->makeImageSnapshot();
}
};
static Register sw{"sw", SWDst::Create};