summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-11-02 23:17:20 +0100
committerandroid-build-merger <android-build-merger@google.com>2018-11-02 23:17:20 +0100
commitf0cf95208291fb5253ea77d916276f54257c1125 (patch)
treec19d37fa8afc0b6b1ce5e3810b03f5583b0bcb22
parentMerge "minui: Add GRSurface::Clone()." (diff)
parentMerge "minui: Use android::base::unique_fd in MinuiBackendFbdev." (diff)
downloadandroid_bootable_recovery-f0cf95208291fb5253ea77d916276f54257c1125.tar
android_bootable_recovery-f0cf95208291fb5253ea77d916276f54257c1125.tar.gz
android_bootable_recovery-f0cf95208291fb5253ea77d916276f54257c1125.tar.bz2
android_bootable_recovery-f0cf95208291fb5253ea77d916276f54257c1125.tar.lz
android_bootable_recovery-f0cf95208291fb5253ea77d916276f54257c1125.tar.xz
android_bootable_recovery-f0cf95208291fb5253ea77d916276f54257c1125.tar.zst
android_bootable_recovery-f0cf95208291fb5253ea77d916276f54257c1125.zip
-rw-r--r--minui/graphics_fbdev.cpp17
-rw-r--r--minui/graphics_fbdev.h6
2 files changed, 9 insertions, 14 deletions
diff --git a/minui/graphics_fbdev.cpp b/minui/graphics_fbdev.cpp
index 4da5613af..93e4420d3 100644
--- a/minui/graphics_fbdev.cpp
+++ b/minui/graphics_fbdev.cpp
@@ -28,6 +28,8 @@
#include <memory>
+#include <android-base/unique_fd.h>
+
#include "minui/minui.h"
std::unique_ptr<GRSurfaceFbdev> GRSurfaceFbdev::Create(int width, int height, int row_bytes,
@@ -54,7 +56,7 @@ void MinuiBackendFbdev::SetDisplayedFramebuffer(size_t n) {
}
GRSurface* MinuiBackendFbdev::Init() {
- int fd = open("/dev/graphics/fb0", O_RDWR);
+ android::base::unique_fd fd(open("/dev/graphics/fb0", O_RDWR));
if (fd == -1) {
perror("cannot open fb0");
return nullptr;
@@ -63,13 +65,11 @@ GRSurface* MinuiBackendFbdev::Init() {
fb_fix_screeninfo fi;
if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) {
perror("failed to get fb0 info");
- close(fd);
return nullptr;
}
if (ioctl(fd, FBIOGET_VSCREENINFO, &vi) < 0) {
perror("failed to get fb0 info");
- close(fd);
return nullptr;
}
@@ -96,7 +96,6 @@ GRSurface* MinuiBackendFbdev::Init() {
void* bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (bits == MAP_FAILED) {
perror("failed to mmap framebuffer");
- close(fd);
return nullptr;
}
@@ -128,10 +127,10 @@ GRSurface* MinuiBackendFbdev::Init() {
gr_draw = gr_framebuffer[1].get();
memset(gr_draw->buffer_, 0, gr_draw->height * gr_draw->row_bytes);
- fb_fd = fd;
+ fb_fd = std::move(fd);
SetDisplayedFramebuffer(0);
- printf("framebuffer: %d (%d x %d)\n", fb_fd, gr_draw->width, gr_draw->height);
+ printf("framebuffer: %d (%d x %d)\n", fb_fd.get(), gr_draw->width, gr_draw->height);
Blank(true);
Blank(false);
@@ -151,9 +150,3 @@ GRSurface* MinuiBackendFbdev::Flip() {
}
return gr_draw;
}
-
-MinuiBackendFbdev::~MinuiBackendFbdev() {
- if (fb_fd != -1) {
- close(fb_fd);
- }
-}
diff --git a/minui/graphics_fbdev.h b/minui/graphics_fbdev.h
index 934e584d7..016ab88bc 100644
--- a/minui/graphics_fbdev.h
+++ b/minui/graphics_fbdev.h
@@ -22,6 +22,8 @@
#include <memory>
#include <vector>
+#include <android-base/unique_fd.h>
+
#include "graphics.h"
#include "minui/minui.h"
@@ -48,7 +50,7 @@ class GRSurfaceFbdev : public GRSurface {
class MinuiBackendFbdev : public MinuiBackend {
public:
MinuiBackendFbdev() = default;
- ~MinuiBackendFbdev() override;
+ ~MinuiBackendFbdev() override = default;
GRSurface* Init() override;
GRSurface* Flip() override;
@@ -64,5 +66,5 @@ class MinuiBackendFbdev : public MinuiBackend {
std::vector<uint8_t> memory_buffer;
size_t displayed_buffer{ 0 };
fb_var_screeninfo vi;
- int fb_fd{ -1 };
+ android::base::unique_fd fb_fd;
};