[scenic] Delete screencap tool

Bug: 100116

Change-Id: I0f1656d609143d502a56e0e0be518959821be79f
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/693602
Reviewed-by: Adam Barth <abarth@google.com>
Commit-Queue: David Worsham <dworsham@google.com>
diff --git a/src/ui/tools/BUILD.gn b/src/ui/tools/BUILD.gn
index d97bf27..c63cb8f 100644
--- a/src/ui/tools/BUILD.gn
+++ b/src/ui/tools/BUILD.gn
@@ -9,7 +9,6 @@
     ":input",
     ":present_view",
     ":print_input",
-    ":screencap",
   ]
 }
 
@@ -18,7 +17,6 @@
     ":input",
     ":present_view",
     ":print_input",
-    ":screencap",
     "paper_shader_compiler",
     "print-input-report",
     "tiles",
@@ -42,10 +40,7 @@
 # follow the pattern:
 # name/meta/name.cmx contains the component manifest
 # name is the name of a subdirectory that builds the output binary `name`
-component_shell_tools = [
-  "present_view",
-  "screencap",
-]
+component_shell_tools = [ "present_view" ]
 foreach(tool, component_shell_tools) {
   fuchsia_shell_package(tool) {
     manifest = "$tool/meta/$tool.cmx"
diff --git a/src/ui/tools/screencap/BUILD.gn b/src/ui/tools/screencap/BUILD.gn
deleted file mode 100644
index 4ef86cf..0000000
--- a/src/ui/tools/screencap/BUILD.gn
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright 2018 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-executable("screencap") {
-  output_name = "screencap"
-
-  sources = [ "main.cc" ]
-
-  deps = [
-    "//sdk/fidl/fuchsia.ui.scenic",
-    "//sdk/lib/sys/cpp",
-    "//src/lib/fsl",
-    "//src/lib/fxl",
-    "//zircon/system/ulib/async-loop:async-loop-cpp",
-    "//zircon/system/ulib/async-loop:async-loop-default",
-    "//zircon/system/ulib/trace-provider",
-  ]
-}
diff --git a/src/ui/tools/screencap/README.md b/src/ui/tools/screencap/README.md
deleted file mode 100644
index 844365c..0000000
--- a/src/ui/tools/screencap/README.md
+++ /dev/null
@@ -1,12 +0,0 @@
-# Scenic Screenshot Tool
-
-This directory contains screencap, a simple tool for capturing a screenshot
-of the composition being rendered.
-
-## USAGE
-
-    screencap <file path>
-
-### Examples
-
-    screencap /tmp/screencap.ppm
diff --git a/src/ui/tools/screencap/main.cc b/src/ui/tools/screencap/main.cc
deleted file mode 100644
index 06f3f75..0000000
--- a/src/ui/tools/screencap/main.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright 2018 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <fuchsia/ui/scenic/cpp/fidl.h>
-#include <lib/async-loop/cpp/loop.h>
-#include <lib/async-loop/default.h>
-#include <lib/sys/cpp/component_context.h>
-#include <lib/syslog/cpp/macros.h>
-#include <lib/trace-provider/provider.h>
-
-#include <cstdlib>
-#include <iostream>
-#include <memory>
-
-#include "src/lib/fsl/vmo/vector.h"
-#include "src/lib/fxl/command_line.h"
-#include "src/lib/fxl/log_settings_command_line.h"
-
-class ScreenshotTaker {
- public:
-  explicit ScreenshotTaker(async::Loop* loop) : loop_(loop) {
-    // Connect to the Scenic service.
-    auto context = sys::ComponentContext::CreateAndServeOutgoingDirectory();
-    scenic_ = context->svc()->Connect<fuchsia::ui::scenic::Scenic>();
-    scenic_.set_error_handler([this](zx_status_t status) {
-      FX_LOGS(ERROR) << "Lost connection to Scenic service.";
-      encountered_error_ = true;
-      loop_->Quit();
-    });
-  }
-
-  bool encountered_error() const { return encountered_error_; }
-
-  void TakeScreenshot() {
-    FX_LOGS(INFO) << "start TakeScreenshot";
-    // If we wait for a call back from GetDisplayInfo, we are guaranteed that
-    // the GFX system is initialized, which is a prerequisite for taking a
-    // screenshot. TODO(fxbug.dev/23901): Remove call to GetDisplayInfo once bug done.
-    scenic_->GetDisplayInfo(
-        [this](fuchsia::ui::gfx::DisplayInfo /*unused*/) { TakeScreenshotInternal(); });
-  }
-
- private:
-  void TakeScreenshotInternal() {
-    FX_LOGS(INFO) << "start TakeScreenshotInternal";
-    scenic_->TakeScreenshot([this](fuchsia::ui::scenic::ScreenshotData screenshot, bool status) {
-      FX_LOGS(INFO) << "start pixel capture";
-      std::vector<uint8_t> imgdata;
-      if (!status || !fsl::VectorFromVmo(screenshot.data, &imgdata)) {
-        FX_LOGS(ERROR) << "TakeScreenshot failed";
-        encountered_error_ = true;
-        loop_->Quit();
-        return;
-      }
-
-      std::cout << "P6\n";
-      std::cout << screenshot.info.width << "\n";
-      std::cout << screenshot.info.height << "\n";
-      std::cout << 255 << "\n";
-
-      FX_LOGS(INFO) << "capturing pixels";
-      const uint8_t* pchannel = &imgdata[0];
-      for (uint32_t pixel = 0; pixel < screenshot.info.width * screenshot.info.height; pixel++) {
-        uint8_t rgb[] = {pchannel[2], pchannel[1], pchannel[0]};
-        std::cout.write(reinterpret_cast<const char*>(rgb), 3);
-        pchannel += 4;
-      }
-      loop_->Quit();
-    });
-  }
-  async::Loop* loop_;
-  bool encountered_error_ = false;
-  fuchsia::ui::scenic::ScenicPtr scenic_;
-};
-
-int main(int argc, const char** argv) {
-  FX_LOGS(INFO) << "starting screen capture";
-  auto command_line = fxl::CommandLineFromArgcArgv(argc, argv);
-  if (!fxl::SetLogSettingsFromCommandLine(command_line))
-    return 1;
-
-  if (!command_line.positional_args().empty()) {
-    FX_LOGS(ERROR) << "Usage: screencap\n"
-                   << "Takes a screenshot in PPM format and writes it "
-                   << "to stdout.\n"
-                   << "To write to a file, redirect stdout, e.g.: "
-                   << "screencap > \"${DST}\"";
-    return 1;
-  }
-
-  async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread);
-  trace::TraceProviderWithFdio trace_provider(loop.dispatcher());
-
-  ScreenshotTaker taker(&loop);
-  taker.TakeScreenshot();
-  loop.Run();
-
-  return taker.encountered_error() ? EXIT_FAILURE : EXIT_SUCCESS;
-}
diff --git a/src/ui/tools/screencap/meta/screencap.cmx b/src/ui/tools/screencap/meta/screencap.cmx
deleted file mode 100644
index 7a1f474..0000000
--- a/src/ui/tools/screencap/meta/screencap.cmx
+++ /dev/null
@@ -1,14 +0,0 @@
-{
-    "include": [
-        "syslog/client.shard.cmx"
-    ],
-    "program": {
-        "binary": "bin/screencap"
-    },
-    "sandbox": {
-        "services": [
-            "fuchsia.tracing.provider.Registry",
-            "fuchsia.ui.scenic.Scenic"
-        ]
-    }
-}
diff --git a/tools/devshell/contrib/screenshot b/tools/devshell/contrib/screenshot
deleted file mode 100755
index a287062..0000000
--- a/tools/devshell/contrib/screenshot
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/bin/bash
-# Copyright 2020 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-#### CATEGORY=Device management
-### takes a screenshot and copies it to the host
-
-## usage: fx screenshot [--landscape] [--png] [--trim] [-o <screencap_file>]
-##
-## This command invokes Fuchsia's screencap tool to create a screenshot.
-## The result is written to screencap.ppm or screencap.png. To write to
-## another filename, use the -o parameter.
-## The --trim, --landscape and --png commands require ImageMagick to be
-## installed.  Unrecognized parameters will be passed to ssh.
-##
-## -o FILENAME     Write to the given filename instead of screencap.ppm
-## --png           Create a .png file instead of a .ppm file
-## --trim          Remove black borders
-## --landscape     Rotate image ninety degrees
-##
-## Example usage:
-##   fx screenshot --trim --png --landscape
-
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $?
-fx-config-read
-
-OUT=screencap.ppm
-png_command=cat
-enable_trim=0
-enable_landscape=0
-while [[ $# -ne 0 ]]; do
-  case $1 in
-  -h|--help)
-    fx-command-help
-    exit 0
-    ;;
-  -o|--out)
-    shift
-    OUT=$1
-    ;;
-  --png)
-    OUT=${OUT%.*}.png
-    png_command=pnmtopng
-    ;;
-  --landscape)
-    enable_landscape=1
-    ;;
-  --trim)
-    enable_trim=1
-    ;;
-  *)
-    break
-    ;;
-  esac
-  shift
-done
-
-set -o pipefail
-
-TMP_FILE="$(mktemp "/tmp/fx_screenshot_XXXXX")"
-fx-command-run shell "$@" screencap | $png_command > "$TMP_FILE"
-if [[ $? -ne 0 ]]; then
-  rm -f "$TMP_FILE"
-  fx-error "Screenshot failed. Scenic is not running or Scenic failed to take screenshot."
-  exit 1
-fi
-
-mog_opts=
-if [[ $enable_trim -ne 0 ]]; then
-  mog_opts="$mog_opts -trim +repage"
-fi
-if [[ $enable_landscape -ne 0 ]]; then
-  mog_opts="$mog_opts -rotate 90"
-fi
-if [[ ! -z $mog_opts ]]; then
-  # Also add a black border so it's easier to see the image when
-  # pasted into the bug database.
-  mogrify -bordercolor black -border 3 $mog_opts “$TMP_FILE”
-fi
-
-mv -f "$TMP_FILE" "$OUT"