surface.cc 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 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 "surface.h"

#include <fcntl.h>
#include <fdio/watcher.h>
#include <unistd.h>
#include <zircon/device/vfs.h>

#include "lib/fxl/files/unique_fd.h"

namespace flutter {

16 17
Surface::Surface(std::string debug_label)
    : debug_label_(std::move(debug_label)) {}
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

Surface::~Surface() = default;

// |shell::Surface|
bool Surface::IsValid() {
  return valid_;
}

// |shell::Surface|
std::unique_ptr<shell::SurfaceFrame> Surface::AcquireFrame(
    const SkISize& size) {
  return std::make_unique<shell::SurfaceFrame>(
      nullptr, [](const shell::SurfaceFrame& surface_frame, SkCanvas* canvas) {
        return true;
      });
}

// |shell::Surface|
GrContext* Surface::GetContext() {
  return nullptr;
}

static zx_status_t DriverWatcher(int dirfd,
                                 int event,
                                 const char* fn,
                                 void* cookie) {
  if (event == WATCH_EVENT_ADD_FILE && !strcmp(fn, "000")) {
    return ZX_ERR_STOP;
  }
  return ZX_OK;
}

bool Surface::CanConnectToDisplay() {
51 52
  constexpr char kGpuDriverClass[] = "/dev/class/gpu";
  fxl::UniqueFD fd(open(kGpuDriverClass, O_DIRECTORY | O_RDONLY));
53
  if (fd.get() < 0) {
54
    FXL_DLOG(ERROR) << "Failed to open " << kGpuDriverClass;
55 56 57 58
    return false;
  }

  zx_status_t status = fdio_watch_directory(
59
      fd.get(), DriverWatcher, zx_deadline_after(ZX_SEC(5)), nullptr);
60 61 62 63
  return status == ZX_ERR_STOP;
}

}  // namespace flutter