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/dri/gbm_buffer.h" | 5 #include "ui/ozone/platform/dri/gbm_buffer.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/dri/dri_wrapper.h" | |
11 #include "ui/ozone/platform/dri/hardware_display_controller.h" | |
12 | 10 |
13 namespace ui { | 11 namespace ui { |
| 12 |
14 namespace { | 13 namespace { |
15 // Pixel configuration for the current buffer format. | |
16 // TODO(dnicoara) These will need to change once we query the hardware for | |
17 // supported configurations. | |
18 const uint8_t kColorDepth = 24; | |
19 const uint8_t kPixelDepth = 32; | |
20 | 14 |
21 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) { | 15 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) { |
22 switch (fmt) { | 16 switch (fmt) { |
23 case SurfaceFactoryOzone::UNKNOWN: | 17 case SurfaceFactoryOzone::UNKNOWN: |
24 return 0; | 18 return 0; |
25 // TODO(alexst): Setting this to XRGB for now to allow presentation | 19 // TODO(alexst): Setting this to XRGB for now to allow presentation |
26 // as a primary plane but disallowing overlay transparency. Address this | 20 // as a primary plane but disallowing overlay transparency. Address this |
27 // to allow both use cases. | 21 // to allow both use cases. |
28 case SurfaceFactoryOzone::RGBA_8888: | 22 case SurfaceFactoryOzone::RGBA_8888: |
29 return GBM_FORMAT_XRGB8888; | 23 return GBM_FORMAT_XRGB8888; |
30 case SurfaceFactoryOzone::RGB_888: | 24 case SurfaceFactoryOzone::RGB_888: |
31 return GBM_FORMAT_RGB888; | 25 return GBM_FORMAT_RGB888; |
32 } | 26 } |
33 return 0; | 27 return 0; |
34 } | 28 } |
35 } | |
36 | 29 |
37 GbmBuffer::GbmBuffer(gbm_device* device, DriWrapper* dri, const gfx::Size& size) | 30 } // namespace |
38 : gbm_device_(device), | 31 |
39 bo_(NULL), | 32 GbmBuffer::GbmBuffer(DriWrapper* dri, gbm_bo* bo, bool scanout) |
40 handle_(0), | 33 : GbmBufferBase(dri, bo, scanout) { |
41 framebuffer_(0), | |
42 dri_(dri), | |
43 size_(size) { | |
44 } | 34 } |
45 | 35 |
46 GbmBuffer::~GbmBuffer() { | 36 GbmBuffer::~GbmBuffer() { |
47 if (framebuffer_) | 37 if (bo()) |
48 dri_->RemoveFramebuffer(framebuffer_); | 38 gbm_bo_destroy(bo()); |
49 if (bo_) | |
50 gbm_bo_destroy(bo_); | |
51 } | 39 } |
52 | 40 |
53 bool GbmBuffer::InitializeBuffer(SurfaceFactoryOzone::BufferFormat format, | 41 // static |
54 bool scanout) { | 42 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( |
| 43 DriWrapper* dri, |
| 44 gbm_device* device, |
| 45 SurfaceFactoryOzone::BufferFormat format, |
| 46 const gfx::Size& size, |
| 47 bool scanout) { |
55 unsigned flags = GBM_BO_USE_RENDERING; | 48 unsigned flags = GBM_BO_USE_RENDERING; |
56 if (scanout) | 49 if (scanout) |
57 flags |= GBM_BO_USE_SCANOUT; | 50 flags |= GBM_BO_USE_SCANOUT; |
58 bo_ = gbm_bo_create(gbm_device_, | 51 gbm_bo* bo = gbm_bo_create(device, |
59 size_.width(), | 52 size.width(), |
60 size_.height(), | 53 size.height(), |
61 GetGbmFormatFromBufferFormat(format), | 54 GetGbmFormatFromBufferFormat(format), |
62 flags); | 55 flags); |
63 if (!bo_) | 56 if (!bo) |
64 return false; | 57 return NULL; |
65 | 58 |
66 gbm_bo_set_user_data(bo_, this, NULL); | 59 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(dri, bo, scanout)); |
67 handle_ = gbm_bo_get_handle(bo_).u32; | 60 if (scanout && !buffer->GetFramebufferId()) |
| 61 return NULL; |
68 | 62 |
69 if (scanout && | 63 return buffer; |
70 !dri_->AddFramebuffer(size_.width(), | |
71 size_.height(), | |
72 kColorDepth, | |
73 kPixelDepth, | |
74 gbm_bo_get_stride(bo_), | |
75 handle_, | |
76 &framebuffer_)) { | |
77 return false; | |
78 } | |
79 return true; | |
80 } | 64 } |
81 | 65 |
82 bool GbmBuffer::Initialize() { | 66 GbmPixmap::GbmPixmap(scoped_refptr<GbmBuffer> buffer) : buffer_(buffer) { |
83 return bo_ != NULL; | |
84 } | |
85 | |
86 uint32_t GbmBuffer::GetFramebufferId() const { | |
87 return framebuffer_; | |
88 } | |
89 | |
90 uint32_t GbmBuffer::GetHandle() const { | |
91 return handle_; | |
92 } | |
93 | |
94 gfx::Size GbmBuffer::Size() const { | |
95 return size_; | |
96 } | |
97 | |
98 void GbmBuffer::PreSwapBuffers() { | |
99 } | |
100 | |
101 void GbmBuffer::SwapBuffers() { | |
102 } | |
103 | |
104 GbmPixmap::GbmPixmap(gbm_device* device, DriWrapper* dri, const gfx::Size& size) | |
105 : buffer_(device, dri, size) { | |
106 } | 67 } |
107 | 68 |
108 GbmPixmap::~GbmPixmap() { | 69 GbmPixmap::~GbmPixmap() { |
109 } | 70 } |
110 | 71 |
111 void* GbmPixmap::GetEGLClientBuffer() { | 72 void* GbmPixmap::GetEGLClientBuffer() { |
112 return buffer_.bo(); | 73 return buffer_->bo(); |
113 } | 74 } |
114 | 75 |
115 int GbmPixmap::GetDmaBufFd() { | 76 int GbmPixmap::GetDmaBufFd() { |
| 77 NOTIMPLEMENTED(); |
116 return -1; | 78 return -1; |
117 } | 79 } |
118 | 80 |
119 } // namespace ui | 81 } // namespace ui |
OLD | NEW |