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/dri/gbm_buffer.h" |
| 6 |
| 7 #include <gbm.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "ui/ozone/platform/dri/dri_wrapper.h" |
| 11 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 12 |
| 13 namespace ui { |
| 14 namespace { |
| 15 // Pixel configuration for the current buffer format. |
| 16 // TODO(dnicoara) These will need to change once we query the hardware for |
| 17 // supported configurations. |
| 18 const uint8_t kColorDepth = 24; |
| 19 const uint8_t kPixelDepth = 32; |
| 20 |
| 21 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) { |
| 22 switch (fmt) { |
| 23 case SurfaceFactoryOzone::UNKNOWN: |
| 24 return 0; |
| 25 // TODO(alexst): Setting this to XRGB for now to allow presentation |
| 26 // as a primary plane but disallowing overlay transparency. Address this |
| 27 // to allow both use cases. |
| 28 case SurfaceFactoryOzone::RGBA_8888: |
| 29 return GBM_FORMAT_XRGB8888; |
| 30 case SurfaceFactoryOzone::RGB_888: |
| 31 return GBM_FORMAT_RGB888; |
| 32 } |
| 33 return 0; |
| 34 } |
| 35 } |
| 36 |
| 37 GbmBuffer::GbmBuffer(gbm_device* device, DriWrapper* dri, const gfx::Size& size) |
| 38 : gbm_device_(device), |
| 39 bo_(NULL), |
| 40 handle_(0), |
| 41 framebuffer_(0), |
| 42 dri_(dri), |
| 43 size_(size) { |
| 44 } |
| 45 |
| 46 GbmBuffer::~GbmBuffer() { |
| 47 if (framebuffer_) |
| 48 dri_->RemoveFramebuffer(framebuffer_); |
| 49 if (bo_) |
| 50 gbm_bo_destroy(bo_); |
| 51 } |
| 52 |
| 53 bool GbmBuffer::InitializeBuffer(SurfaceFactoryOzone::BufferFormat format, |
| 54 bool scanout) { |
| 55 unsigned flags = GBM_BO_USE_RENDERING; |
| 56 if (scanout) |
| 57 flags |= GBM_BO_USE_SCANOUT; |
| 58 bo_ = gbm_bo_create(gbm_device_, |
| 59 size_.width(), |
| 60 size_.height(), |
| 61 GetGbmFormatFromBufferFormat(format), |
| 62 flags); |
| 63 if (!bo_) |
| 64 return false; |
| 65 |
| 66 gbm_bo_set_user_data(bo_, this, NULL); |
| 67 handle_ = gbm_bo_get_handle(bo_).u32; |
| 68 |
| 69 if (scanout && |
| 70 !dri_->AddFramebuffer(size_.width(), |
| 71 size_.height(), |
| 72 kColorDepth, |
| 73 kPixelDepth, |
| 74 gbm_bo_get_stride(bo_), |
| 75 handle_, |
| 76 &framebuffer_)) { |
| 77 return false; |
| 78 } |
| 79 return true; |
| 80 } |
| 81 |
| 82 void* GbmBuffer::GetEGLClientBuffer() { |
| 83 return bo_; |
| 84 } |
| 85 |
| 86 int GbmBuffer::GetDmaBufFd() { |
| 87 return -1; |
| 88 } |
| 89 |
| 90 } // namespace ui |
OLD | NEW |