OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ui/ozone/platform/drm/gpu/drm_console_buffer.h" |
| 6 |
| 7 #include <sys/mman.h> |
| 8 #include <xf86drmMode.h> |
| 9 |
| 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" |
| 13 |
| 14 namespace ui { |
| 15 |
| 16 DrmConsoleBuffer::DrmConsoleBuffer(const scoped_refptr<DrmDevice>& drm, |
| 17 uint32_t framebuffer) |
| 18 : drm_(drm), framebuffer_(framebuffer) { |
| 19 } |
| 20 |
| 21 DrmConsoleBuffer::~DrmConsoleBuffer() { |
| 22 if (mmap_base_) |
| 23 if (munmap(mmap_base_, mmap_size_)) |
| 24 PLOG(ERROR) << "munmap"; |
| 25 |
| 26 if (handle_ && !drm_->CloseBufferHandle(handle_)) |
| 27 PLOG(ERROR) << "DrmConsoleBuffer: CloseBufferHandle: handle " << handle_; |
| 28 } |
| 29 |
| 30 bool DrmConsoleBuffer::Initialize() { |
| 31 ScopedDrmFramebufferPtr fb(drm_->GetFramebuffer(framebuffer_)); |
| 32 |
| 33 if (!fb) |
| 34 return false; |
| 35 |
| 36 handle_ = fb->handle; |
| 37 stride_ = fb->pitch; |
| 38 SkImageInfo info = SkImageInfo::MakeN32Premul(fb->width, fb->height); |
| 39 |
| 40 mmap_size_ = info.getSafeSize(stride_); |
| 41 |
| 42 if (!drm_->MapDumbBuffer(fb->handle, mmap_size_, &mmap_base_)) { |
| 43 mmap_base_ = NULL; |
| 44 return false; |
| 45 } |
| 46 |
| 47 surface_ = |
| 48 skia::AdoptRef(SkSurface::NewRasterDirect(info, mmap_base_, stride_)); |
| 49 if (!surface_) |
| 50 return false; |
| 51 |
| 52 return true; |
| 53 } |
| 54 |
| 55 } // namespace ui |
OLD | NEW |