OLD | NEW |
---|---|
(Empty) | |
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 #include "ui/ozone/platform/dri/dri_wrapper.h" | |
11 #include "ui/ozone/platform/dri/hardware_display_controller.h" | |
12 | |
13 namespace ui { | |
14 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 | |
21 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) { | |
22 switch (fmt) { | |
23 case SurfaceFactoryOzone::UNKNOWN: | |
24 return 0; | |
25 // TODO(alexst): Setting this to XRGB for now to allow presentation | |
26 // as a primary plane but disallowing overlay transparency. Address this | |
27 // to allow both use cases. | |
28 case SurfaceFactoryOzone::RGBA_8888: | |
29 return GBM_FORMAT_XRGB8888; | |
30 case SurfaceFactoryOzone::RGB_888: | |
31 return GBM_FORMAT_RGB888; | |
32 } | |
33 return 0; | |
34 } | |
35 } | |
36 | |
37 GbmBuffer::GbmBuffer(gbm_device* device, DriWrapper* dri, | |
alexst (slow to review)
2014/07/03 18:30:32
nit: these fit in 80chars
achaulk
2014/07/03 19:49:43
Done.
| |
38 const gfx::Size& size) | |
39 : gbm_device_(device), | |
40 bo_(NULL), | |
41 handle_(0), | |
42 framebuffer_(0), | |
43 dri_(dri), | |
44 size_(size) {} | |
45 | |
46 GbmBuffer::~GbmBuffer() { | |
47 if (framebuffer_) | |
48 dri_->RemoveFramebuffer(framebuffer_); | |
49 if (bo_) | |
50 gbm_bo_destroy(bo_); | |
51 } | |
52 | |
53 bool GbmBuffer::InitializeBuffer(SurfaceFactoryOzone::BufferFormat format, | |
54 bool scanout) { | |
55 unsigned flags = GBM_BO_USE_RENDERING; | |
56 if (scanout) | |
57 flags |= GBM_BO_USE_SCANOUT; | |
58 bo_ = gbm_bo_create(gbm_device_, | |
59 size_.width(), | |
60 size_.height(), | |
61 GetGbmFormatFromBufferFormat(format), | |
62 flags); | |
63 if (!bo_) | |
64 return false; | |
65 | |
66 gbm_bo_set_user_data(bo_, this, NULL); | |
67 handle_ = gbm_bo_get_handle(bo_).u32; | |
68 | |
69 if (!dri_->AddFramebuffer(size_.width(), | |
dnicoara
2014/07/03 18:30:16
Should skip this is the buffer isn't a scanout buf
achaulk
2014/07/03 19:49:43
Done.
| |
70 size_.height(), | |
71 kColorDepth, | |
72 kPixelDepth, | |
73 gbm_bo_get_stride(bo_), | |
74 handle_, | |
75 &framebuffer_)) { | |
76 return false; | |
77 } | |
78 return true; | |
79 } | |
80 | |
81 bool GbmBuffer::Initialize() { | |
82 return bo_ != NULL; | |
83 } | |
84 | |
85 uint32_t GbmBuffer::GetFramebufferId() const { | |
86 return framebuffer_; | |
87 } | |
88 | |
89 uint32_t GbmBuffer::GetHandle() const { | |
90 return handle_; | |
91 } | |
92 | |
93 gfx::Size GbmBuffer::Size() const { | |
94 return size_; | |
95 } | |
96 | |
97 void GbmBuffer::SwapBuffers() { | |
98 NOTREACHED(); | |
99 } | |
100 | |
101 void* GbmBuffer::native_handle() OVERRIDE { | |
102 return bo_; | |
103 } | |
104 | |
105 int GbmBuffer::dma_buf_fd() OVERRIDE { | |
106 return -1; | |
107 } | |
108 | |
109 //static | |
alexst (slow to review)
2014/07/03 18:30:32
nit: space after //
achaulk
2014/07/03 19:49:43
Done.
| |
110 GbmBuffer* GbmBuffer::GetFromNative(NativeBufferOzone buffer) { | |
111 gbm_bo* bo = reinterpret_cast<gbm_bo*>(buffer); | |
112 return static_cast<GbmBuffer*>(gbm_bo_get_user_data(bo)); | |
113 } | |
114 | |
115 } // namespace ui | |
OLD | NEW |