| 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> | 
 |    8  | 
|    7 #include "base/logging.h" |    9 #include "base/logging.h" | 
|    8 #include "ui/ozone/platform/drm/gpu/drm_device.h" |   10 #include "ui/ozone/platform/drm/gpu/drm_device.h" | 
|    9  |   11  | 
|   10 namespace ui { |   12 namespace ui { | 
|   11  |   13  | 
|   12 namespace { |   14 namespace { | 
|   13  |   15  | 
|   14 // Modesetting cannot happen from a buffer with transparencies. Return the size |   16 // Modesetting cannot happen from a buffer with transparencies. Return the size | 
|   15 // of a pixel without alpha. |   17 // of a pixel without alpha. | 
|   16 uint8_t GetColorDepth(SkColorType type) { |   18 uint8_t GetColorDepth(SkColorType type) { | 
|   17   switch (type) { |   19   switch (type) { | 
|   18     case kUnknown_SkColorType: |   20     case kUnknown_SkColorType: | 
|   19     case kAlpha_8_SkColorType: |   21     case kAlpha_8_SkColorType: | 
|   20       return 0; |   22       return 0; | 
|   21     case kIndex_8_SkColorType: |   23     case kIndex_8_SkColorType: | 
|   22       return 8; |   24       return 8; | 
|   23     case kRGB_565_SkColorType: |   25     case kRGB_565_SkColorType: | 
|   24       return 16; |   26       return 16; | 
|   25     case kARGB_4444_SkColorType: |   27     case kARGB_4444_SkColorType: | 
|   26       return 12; |   28       return 12; | 
|   27     case kN32_SkColorType: |   29     case kN32_SkColorType: | 
|   28       return 24; |   30       return 24; | 
|   29     default: |   31     default: | 
|   30       NOTREACHED(); |   32       NOTREACHED(); | 
|   31       return 0; |   33       return 0; | 
|   32   } |   34   } | 
|   33 } |   35 } | 
|   34  |   36  | 
 |   37 // We always ignore Alpha. | 
 |   38 uint32_t GetFourCCCodeForSkColorType(SkColorType type) { | 
 |   39   switch (type) { | 
 |   40     case kUnknown_SkColorType: | 
 |   41     case kAlpha_8_SkColorType: | 
 |   42       return 0; | 
 |   43     case kIndex_8_SkColorType: | 
 |   44       return DRM_FORMAT_C8; | 
 |   45     case kRGB_565_SkColorType: | 
 |   46       return DRM_FORMAT_RGB565; | 
 |   47     case kARGB_4444_SkColorType: | 
 |   48       return DRM_FORMAT_XRGB4444; | 
 |   49     case kN32_SkColorType: | 
 |   50       return DRM_FORMAT_XRGB8888; | 
 |   51     default: | 
 |   52       NOTREACHED(); | 
 |   53       return 0; | 
 |   54   } | 
 |   55 } | 
 |   56  | 
|   35 }  // namespace |   57 }  // namespace | 
|   36  |   58  | 
|   37 DrmBuffer::DrmBuffer(const scoped_refptr<DrmDevice>& drm) : drm_(drm) { |   59 DrmBuffer::DrmBuffer(const scoped_refptr<DrmDevice>& drm) : drm_(drm) { | 
|   38 } |   60 } | 
|   39  |   61  | 
|   40 DrmBuffer::~DrmBuffer() { |   62 DrmBuffer::~DrmBuffer() { | 
|   41   surface_.clear(); |   63   surface_.clear(); | 
|   42  |   64  | 
|   43   if (framebuffer_ && !drm_->RemoveFramebuffer(framebuffer_)) |   65   if (framebuffer_ && !drm_->RemoveFramebuffer(framebuffer_)) | 
|   44     PLOG(ERROR) << "DrmBuffer: RemoveFramebuffer: fb " << framebuffer_; |   66     PLOG(ERROR) << "DrmBuffer: RemoveFramebuffer: fb " << framebuffer_; | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|   57                 << " height " << info.height(); |   79                 << " height " << info.height(); | 
|   58     return false; |   80     return false; | 
|   59   } |   81   } | 
|   60  |   82  | 
|   61   mmap_size_ = info.getSafeSize(stride_); |   83   mmap_size_ = info.getSafeSize(stride_); | 
|   62   if (!drm_->MapDumbBuffer(handle_, mmap_size_, &mmap_base_)) { |   84   if (!drm_->MapDumbBuffer(handle_, mmap_size_, &mmap_base_)) { | 
|   63     PLOG(ERROR) << "DrmBuffer: MapDumbBuffer: handle " << handle_; |   85     PLOG(ERROR) << "DrmBuffer: MapDumbBuffer: handle " << handle_; | 
|   64     return false; |   86     return false; | 
|   65   } |   87   } | 
|   66  |   88  | 
|   67   if (should_register_framebuffer && |   89   if (should_register_framebuffer) { | 
|   68       !drm_->AddFramebuffer( |   90     if (!drm_->AddFramebuffer( | 
|   69           info.width(), info.height(), GetColorDepth(info.colorType()), |   91             info.width(), info.height(), GetColorDepth(info.colorType()), | 
|   70           info.bytesPerPixel() << 3, stride_, handle_, &framebuffer_)) { |   92             info.bytesPerPixel() << 3, stride_, handle_, &framebuffer_)) { | 
|   71     PLOG(ERROR) << "DrmBuffer: AddFramebuffer: handle " << handle_; |   93       PLOG(ERROR) << "DrmBuffer: AddFramebuffer: handle " << handle_; | 
|   72     return false; |   94       return false; | 
 |   95     } | 
 |   96  | 
 |   97     fb_pixel_format_ = GetFourCCCodeForSkColorType(info.colorType()); | 
|   73   } |   98   } | 
|   74  |   99  | 
|   75   surface_ = |  100   surface_ = | 
|   76       skia::AdoptRef(SkSurface::NewRasterDirect(info, mmap_base_, stride_)); |  101       skia::AdoptRef(SkSurface::NewRasterDirect(info, mmap_base_, stride_)); | 
|   77   if (!surface_) { |  102   if (!surface_) { | 
|   78     LOG(ERROR) << "DrmBuffer: Failed to create SkSurface: handle " << handle_; |  103     LOG(ERROR) << "DrmBuffer: Failed to create SkSurface: handle " << handle_; | 
|   79     return false; |  104     return false; | 
|   80   } |  105   } | 
|   81  |  106  | 
|   82   return true; |  107   return true; | 
|   83 } |  108 } | 
|   84  |  109  | 
|   85 SkCanvas* DrmBuffer::GetCanvas() const { |  110 SkCanvas* DrmBuffer::GetCanvas() const { | 
|   86   return surface_->getCanvas(); |  111   return surface_->getCanvas(); | 
|   87 } |  112 } | 
|   88  |  113  | 
|   89 uint32_t DrmBuffer::GetFramebufferId() const { |  114 uint32_t DrmBuffer::GetFramebufferId() const { | 
|   90   return framebuffer_; |  115   return framebuffer_; | 
|   91 } |  116 } | 
|   92  |  117  | 
 |  118 uint32_t DrmBuffer::GetFramebufferPixelFormat() const { | 
 |  119   return fb_pixel_format_; | 
 |  120 } | 
 |  121  | 
|   93 uint32_t DrmBuffer::GetHandle() const { |  122 uint32_t DrmBuffer::GetHandle() const { | 
|   94   return handle_; |  123   return handle_; | 
|   95 } |  124 } | 
|   96  |  125  | 
|   97 gfx::Size DrmBuffer::GetSize() const { |  126 gfx::Size DrmBuffer::GetSize() const { | 
|   98   return gfx::Size(surface_->width(), surface_->height()); |  127   return gfx::Size(surface_->width(), surface_->height()); | 
|   99 } |  128 } | 
|  100  |  129  | 
|  101 uint32_t DrmBuffer::GetFormat() const { |  | 
|  102   return 0; |  | 
|  103 } |  | 
|  104  |  | 
|  105 DrmBufferGenerator::DrmBufferGenerator() { |  130 DrmBufferGenerator::DrmBufferGenerator() { | 
|  106 } |  131 } | 
|  107  |  132  | 
|  108 DrmBufferGenerator::~DrmBufferGenerator() { |  133 DrmBufferGenerator::~DrmBufferGenerator() { | 
|  109 } |  134 } | 
|  110  |  135  | 
|  111 scoped_refptr<ScanoutBuffer> DrmBufferGenerator::Create( |  136 scoped_refptr<ScanoutBuffer> DrmBufferGenerator::Create( | 
|  112     const scoped_refptr<DrmDevice>& drm, |  137     const scoped_refptr<DrmDevice>& drm, | 
|  113     const gfx::Size& size) { |  138     const gfx::Size& size) { | 
|  114   scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm)); |  139   scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm)); | 
|  115   SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); |  140   SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); | 
|  116   if (!buffer->Initialize(info, true /* should_register_framebuffer */)) |  141   if (!buffer->Initialize(info, true /* should_register_framebuffer */)) | 
|  117     return NULL; |  142     return NULL; | 
|  118  |  143  | 
|  119   return buffer; |  144   return buffer; | 
|  120 } |  145 } | 
|  121  |  146  | 
|  122 }  // namespace ui |  147 }  // namespace ui | 
| OLD | NEW |