Commit a6767cf7 authored by Drew Davenport's avatar Drew Davenport Committed by Commit Bot

Revert "Revert "ozone/drm: Use minigbm mmap for modeset buffers""

This reverts commit 57af9203.

After bisecting the changes between the failing and passing pfq runs,
the CL responsible for fixing desktopui_MashLogin was CL:1215947 and
not the revert of "Use minigbm mmap for modeset buffers"

BUG=b:78892556

Change-Id: I07908ca894d9132073c1846277d3e32fa1e7d4a8
Reviewed-on: https://chromium-review.googlesource.com/1235202Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Commit-Queue: Drew Davenport <ddavenport@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592882}
parent 7582b2aa
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
#include <inttypes.h> #include <inttypes.h>
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_pixmap_handle.h" #include "ui/gfx/native_pixmap_handle.h"
class SkSurface;
namespace ui { namespace ui {
class GbmBuffer { class GbmBuffer {
...@@ -34,6 +37,7 @@ class GbmBuffer { ...@@ -34,6 +37,7 @@ class GbmBuffer {
virtual size_t GetPlaneSize(size_t plane) const = 0; virtual size_t GetPlaneSize(size_t plane) const = 0;
virtual uint32_t GetHandle() const = 0; virtual uint32_t GetHandle() const = 0;
virtual gfx::NativePixmapHandle ExportHandle() const = 0; virtual gfx::NativePixmapHandle ExportHandle() const = 0;
virtual sk_sp<SkSurface> GetSurface() = 0;
}; };
} // namespace ui } // namespace ui
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <gbm.h> #include <gbm.h>
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/buffer_format_util.h" #include "ui/gfx/buffer_format_util.h"
#include "ui/ozone/common/linux/drm_util_linux.h" #include "ui/ozone/common/linux/drm_util_linux.h"
#include "ui/ozone/common/linux/gbm_buffer.h" #include "ui/ozone/common/linux/gbm_buffer.h"
...@@ -31,7 +32,10 @@ class Buffer final : public ui::GbmBuffer { ...@@ -31,7 +32,10 @@ class Buffer final : public ui::GbmBuffer {
size_(size), size_(size),
planes_(std::move(planes)) {} planes_(std::move(planes)) {}
~Buffer() override { gbm_bo_destroy(bo_); } ~Buffer() override {
DCHECK(!mmap_data_);
gbm_bo_destroy(bo_);
}
uint32_t GetFormat() const override { return format_; } uint32_t GetFormat() const override { return format_; }
uint64_t GetFormatModifier() const override { return format_modifier_; } uint64_t GetFormatModifier() const override { return format_modifier_; }
...@@ -97,8 +101,24 @@ class Buffer final : public ui::GbmBuffer { ...@@ -97,8 +101,24 @@ class Buffer final : public ui::GbmBuffer {
return handle; return handle;
} }
sk_sp<SkSurface> GetSurface() override {
DCHECK(!mmap_data_);
uint32_t stride;
void* addr;
addr = gbm_bo_map(bo_, 0, 0, gbm_bo_get_width(bo_), gbm_bo_get_height(bo_),
GBM_BO_TRANSFER_READ_WRITE, &stride, &mmap_data_, 0);
if (!addr)
return nullptr;
SkImageInfo info =
SkImageInfo::MakeN32Premul(size_.width(), size_.height());
return SkSurface::MakeRasterDirectReleaseProc(info, addr, stride,
&Buffer::UnmapGbmBo, this);
}
private: private:
gbm_bo* bo_ = nullptr; gbm_bo* bo_ = nullptr;
void* mmap_data_ = nullptr;
uint32_t format_ = 0; uint32_t format_ = 0;
uint64_t format_modifier_ = 0; uint64_t format_modifier_ = 0;
...@@ -110,6 +130,12 @@ class Buffer final : public ui::GbmBuffer { ...@@ -110,6 +130,12 @@ class Buffer final : public ui::GbmBuffer {
std::vector<gfx::NativePixmapPlane> planes_; std::vector<gfx::NativePixmapPlane> planes_;
static void UnmapGbmBo(void* pixels, void* context) {
Buffer* buffer = static_cast<Buffer*>(context);
gbm_bo_unmap(buffer->bo_, buffer->mmap_data_);
buffer->mmap_data_ = nullptr;
}
DISALLOW_COPY_AND_ASSIGN(Buffer); DISALLOW_COPY_AND_ASSIGN(Buffer);
}; };
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_math.h" #include "base/numerics/safe_math.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "ui/ozone/common/linux/drm_util_linux.h" #include "ui/ozone/common/linux/drm_util_linux.h"
#include "ui/ozone/common/linux/gbm_buffer.h" #include "ui/ozone/common/linux/gbm_buffer.h"
...@@ -69,6 +70,8 @@ class MockGbmBuffer final : public ui::GbmBuffer { ...@@ -69,6 +70,8 @@ class MockGbmBuffer final : public ui::GbmBuffer {
return gfx::NativePixmapHandle(); return gfx::NativePixmapHandle();
} }
sk_sp<SkSurface> GetSurface() override { return nullptr; }
private: private:
uint32_t format_ = 0; uint32_t format_ = 0;
uint64_t format_modifier_ = 0; uint64_t format_modifier_ = 0;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/gpu_fence.h" #include "ui/gfx/gpu_fence.h"
#include "ui/gfx/skia_util.h"
#include "ui/ozone/common/linux/gbm_buffer.h" #include "ui/ozone/common/linux/gbm_buffer.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/crtc_controller.h" #include "ui/ozone/platform/drm/gpu/crtc_controller.h"
...@@ -32,13 +33,7 @@ namespace { ...@@ -32,13 +33,7 @@ namespace {
// to the new modeset buffer |buffer|. // to the new modeset buffer |buffer|.
void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm, void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm,
HardwareDisplayController* controller, HardwareDisplayController* controller,
DrmFramebuffer* buffer) { GbmBuffer* buffer) {
DrmConsoleBuffer modeset_buffer(drm, buffer->opaque_framebuffer_id());
if (!modeset_buffer.Initialize()) {
VLOG(2) << "Failed to grab framebuffer " << buffer->opaque_framebuffer_id();
return;
}
DCHECK(!controller->crtc_controllers().empty()); DCHECK(!controller->crtc_controllers().empty());
CrtcController* first_crtc = controller->crtc_controllers()[0].get(); CrtcController* first_crtc = controller->crtc_controllers()[0].get();
ScopedDrmCrtcPtr saved_crtc(drm->GetCrtc(first_crtc->crtc())); ScopedDrmCrtcPtr saved_crtc(drm->GetCrtc(first_crtc->crtc()));
...@@ -47,7 +42,7 @@ void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm, ...@@ -47,7 +42,7 @@ void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm,
return; return;
} }
uint32_t fourcc_format = buffer->framebuffer_pixel_format(); uint32_t fourcc_format = buffer->GetFormat();
const auto& modifiers = controller->GetFormatModifiers(fourcc_format); const auto& modifiers = controller->GetFormatModifiers(fourcc_format);
for (const uint64_t modifier : modifiers) { for (const uint64_t modifier : modifiers) {
// A value of 0 means DRM_FORMAT_MOD_NONE. If the CRTC has any other // A value of 0 means DRM_FORMAT_MOD_NONE. If the CRTC has any other
...@@ -71,15 +66,20 @@ void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm, ...@@ -71,15 +66,20 @@ void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm,
// Don't copy anything if the sizes mismatch. This can happen when the user // Don't copy anything if the sizes mismatch. This can happen when the user
// changes modes. // changes modes.
if (saved_buffer.canvas()->getBaseLayerSize() != if (saved_buffer.canvas()->getBaseLayerSize() !=
modeset_buffer.canvas()->getBaseLayerSize()) { SizeToSkISize(buffer->GetSize())) {
VLOG(2) << "Previous buffer has a different size than modeset buffer"; VLOG(2) << "Previous buffer has a different size than modeset buffer";
return; return;
} }
sk_sp<SkSurface> surface = buffer->GetSurface();
if (!surface) {
VLOG(2) << "Can't get a SkSurface from the modeset gbm buffer.";
return;
}
SkPaint paint; SkPaint paint;
// Copy the source buffer. Do not perform any blending. // Copy the source buffer. Do not perform any blending.
paint.setBlendMode(SkBlendMode::kSrc); paint.setBlendMode(SkBlendMode::kSrc);
modeset_buffer.canvas()->drawImage(saved_buffer.image(), 0, 0, &paint); surface->getCanvas()->drawImage(saved_buffer.image(), 0, 0, &paint);
} }
CrtcController* GetCrtcController(HardwareDisplayController* controller, CrtcController* GetCrtcController(HardwareDisplayController* controller,
...@@ -400,7 +400,7 @@ DrmOverlayPlane ScreenManager::GetModesetBuffer( ...@@ -400,7 +400,7 @@ DrmOverlayPlane ScreenManager::GetModesetBuffer(
LOG(ERROR) << "Failed to add framebuffer for scanout buffer"; LOG(ERROR) << "Failed to add framebuffer for scanout buffer";
return DrmOverlayPlane::Error(); return DrmOverlayPlane::Error();
} }
FillModesetBuffer(drm, controller, framebuffer.get()); FillModesetBuffer(drm, controller, buffer.get());
return DrmOverlayPlane(framebuffer, nullptr); return DrmOverlayPlane(framebuffer, nullptr);
} }
......
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