Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / drm_console_buffer.cc
blob743fbaec8dedc022eb0c76840c69cdb9c72a8cbb
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/gpu/drm_device.h"
12 #include "ui/ozone/platform/drm/gpu/drm_util.h"
13 #include "ui/ozone/platform/drm/gpu/scoped_drm_types.h"
15 namespace ui {
17 DrmConsoleBuffer::DrmConsoleBuffer(const scoped_refptr<DrmDevice>& drm,
18 uint32_t framebuffer)
19 : drm_(drm),
20 handle_(0),
21 framebuffer_(framebuffer),
22 mmap_base_(NULL),
23 mmap_size_(0) {
26 DrmConsoleBuffer::~DrmConsoleBuffer() {
27 if (mmap_base_)
28 if (munmap(mmap_base_, mmap_size_))
29 PLOG(ERROR) << "munmap";
32 bool DrmConsoleBuffer::Initialize() {
33 ScopedDrmFramebufferPtr fb(drm_->GetFramebuffer(framebuffer_));
35 if (!fb)
36 return false;
38 handle_ = fb->handle;
39 stride_ = fb->pitch;
40 SkImageInfo info = SkImageInfo::MakeN32Premul(fb->width, fb->height);
42 mmap_size_ = info.getSafeSize(stride_);
44 if (!MapDumbBuffer(drm_->get_fd(), fb->handle, mmap_size_, &mmap_base_)) {
45 mmap_base_ = NULL;
46 return false;
49 surface_ =
50 skia::AdoptRef(SkSurface::NewRasterDirect(info, mmap_base_, stride_));
51 if (!surface_)
52 return false;
54 return true;
57 } // namespace ui