| 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/gbm_buffer_base.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_buffer_base.h" |
| 6 | 6 |
| 7 #include <gbm.h> | 7 #include <gbm.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/ozone/platform/drm/common/drm_util.h" | 10 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 11 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 11 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 GbmBufferBase::GbmBufferBase(const scoped_refptr<GbmDevice>& drm, | 15 GbmBufferBase::GbmBufferBase(const scoped_refptr<GbmDevice>& drm, |
| 16 gbm_bo* bo, | 16 gbm_bo* bo, |
| 17 uint32_t format, | 17 uint32_t format, |
| 18 uint32_t flags, | 18 uint32_t flags, |
| 19 uint64_t modifier, | 19 uint64_t modifier, |
| 20 uint32_t addfb_flags) | 20 uint32_t addfb_flags) |
| 21 : drm_(drm), bo_(bo) { | 21 : drm_(drm), bo_(bo) { |
| 22 if (flags & GBM_BO_USE_SCANOUT) { | 22 if (flags & GBM_BO_USE_SCANOUT) { |
| 23 DCHECK(bo_); | 23 DCHECK(bo_); |
| 24 // The framebuffer format might be different than the format: | 24 framebuffer_pixel_format_ = format; |
| 25 // drm supports 24 bit color depth and formats with alpha will | 25 opaque_framebuffer_pixel_format_ = GetFourCCFormatForOpaqueFramebuffer( |
| 26 // be converted to one without it. | 26 GetBufferFormatFromFourCCFormat(format)); |
| 27 framebuffer_pixel_format_ = | |
| 28 GetFourCCFormatForFramebuffer(GetBufferFormatFromFourCCFormat(format)); | |
| 29 | 27 |
| 30 // TODO(dcastagna): Add multi-planar support. | 28 // TODO(dcastagna): Add multi-planar support. |
| 31 uint32_t handles[4] = {0}; | 29 uint32_t handles[4] = {0}; |
| 32 handles[0] = gbm_bo_get_handle(bo).u32; | 30 handles[0] = gbm_bo_get_handle(bo).u32; |
| 33 uint32_t strides[4] = {0}; | 31 uint32_t strides[4] = {0}; |
| 34 strides[0] = gbm_bo_get_stride(bo); | 32 strides[0] = gbm_bo_get_stride(bo); |
| 35 uint32_t offsets[4] = {0}; | 33 uint32_t offsets[4] = {0}; |
| 36 uint64_t modifiers[4] = {0}; | 34 uint64_t modifiers[4] = {0}; |
| 37 modifiers[0] = modifier; | 35 modifiers[0] = modifier; |
| 38 | 36 |
| 39 // AddFramebuffer2 only considers the modifiers if addfb_flags has | 37 // AddFramebuffer2 only considers the modifiers if addfb_flags has |
| 40 // DRM_MODE_FB_MODIFIERS set. We only set that when we've created | 38 // DRM_MODE_FB_MODIFIERS set. We only set that when we've created |
| 41 // a bo with modifiers, otherwise, we rely on the "no modifiers" | 39 // a bo with modifiers, otherwise, we rely on the "no modifiers" |
| 42 // behavior doing the right thing. | 40 // behavior doing the right thing. |
| 43 drm_->AddFramebuffer2(gbm_bo_get_width(bo), gbm_bo_get_height(bo), | 41 drm_->AddFramebuffer2(gbm_bo_get_width(bo), gbm_bo_get_height(bo), |
| 44 framebuffer_pixel_format_, handles, strides, offsets, | 42 framebuffer_pixel_format_, handles, strides, offsets, |
| 45 modifiers, &framebuffer_, addfb_flags); | 43 modifiers, &framebuffer_, addfb_flags); |
| 44 if (opaque_framebuffer_pixel_format_ != framebuffer_pixel_format_) { |
| 45 drm_->AddFramebuffer2(gbm_bo_get_width(bo), gbm_bo_get_height(bo), |
| 46 opaque_framebuffer_pixel_format_, handles, strides, |
| 47 offsets, modifiers, &opaque_framebuffer_, |
| 48 addfb_flags); |
| 49 } |
| 46 } | 50 } |
| 47 } | 51 } |
| 48 | 52 |
| 49 GbmBufferBase::~GbmBufferBase() { | 53 GbmBufferBase::~GbmBufferBase() { |
| 50 if (framebuffer_) | 54 if (framebuffer_) |
| 51 drm_->RemoveFramebuffer(framebuffer_); | 55 drm_->RemoveFramebuffer(framebuffer_); |
| 52 } | 56 } |
| 53 | 57 |
| 54 uint32_t GbmBufferBase::GetFramebufferId() const { | 58 uint32_t GbmBufferBase::GetFramebufferId() const { |
| 55 return framebuffer_; | 59 return framebuffer_; |
| 56 } | 60 } |
| 57 | 61 |
| 62 uint32_t GbmBufferBase::GetOpaqueFramebufferId() const { |
| 63 return opaque_framebuffer_ ? opaque_framebuffer_ : framebuffer_; |
| 64 } |
| 65 |
| 58 uint32_t GbmBufferBase::GetHandle() const { | 66 uint32_t GbmBufferBase::GetHandle() const { |
| 59 return gbm_bo_get_handle(bo_).u32; | 67 return gbm_bo_get_handle(bo_).u32; |
| 60 } | 68 } |
| 61 | 69 |
| 62 gfx::Size GbmBufferBase::GetSize() const { | 70 gfx::Size GbmBufferBase::GetSize() const { |
| 63 return gfx::Size(gbm_bo_get_width(bo_), gbm_bo_get_height(bo_)); | 71 return gfx::Size(gbm_bo_get_width(bo_), gbm_bo_get_height(bo_)); |
| 64 } | 72 } |
| 65 | 73 |
| 66 uint32_t GbmBufferBase::GetFramebufferPixelFormat() const { | 74 uint32_t GbmBufferBase::GetFramebufferPixelFormat() const { |
| 67 DCHECK(framebuffer_); | 75 DCHECK(framebuffer_); |
| 68 return framebuffer_pixel_format_; | 76 return framebuffer_pixel_format_; |
| 69 } | 77 } |
| 70 | 78 |
| 79 uint32_t GbmBufferBase::GetOpaqueFramebufferPixelFormat() const { |
| 80 DCHECK(framebuffer_); |
| 81 return opaque_framebuffer_pixel_format_; |
| 82 } |
| 83 |
| 71 const DrmDevice* GbmBufferBase::GetDrmDevice() const { | 84 const DrmDevice* GbmBufferBase::GetDrmDevice() const { |
| 72 return drm_.get(); | 85 return drm_.get(); |
| 73 } | 86 } |
| 74 | 87 |
| 75 bool GbmBufferBase::RequiresGlFinish() const { | 88 bool GbmBufferBase::RequiresGlFinish() const { |
| 76 return !drm_->is_primary_device(); | 89 return !drm_->is_primary_device(); |
| 77 } | 90 } |
| 78 | 91 |
| 79 } // namespace ui | 92 } // namespace ui |
| OLD | NEW |