Commit fa1becb2 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add layer submit operation

parent bd71f98c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -29,12 +29,12 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#include "layer.h"
#include <utils/stringutil.h>
#include "png.h"

namespace plotfx {

//Layer::Layer() : width(0), height(0) {}
ReturnCode layer_submit(Layer* layer) {
  return layer->apply(layer_ops::SubmitOp{});
}

} // namespace plotfx
+6 −4
Original line number Diff line number Diff line
@@ -57,9 +57,6 @@ namespace plotfx {
 * of interacting directly with the Layer. Nevertheless, all supported drawing
 * operation are available through the `apply` method of the layer. Please refer
 * to `layer_op.h` for more information on the low-level operations API.
 *
 * Once you are done with all drawing calls, you can retrieve the result image by
 * calling the `data` function.
 */
struct Layer {
  const double width;
@@ -67,10 +64,15 @@ struct Layer {
  const MeasureTable measures;
  const std::shared_ptr<text::TextShaper> text_shaper;
  const std::function<Status (const layer_ops::Op&)> apply;
  const std::function<std::string ()> data;
};

using LayerRef = std::unique_ptr<Layer>;

/**
 * Submit the layer to the rendering backend. Depending on the rendering backend,
 * this will return a value to the user or swap the current screen buffer
 */
ReturnCode layer_submit(Layer* layer);

} // namespace plotfx
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@
namespace plotfx {
namespace layer_ops {

struct SubmitOp {};

struct BrushStrokeOp {
  Rectangle clip;
  Path path;
@@ -62,6 +64,7 @@ struct TextSpanOp {
};

using Op = std::variant<
    SubmitOp,
    BrushFillOp,
    BrushStrokeOp,
    TextSpanOp>;
+5 −3
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ ReturnCode layer_bind_png(
    double height,
    const MeasureTable& measures,
    const Colour& background_colour,
    std::function<Status (const std::string&)> submit,
    LayerRef* layer) {
  auto text_shaper = std::make_shared<text::TextShaper>();
  auto raster = std::make_shared<Rasterizer>(width, height, measures, text_shaper);
@@ -47,8 +48,8 @@ ReturnCode layer_bind_png(
    .height = height,
    .measures = measures,
    .text_shaper = text_shaper,
    .apply = [raster] (auto op) {
      return std::visit([raster] (auto&& op) {
    .apply = [submit, raster] (auto op) {
      return std::visit([submit, raster] (auto&& op) {
        using T = std::decay_t<decltype(op)>;
        if constexpr (std::is_same_v<T, layer_ops::BrushStrokeOp>)
          return raster->strokePath(op);
@@ -56,11 +57,12 @@ ReturnCode layer_bind_png(
          return raster->fillPath(op);
        if constexpr (std::is_same_v<T, layer_ops::TextSpanOp>)
          return raster->drawText(op);
        if constexpr (std::is_same_v<T, layer_ops::SubmitOp>)
          return submit(raster->to_png());
        else
          return ERROR_NOT_IMPLEMENTED;
      }, op);
    },
    .data = [raster] { return raster->to_png(); },
  });

  return OK;
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ ReturnCode layer_bind_png(
    double height,
    const MeasureTable& measures,
    const Colour& background_colour,
    std::function<Status (const std::string&)> submit,
    LayerRef* layer);

} // namespace plotfx
Loading