Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: ui/ozone/platform/drm/gpu/drm_buffer.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_buffer.h ('k') | ui/ozone/platform/drm/gpu/drm_console_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_buffer.h"
6
7 #include "base/logging.h"
8 #include "ui/ozone/platform/drm/gpu/drm_device.h"
9
10 namespace ui {
11
12 namespace {
13
14 // Modesetting cannot happen from a buffer with transparencies. Return the size
15 // of a pixel without alpha.
16 uint8_t GetColorDepth(SkColorType type) {
17 switch (type) {
18 case kUnknown_SkColorType:
19 case kAlpha_8_SkColorType:
20 return 0;
21 case kIndex_8_SkColorType:
22 return 8;
23 case kRGB_565_SkColorType:
24 return 16;
25 case kARGB_4444_SkColorType:
26 return 12;
27 case kN32_SkColorType:
28 return 24;
29 default:
30 NOTREACHED();
31 return 0;
32 }
33 }
34
35 } // namespace
36
37 DrmBuffer::DrmBuffer(const scoped_refptr<DrmDevice>& drm) : drm_(drm) {
38 }
39
40 DrmBuffer::~DrmBuffer() {
41 surface_.clear();
42
43 if (framebuffer_ && !drm_->RemoveFramebuffer(framebuffer_))
44 PLOG(ERROR) << "DrmBuffer: RemoveFramebuffer: fb " << framebuffer_;
45
46 if (mmap_base_ && !drm_->UnmapDumbBuffer(mmap_base_, mmap_size_))
47 PLOG(ERROR) << "DrmBuffer: UnmapDumbBuffer: handle " << handle_;
48
49 if (handle_ && !drm_->DestroyDumbBuffer(handle_))
50 PLOG(ERROR) << "DrmBuffer: DestroyDumbBuffer: handle " << handle_;
51 }
52
53 bool DrmBuffer::Initialize(const SkImageInfo& info,
54 bool should_register_framebuffer) {
55 if (!drm_->CreateDumbBuffer(info, &handle_, &stride_)) {
56 PLOG(ERROR) << "DrmBuffer: CreateDumbBuffer: width " << info.width()
57 << " height " << info.height();
58 return false;
59 }
60
61 mmap_size_ = info.getSafeSize(stride_);
62 if (!drm_->MapDumbBuffer(handle_, mmap_size_, &mmap_base_)) {
63 PLOG(ERROR) << "DrmBuffer: MapDumbBuffer: handle " << handle_;
64 return false;
65 }
66
67 if (should_register_framebuffer &&
68 !drm_->AddFramebuffer(
69 info.width(), info.height(), GetColorDepth(info.colorType()),
70 info.bytesPerPixel() << 3, stride_, handle_, &framebuffer_)) {
71 PLOG(ERROR) << "DrmBuffer: AddFramebuffer: handle " << handle_;
72 return false;
73 }
74
75 surface_ =
76 skia::AdoptRef(SkSurface::NewRasterDirect(info, mmap_base_, stride_));
77 if (!surface_) {
78 LOG(ERROR) << "DrmBuffer: Failed to create SkSurface: handle " << handle_;
79 return false;
80 }
81
82 return true;
83 }
84
85 SkCanvas* DrmBuffer::GetCanvas() const {
86 return surface_->getCanvas();
87 }
88
89 uint32_t DrmBuffer::GetFramebufferId() const {
90 return framebuffer_;
91 }
92
93 uint32_t DrmBuffer::GetHandle() const {
94 return handle_;
95 }
96
97 gfx::Size DrmBuffer::GetSize() const {
98 return gfx::Size(surface_->width(), surface_->height());
99 }
100
101 DrmBufferGenerator::DrmBufferGenerator() {
102 }
103
104 DrmBufferGenerator::~DrmBufferGenerator() {
105 }
106
107 scoped_refptr<ScanoutBuffer> DrmBufferGenerator::Create(
108 const scoped_refptr<DrmDevice>& drm,
109 const gfx::Size& size) {
110 scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm));
111 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
112 if (!buffer->Initialize(info, true /* should_register_framebuffer */))
113 return NULL;
114
115 return buffer;
116 }
117
118 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_buffer.h ('k') | ui/ozone/platform/drm/gpu/drm_console_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698