Commit 61a48bb6 authored by Miguel Casas-Sanchez's avatar Miguel Casas-Sanchez Committed by Commit Bot

ui/ozone/drm: introduce ScopedGbmDevice

A gbm_device must be closed using gbm_destroy_device(); this CL
introduces ScopedGbmDevice with a custom deleter that does just
that, and uses it in the place where it's needed now -- I'll also
use it in crrev.com/c/1635929 imminently.

Bug: 970923
Change-Id: I954c1f4bfdf0d6ca8ef91f336eb21fc2d255ee6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1643684
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666346}
parent cccb6c78
...@@ -25,6 +25,8 @@ source_set("gbm") { ...@@ -25,6 +25,8 @@ source_set("gbm") {
"gbm_buffer.h", "gbm_buffer.h",
"gbm_device.h", "gbm_device.h",
"gbm_wrapper.cc", "gbm_wrapper.cc",
"scoped_gbm_device.cc",
"scoped_gbm_device.h",
] ]
deps = [ deps = [
......
// Copyright 2019 The Chromium 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 "ui/ozone/common/linux/scoped_gbm_device.h"
namespace ui {
void GbmDeviceDeleter::operator()(gbm_device* device) {
if (device)
gbm_device_destroy(device);
}
} // namespace ui
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_COMMON_LINUX_SCOPED_GBM_DEVICE_H_
#define UI_OZONE_COMMON_LINUX_SCOPED_GBM_DEVICE_H_
#include <gbm.h>
#include <memory>
namespace ui {
struct GbmDeviceDeleter {
void operator()(gbm_device* device);
};
using ScopedGbmDevice = std::unique_ptr<gbm_device, GbmDeviceDeleter>;
} // namespace ui
#endif // UI_OZONE_COMMON_LINUX_SCOPED_GBM_DEVICE_H_
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ui/ozone/common/egl_util.h" #include "ui/ozone/common/egl_util.h"
#include "ui/ozone/common/gl_ozone_egl.h" #include "ui/ozone/common/gl_ozone_egl.h"
#include "ui/ozone/common/linux/drm_util_linux.h" #include "ui/ozone/common/linux/drm_util_linux.h"
#include "ui/ozone/common/linux/scoped_gbm_device.h"
#include "ui/ozone/platform/drm/common/drm_util.h" #include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h" #include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h"
#include "ui/ozone/platform/drm/gpu/drm_window_proxy.h" #include "ui/ozone/platform/drm/gpu/drm_window_proxy.h"
...@@ -108,7 +109,7 @@ std::vector<gfx::BufferFormat> EnumerateSupportedBufferFormatsForTexturing() { ...@@ -108,7 +109,7 @@ std::vector<gfx::BufferFormat> EnumerateSupportedBufferFormatsForTexturing() {
if (!dev_path_file.IsValid()) if (!dev_path_file.IsValid())
break; break;
gbm_device* device = gbm_create_device(dev_path_file.GetPlatformFile()); ScopedGbmDevice device(gbm_create_device(dev_path_file.GetPlatformFile()));
if (!device) { if (!device) {
LOG(ERROR) << "Couldn't create Gbm Device at " << dev_path.MaybeAsASCII(); LOG(ERROR) << "Couldn't create Gbm Device at " << dev_path.MaybeAsASCII();
return supported_buffer_formats; return supported_buffer_formats;
...@@ -119,12 +120,11 @@ std::vector<gfx::BufferFormat> EnumerateSupportedBufferFormatsForTexturing() { ...@@ -119,12 +120,11 @@ std::vector<gfx::BufferFormat> EnumerateSupportedBufferFormatsForTexturing() {
if (base::ContainsValue(supported_buffer_formats, buffer_format)) if (base::ContainsValue(supported_buffer_formats, buffer_format))
continue; continue;
if (gbm_device_is_format_supported( if (gbm_device_is_format_supported(
device, GetFourCCFormatFromBufferFormat(buffer_format), device.get(), GetFourCCFormatFromBufferFormat(buffer_format),
GBM_BO_USE_TEXTURING)) { GBM_BO_USE_TEXTURING)) {
supported_buffer_formats.push_back(buffer_format); supported_buffer_formats.push_back(buffer_format);
} }
} }
gbm_device_destroy(device);
} }
return supported_buffer_formats; return supported_buffer_formats;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment