Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / drm_console_buffer.cc
blob464c380526972f8ba79e940e33b921d26e427104
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"
7 #include <sys/mman.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"
14 namespace ui {
16 DrmConsoleBuffer::DrmConsoleBuffer(const scoped_refptr<DrmDevice>& drm,
17 uint32_t framebuffer)
18 : drm_(drm), framebuffer_(framebuffer) {
21 DrmConsoleBuffer::~DrmConsoleBuffer() {
22 if (mmap_base_)
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_));
33 if (!fb)
34 return false;
36 handle_ = fb->handle;
37 stride_ = fb->pitch;
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_)) {
43 mmap_base_ = NULL;
44 return false;
47 surface_ =
48 skia::AdoptRef(SkSurface::NewRasterDirect(info, mmap_base_, stride_));
49 if (!surface_)
50 return false;
52 return true;
55 } // namespace ui