1 // Copyright 2014 The Chromium 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.
5 #include "ui/ozone/platform/drm/gpu/drm_console_buffer.h"
8 #include <xf86drmMode.h>
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "ui/ozone/platform/drm/common/scoped_drm_types.h"
12 #include "ui/ozone/platform/drm/gpu/drm_device.h"
16 DrmConsoleBuffer::DrmConsoleBuffer(const scoped_refptr
<DrmDevice
>& drm
,
18 : drm_(drm
), framebuffer_(framebuffer
) {
21 DrmConsoleBuffer::~DrmConsoleBuffer() {
23 if (munmap(mmap_base_
, mmap_size_
))
24 PLOG(ERROR
) << "munmap";
26 if (handle_
&& !drm_
->CloseBufferHandle(handle_
))
27 PLOG(ERROR
) << "DrmConsoleBuffer: CloseBufferHandle: handle " << handle_
;
30 bool DrmConsoleBuffer::Initialize() {
31 ScopedDrmFramebufferPtr
fb(drm_
->GetFramebuffer(framebuffer_
));
38 SkImageInfo info
= SkImageInfo::MakeN32Premul(fb
->width
, fb
->height
);
40 mmap_size_
= info
.getSafeSize(stride_
);
42 if (!drm_
->MapDumbBuffer(fb
->handle
, mmap_size_
, &mmap_base_
)) {
48 skia::AdoptRef(SkSurface::NewRasterDirect(info
, mmap_base_
, stride_
));