| OLD | NEW |
| 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/drm/gpu/drm_buffer.h" | 5 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" |
| 6 | 6 |
| 7 #include <drm_fourcc.h> | 7 #include <drm_fourcc.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/ozone/platform/drm/gpu/drm_device.h" | 10 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| 11 | 11 |
| 12 namespace ui { | 12 namespace ui { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Modesetting cannot happen from a buffer with transparencies. Return the size | |
| 17 // of a pixel without alpha. | |
| 18 uint8_t GetColorDepth(SkColorType type) { | |
| 19 switch (type) { | |
| 20 case kUnknown_SkColorType: | |
| 21 case kAlpha_8_SkColorType: | |
| 22 return 0; | |
| 23 case kIndex_8_SkColorType: | |
| 24 return 8; | |
| 25 case kRGB_565_SkColorType: | |
| 26 return 16; | |
| 27 case kARGB_4444_SkColorType: | |
| 28 return 12; | |
| 29 case kN32_SkColorType: | |
| 30 return 24; | |
| 31 default: | |
| 32 NOTREACHED(); | |
| 33 return 0; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 // We always ignore Alpha. | 16 // We always ignore Alpha. |
| 38 uint32_t GetFourCCCodeForSkColorType(SkColorType type) { | 17 uint32_t GetFourCCCodeForSkColorType(SkColorType type) { |
| 39 switch (type) { | 18 switch (type) { |
| 40 case kUnknown_SkColorType: | 19 case kUnknown_SkColorType: |
| 41 case kAlpha_8_SkColorType: | 20 case kAlpha_8_SkColorType: |
| 42 return 0; | 21 return 0; |
| 43 case kIndex_8_SkColorType: | 22 case kIndex_8_SkColorType: |
| 44 return DRM_FORMAT_C8; | 23 return DRM_FORMAT_C8; |
| 45 case kRGB_565_SkColorType: | 24 case kRGB_565_SkColorType: |
| 46 return DRM_FORMAT_RGB565; | 25 return DRM_FORMAT_RGB565; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return false; | 59 return false; |
| 81 } | 60 } |
| 82 | 61 |
| 83 mmap_size_ = info.getSafeSize(stride_); | 62 mmap_size_ = info.getSafeSize(stride_); |
| 84 if (!drm_->MapDumbBuffer(handle_, mmap_size_, &mmap_base_)) { | 63 if (!drm_->MapDumbBuffer(handle_, mmap_size_, &mmap_base_)) { |
| 85 PLOG(ERROR) << "DrmBuffer: MapDumbBuffer: handle " << handle_; | 64 PLOG(ERROR) << "DrmBuffer: MapDumbBuffer: handle " << handle_; |
| 86 return false; | 65 return false; |
| 87 } | 66 } |
| 88 | 67 |
| 89 if (should_register_framebuffer) { | 68 if (should_register_framebuffer) { |
| 90 if (!drm_->AddFramebuffer( | 69 uint32_t handles[4] = {0}; |
| 91 info.width(), info.height(), GetColorDepth(info.colorType()), | 70 handles[0] = handle_; |
| 92 info.bytesPerPixel() << 3, stride_, handle_, &framebuffer_)) { | 71 uint32_t strides[4] = {0}; |
| 93 PLOG(ERROR) << "DrmBuffer: AddFramebuffer: handle " << handle_; | 72 strides[0] = stride_; |
| 73 uint32_t offsets[4] = {0}; |
| 74 fb_pixel_format_ = GetFourCCCodeForSkColorType(info.colorType()); |
| 75 if (!drm_->AddFramebuffer2(info.width(), info.height(), fb_pixel_format_, |
| 76 handles, strides, offsets, &framebuffer_, 0)) { |
| 77 PLOG(ERROR) << "DrmBuffer: AddFramebuffer2: handle " << handle_; |
| 94 return false; | 78 return false; |
| 95 } | 79 } |
| 96 | |
| 97 fb_pixel_format_ = GetFourCCCodeForSkColorType(info.colorType()); | |
| 98 } | 80 } |
| 99 | 81 |
| 100 surface_ = | 82 surface_ = |
| 101 skia::AdoptRef(SkSurface::NewRasterDirect(info, mmap_base_, stride_)); | 83 skia::AdoptRef(SkSurface::NewRasterDirect(info, mmap_base_, stride_)); |
| 102 if (!surface_) { | 84 if (!surface_) { |
| 103 LOG(ERROR) << "DrmBuffer: Failed to create SkSurface: handle " << handle_; | 85 LOG(ERROR) << "DrmBuffer: Failed to create SkSurface: handle " << handle_; |
| 104 return false; | 86 return false; |
| 105 } | 87 } |
| 106 | 88 |
| 107 return true; | 89 return true; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 const gfx::Size& size) { | 125 const gfx::Size& size) { |
| 144 scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm)); | 126 scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm)); |
| 145 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); | 127 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); |
| 146 if (!buffer->Initialize(info, true /* should_register_framebuffer */)) | 128 if (!buffer->Initialize(info, true /* should_register_framebuffer */)) |
| 147 return NULL; | 129 return NULL; |
| 148 | 130 |
| 149 return buffer; | 131 return buffer; |
| 150 } | 132 } |
| 151 | 133 |
| 152 } // namespace ui | 134 } // namespace ui |
| OLD | NEW |