| Index: ui/ozone/platform/dri/dri_wrapper.cc
|
| diff --git a/ui/ozone/platform/dri/dri_wrapper.cc b/ui/ozone/platform/dri/dri_wrapper.cc
|
| index 908ddf079f86080c74c10d22fe8f617dae861a12..035243c95ef62961eb8ecc24043013393c77a3b0 100644
|
| --- a/ui/ozone/platform/dri/dri_wrapper.cc
|
| +++ b/ui/ozone/platform/dri/dri_wrapper.cc
|
| @@ -5,18 +5,58 @@
|
| #include "ui/ozone/platform/dri/dri_wrapper.h"
|
|
|
| #include <fcntl.h>
|
| +#include <sys/mman.h>
|
| #include <unistd.h>
|
| #include <xf86drm.h>
|
| #include <xf86drmMode.h>
|
|
|
| #include "base/logging.h"
|
| +#include "third_party/skia/include/core/SkImageInfo.h"
|
| +#include "ui/ozone/platform/dri/dri_util.h"
|
|
|
| namespace ui {
|
| +
|
| namespace {
|
| +
|
| uint32_t ToFixedPoint(double v) {
|
| // This returns a number in a 16-bit.16-bit fixed point.
|
| return v * 65536.0;
|
| }
|
| +
|
| +bool DrmCreateDumbBuffer(int fd,
|
| + const SkImageInfo& info,
|
| + uint32_t* handle,
|
| + uint32_t* stride) {
|
| + struct drm_mode_create_dumb request;
|
| + memset(&request, 0, sizeof(request));
|
| + request.width = info.width();
|
| + request.height = info.height();
|
| + request.bpp = info.bytesPerPixel() << 3;
|
| + request.flags = 0;
|
| +
|
| + if (drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &request) < 0) {
|
| + VLOG(2) << "Cannot create dumb buffer (" << errno << ") "
|
| + << strerror(errno);
|
| + return false;
|
| + }
|
| +
|
| + // The driver may choose to align the last row as well. We don't care about
|
| + // the last alignment bits since they aren't used for display purposes, so
|
| + // just check that the expected size is <= to what the driver allocated.
|
| + DCHECK_LE(info.getSafeSize(request.pitch), request.size);
|
| +
|
| + *handle = request.handle;
|
| + *stride = request.pitch;
|
| + return true;
|
| +}
|
| +
|
| +void DrmDestroyDumbBuffer(int fd, uint32_t handle) {
|
| + struct drm_mode_destroy_dumb destroy_request;
|
| + memset(&destroy_request, 0, sizeof(destroy_request));
|
| + destroy_request.handle = handle;
|
| + drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_request);
|
| +}
|
| +
|
| } // namespace
|
|
|
| DriWrapper::DriWrapper(const char* device_path) {
|
| @@ -174,4 +214,31 @@ void DriWrapper::HandleEvent(drmEventContext& event) {
|
| drmHandleEvent(fd_, &event);
|
| }
|
|
|
| +bool DriWrapper::CreateDumbBuffer(const SkImageInfo& info,
|
| + uint32_t* handle,
|
| + uint32_t* stride,
|
| + void** pixels) {
|
| + CHECK(fd_ >= 0);
|
| +
|
| + if (!DrmCreateDumbBuffer(fd_, info, handle, stride))
|
| + return false;
|
| +
|
| + if (!MapDumbBuffer(fd_, *handle, info.getSafeSize(*stride), pixels)) {
|
| + DrmDestroyDumbBuffer(fd_, *handle);
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void DriWrapper::DestroyDumbBuffer(const SkImageInfo& info,
|
| + uint32_t handle,
|
| + uint32_t stride,
|
| + void* pixels) {
|
| + CHECK(fd_ >= 0);
|
| + munmap(pixels, info.getSafeSize(stride));
|
| + DrmDestroyDumbBuffer(fd_, handle);
|
| +}
|
| +
|
| +
|
| } // namespace ui
|
|
|