Home | History | Annotate | Download | only in dri
      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 
     11 namespace ui {
     12 
     13 namespace {
     14 
     15 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) {
     16   switch (fmt) {
     17     case SurfaceFactoryOzone::RGBA_8888:
     18       return GBM_BO_FORMAT_ARGB8888;
     19     case SurfaceFactoryOzone::RGBX_8888:
     20       return GBM_BO_FORMAT_XRGB8888;
     21     default:
     22       NOTREACHED();
     23       return 0;
     24   }
     25 }
     26 
     27 }  // namespace
     28 
     29 GbmBuffer::GbmBuffer(DriWrapper* dri, gbm_bo* bo, bool scanout)
     30     : GbmBufferBase(dri, bo, scanout) {
     31 }
     32 
     33 GbmBuffer::~GbmBuffer() {
     34   if (bo())
     35     gbm_bo_destroy(bo());
     36 }
     37 
     38 // static
     39 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
     40     DriWrapper* dri,
     41     gbm_device* device,
     42     SurfaceFactoryOzone::BufferFormat format,
     43     const gfx::Size& size,
     44     bool scanout) {
     45   unsigned flags = GBM_BO_USE_RENDERING;
     46   if (scanout)
     47     flags |= GBM_BO_USE_SCANOUT;
     48   gbm_bo* bo = gbm_bo_create(device,
     49                              size.width(),
     50                              size.height(),
     51                              GetGbmFormatFromBufferFormat(format),
     52                              flags);
     53   if (!bo)
     54     return NULL;
     55 
     56   scoped_refptr<GbmBuffer> buffer(new GbmBuffer(dri, bo, scanout));
     57   if (scanout && !buffer->GetFramebufferId())
     58     return NULL;
     59 
     60   return buffer;
     61 }
     62 
     63 GbmPixmap::GbmPixmap(scoped_refptr<GbmBuffer> buffer) : buffer_(buffer) {
     64 }
     65 
     66 GbmPixmap::~GbmPixmap() {
     67 }
     68 
     69 void* GbmPixmap::GetEGLClientBuffer() {
     70   return buffer_->bo();
     71 }
     72 
     73 int GbmPixmap::GetDmaBufFd() {
     74   NOTIMPLEMENTED();
     75   return -1;
     76 }
     77 
     78 }  // namespace ui
     79