1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "surface.h"
6
7 #include <fcntl.h>
8 #include <lib/fdio/watcher.h>
9 #include <unistd.h>
10
11 #include "flutter/fml/unique_fd.h"
12
13 namespace flutter_runner {
14
Surface(std::string debug_label)15 Surface::Surface(std::string debug_label)
16 : debug_label_(std::move(debug_label)) {}
17
18 Surface::~Surface() = default;
19
20 // |flutter::Surface|
IsValid()21 bool Surface::IsValid() {
22 return valid_;
23 }
24
25 // |flutter::Surface|
AcquireFrame(const SkISize & size)26 std::unique_ptr<flutter::SurfaceFrame> Surface::AcquireFrame(
27 const SkISize& size) {
28 return std::make_unique<flutter::SurfaceFrame>(
29 nullptr, [](const flutter::SurfaceFrame& surface_frame,
30 SkCanvas* canvas) { return true; });
31 }
32
33 // |flutter::Surface|
GetContext()34 GrContext* Surface::GetContext() {
35 return nullptr;
36 }
37
DriverWatcher(int dirfd,int event,const char * fn,void * cookie)38 static zx_status_t DriverWatcher(int dirfd,
39 int event,
40 const char* fn,
41 void* cookie) {
42 if (event == WATCH_EVENT_ADD_FILE && !strcmp(fn, "000")) {
43 return ZX_ERR_STOP;
44 }
45 return ZX_OK;
46 }
47
CanConnectToDisplay()48 bool Surface::CanConnectToDisplay() {
49 constexpr char kGpuDriverClass[] = "/dev/class/gpu";
50 fml::UniqueFD fd(open(kGpuDriverClass, O_DIRECTORY | O_RDONLY));
51 if (fd.get() < 0) {
52 FML_DLOG(ERROR) << "Failed to open " << kGpuDriverClass;
53 return false;
54 }
55
56 zx_status_t status = fdio_watch_directory(
57 fd.get(), DriverWatcher, zx_deadline_after(ZX_SEC(5)), nullptr);
58 return status == ZX_ERR_STOP;
59 }
60
61 // |flutter::Surface|
GetRootTransformation() const62 SkMatrix Surface::GetRootTransformation() const {
63 // This backend does not support delegating to the underlying platform to
64 // query for root surface transformations. Just return identity.
65 SkMatrix matrix;
66 matrix.reset();
67 return matrix;
68 }
69
70 } // namespace flutter_runner
71