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_base.h"
6
7#include <gbm.h>
8
9#include "base/logging.h"
10#include "ui/ozone/platform/dri/dri_wrapper.h"
11
12namespace ui {
13
14namespace {
15
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.
19const uint8_t kColorDepth = 24;
20const uint8_t kPixelDepth = 32;
21
22}  // namespace
23
24GbmBufferBase::GbmBufferBase(DriWrapper* dri, gbm_bo* bo, bool scanout)
25    : dri_(dri), bo_(bo), framebuffer_(0) {
26  if (scanout && !dri_->AddFramebuffer(gbm_bo_get_width(bo),
27                                       gbm_bo_get_height(bo),
28                                       kColorDepth,
29                                       kPixelDepth,
30                                       gbm_bo_get_stride(bo),
31                                       gbm_bo_get_handle(bo).u32,
32                                       &framebuffer_))
33    LOG(ERROR) << "Failed to register buffer";
34}
35
36GbmBufferBase::~GbmBufferBase() {
37  if (framebuffer_)
38    dri_->RemoveFramebuffer(framebuffer_);
39}
40
41uint32_t GbmBufferBase::GetFramebufferId() const {
42  return framebuffer_;
43}
44
45uint32_t GbmBufferBase::GetHandle() const {
46  return gbm_bo_get_handle(bo_).u32;
47}
48
49gfx::Size GbmBufferBase::GetSize() const {
50  return gfx::Size(gbm_bo_get_width(bo_), gbm_bo_get_height(bo_));
51}
52
53}  // namespace ui
54