Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / gbm_buffer_base.cc
blobfc04238a91a3bdff3958ca8045a9bdbd80cb335f
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.
5 #include "ui/ozone/platform/drm/gpu/gbm_buffer_base.h"
7 #include <gbm.h>
9 #include "base/logging.h"
10 #include "ui/ozone/platform/drm/gpu/drm_device.h"
12 namespace ui {
14 namespace {
16 // Pixel configuration for the current buffer format.
17 // TODO(dnicoara) These will need to change once we query the hardware for
18 // supported configurations.
19 const uint8_t kColorDepth = 24;
20 const uint8_t kPixelDepth = 32;
22 } // namespace
24 GbmBufferBase::GbmBufferBase(const scoped_refptr<DrmDevice>& drm,
25 gbm_bo* bo,
26 bool scanout)
27 : drm_(drm), bo_(bo) {
28 if (scanout) {
29 if (!drm_->AddFramebuffer(gbm_bo_get_width(bo), gbm_bo_get_height(bo),
30 kColorDepth, kPixelDepth, gbm_bo_get_stride(bo),
31 gbm_bo_get_handle(bo).u32, &framebuffer_)) {
32 PLOG(ERROR) << "Failed to register buffer";
33 return;
36 fb_pixel_format_ = gbm_bo_get_format(bo);
37 if (fb_pixel_format_ == GBM_FORMAT_ARGB8888)
38 fb_pixel_format_ = GBM_FORMAT_XRGB8888;
40 // For now, we always create a frame buffer of 24 bit color depth and
41 // support only XRGB format.
42 DCHECK(fb_pixel_format_ == GBM_FORMAT_XRGB8888);
46 GbmBufferBase::~GbmBufferBase() {
47 if (framebuffer_)
48 drm_->RemoveFramebuffer(framebuffer_);
51 uint32_t GbmBufferBase::GetFramebufferId() const {
52 return framebuffer_;
55 uint32_t GbmBufferBase::GetHandle() const {
56 return gbm_bo_get_handle(bo_).u32;
59 gfx::Size GbmBufferBase::GetSize() const {
60 return gfx::Size(gbm_bo_get_width(bo_), gbm_bo_get_height(bo_));
63 uint32_t GbmBufferBase::GetFramebufferPixelFormat() const {
64 return fb_pixel_format_;
67 } // namespace ui