summaryrefslogtreecommitdiffstats
path: root/ui/ozone/platform/drm/gpu/gbm_buffer_base.cc
blob: 7b36652e4f2bb366308cfe4b2dfc86b76b2c26b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/ozone/platform/drm/gpu/gbm_buffer_base.h"

#include <gbm.h>

#include "base/logging.h"
#include "ui/ozone/platform/drm/gpu/drm_device.h"

namespace ui {

namespace {

// Pixel configuration for the current buffer format.
// TODO(dnicoara) These will need to change once we query the hardware for
// supported configurations.
const uint8_t kColorDepth = 24;
const uint8_t kPixelDepth = 32;

}  // namespace

GbmBufferBase::GbmBufferBase(const scoped_refptr<DrmDevice>& drm,
                             gbm_bo* bo,
                             bool scanout)
    : drm_(drm), bo_(bo), framebuffer_(0) {
  if (scanout &&
      !drm_->AddFramebuffer(gbm_bo_get_width(bo), gbm_bo_get_height(bo),
                            kColorDepth, kPixelDepth, gbm_bo_get_stride(bo),
                            gbm_bo_get_handle(bo).u32, &framebuffer_))
    PLOG(ERROR) << "Failed to register buffer";
}

GbmBufferBase::~GbmBufferBase() {
  if (framebuffer_)
    drm_->RemoveFramebuffer(framebuffer_);
}

uint32_t GbmBufferBase::GetFramebufferId() const {
  return framebuffer_;
}

uint32_t GbmBufferBase::GetHandle() const {
  return gbm_bo_get_handle(bo_).u32;
}

gfx::Size GbmBufferBase::GetSize() const {
  return gfx::Size(gbm_bo_get_width(bo_), gbm_bo_get_height(bo_));
}

}  // namespace ui