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

Side by Side Diff: ui/ozone/platform/dri/dri_buffer.cc

Issue 908993003: [Ozone-Dri] Rename DriWrapper to DrmDevice (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@udl3-pass-drm-fd
Patch Set: rebased Created 5 years, 9 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/dri/dri_buffer.h ('k') | ui/ozone/platform/dri/dri_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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/ozone/platform/dri/dri_buffer.h" 5 #include "ui/ozone/platform/dri/dri_buffer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/ozone/platform/dri/dri_wrapper.h" 8 #include "ui/ozone/platform/dri/drm_device.h"
9 9
10 namespace ui { 10 namespace ui {
11 11
12 namespace { 12 namespace {
13 13
14 // Modesetting cannot happen from a buffer with transparencies. Return the size 14 // Modesetting cannot happen from a buffer with transparencies. Return the size
15 // of a pixel without alpha. 15 // of a pixel without alpha.
16 uint8_t GetColorDepth(SkColorType type) { 16 uint8_t GetColorDepth(SkColorType type) {
17 switch (type) { 17 switch (type) {
18 case kUnknown_SkColorType: 18 case kUnknown_SkColorType:
19 case kAlpha_8_SkColorType: 19 case kAlpha_8_SkColorType:
20 return 0; 20 return 0;
21 case kIndex_8_SkColorType: 21 case kIndex_8_SkColorType:
22 return 8; 22 return 8;
23 case kRGB_565_SkColorType: 23 case kRGB_565_SkColorType:
24 return 16; 24 return 16;
25 case kARGB_4444_SkColorType: 25 case kARGB_4444_SkColorType:
26 return 12; 26 return 12;
27 case kN32_SkColorType: 27 case kN32_SkColorType:
28 return 24; 28 return 24;
29 default: 29 default:
30 NOTREACHED(); 30 NOTREACHED();
31 return 0; 31 return 0;
32 } 32 }
33 } 33 }
34 34
35 } // namespace 35 } // namespace
36 36
37 DriBuffer::DriBuffer(const scoped_refptr<DriWrapper>& dri) 37 DriBuffer::DriBuffer(const scoped_refptr<DrmDevice>& drm)
38 : dri_(dri), handle_(0), framebuffer_(0) { 38 : drm_(drm), handle_(0), framebuffer_(0) {
39 } 39 }
40 40
41 DriBuffer::~DriBuffer() { 41 DriBuffer::~DriBuffer() {
42 if (!surface_) 42 if (!surface_)
43 return; 43 return;
44 44
45 if (framebuffer_) 45 if (framebuffer_)
46 dri_->RemoveFramebuffer(framebuffer_); 46 drm_->RemoveFramebuffer(framebuffer_);
47 47
48 SkImageInfo info; 48 SkImageInfo info;
49 void* pixels = const_cast<void*>(surface_->peekPixels(&info, NULL)); 49 void* pixels = const_cast<void*>(surface_->peekPixels(&info, NULL));
50 if (!pixels) 50 if (!pixels)
51 return; 51 return;
52 52
53 dri_->DestroyDumbBuffer(info, handle_, stride_, pixels); 53 drm_->DestroyDumbBuffer(info, handle_, stride_, pixels);
54 } 54 }
55 55
56 bool DriBuffer::Initialize(const SkImageInfo& info, 56 bool DriBuffer::Initialize(const SkImageInfo& info,
57 bool should_register_framebuffer) { 57 bool should_register_framebuffer) {
58 void* pixels = NULL; 58 void* pixels = NULL;
59 if (!dri_->CreateDumbBuffer(info, &handle_, &stride_, &pixels)) { 59 if (!drm_->CreateDumbBuffer(info, &handle_, &stride_, &pixels)) {
60 VLOG(2) << "Cannot create drm dumb buffer"; 60 VLOG(2) << "Cannot create drm dumb buffer";
61 return false; 61 return false;
62 } 62 }
63 63
64 if (should_register_framebuffer && 64 if (should_register_framebuffer &&
65 !dri_->AddFramebuffer( 65 !drm_->AddFramebuffer(
66 info.width(), info.height(), GetColorDepth(info.colorType()), 66 info.width(), info.height(), GetColorDepth(info.colorType()),
67 info.bytesPerPixel() << 3, stride_, handle_, &framebuffer_)) { 67 info.bytesPerPixel() << 3, stride_, handle_, &framebuffer_)) {
68 VLOG(2) << "Failed to register framebuffer: " << strerror(errno); 68 VLOG(2) << "Failed to register framebuffer: " << strerror(errno);
69 return false; 69 return false;
70 } 70 }
71 71
72 surface_ = skia::AdoptRef(SkSurface::NewRasterDirect(info, pixels, stride_)); 72 surface_ = skia::AdoptRef(SkSurface::NewRasterDirect(info, pixels, stride_));
73 if (!surface_) { 73 if (!surface_) {
74 VLOG(2) << "Cannot install Skia pixels for drm buffer"; 74 VLOG(2) << "Cannot install Skia pixels for drm buffer";
75 return false; 75 return false;
(...skipping 17 matching lines...) Expand all
93 gfx::Size DriBuffer::GetSize() const { 93 gfx::Size DriBuffer::GetSize() const {
94 return gfx::Size(surface_->width(), surface_->height()); 94 return gfx::Size(surface_->width(), surface_->height());
95 } 95 }
96 96
97 DriBufferGenerator::DriBufferGenerator() { 97 DriBufferGenerator::DriBufferGenerator() {
98 } 98 }
99 99
100 DriBufferGenerator::~DriBufferGenerator() {} 100 DriBufferGenerator::~DriBufferGenerator() {}
101 101
102 scoped_refptr<ScanoutBuffer> DriBufferGenerator::Create( 102 scoped_refptr<ScanoutBuffer> DriBufferGenerator::Create(
103 const scoped_refptr<DriWrapper>& drm, 103 const scoped_refptr<DrmDevice>& drm,
104 const gfx::Size& size) { 104 const gfx::Size& size) {
105 scoped_refptr<DriBuffer> buffer(new DriBuffer(drm)); 105 scoped_refptr<DriBuffer> buffer(new DriBuffer(drm));
106 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); 106 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
107 if (!buffer->Initialize(info, true /* should_register_framebuffer */)) 107 if (!buffer->Initialize(info, true /* should_register_framebuffer */))
108 return NULL; 108 return NULL;
109 109
110 return buffer; 110 return buffer;
111 } 111 }
112 112
113 } // namespace ui 113 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/dri_buffer.h ('k') | ui/ozone/platform/dri/dri_console_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698