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/drm/gpu/gbm_buffer_base.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_buffer_base.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/drm/gpu/drm_device.h" | 10 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Pixel configuration for the current buffer format. | 16 // Pixel configuration for the current buffer format. |
17 // TODO(dnicoara) These will need to change once we query the hardware for | 17 // TODO(dnicoara) These will need to change once we query the hardware for |
18 // supported configurations. | 18 // supported configurations. |
19 const uint8_t kColorDepth = 24; | 19 const uint8_t kColorDepth = 24; |
20 const uint8_t kPixelDepth = 32; | 20 const uint8_t kPixelDepth = 32; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 GbmBufferBase::GbmBufferBase(const scoped_refptr<DrmDevice>& drm, | 24 GbmBufferBase::GbmBufferBase(const scoped_refptr<DrmDevice>& drm, |
25 gbm_bo* bo, | 25 gbm_bo* bo, |
26 bool scanout) | 26 bool scanout) |
27 : drm_(drm), bo_(bo) { | 27 : drm_(drm), bo_(bo) { |
28 if (scanout) { | 28 if (scanout) { |
29 if (!drm_->AddFramebuffer(gbm_bo_get_width(bo), gbm_bo_get_height(bo), | |
30 kColorDepth, kPixelDepth, gbm_bo_get_stride(bo), | |
31 gbm_bo_get_handle(bo).u32, &framebuffer_)) { | |
32 PLOG(ERROR) << "Failed to register buffer"; | |
33 return; | |
34 } | |
35 | |
36 fb_pixel_format_ = gbm_bo_get_format(bo); | 29 fb_pixel_format_ = gbm_bo_get_format(bo); |
37 if (fb_pixel_format_ == GBM_FORMAT_ARGB8888) | 30 if (fb_pixel_format_ == GBM_FORMAT_ARGB8888) |
38 fb_pixel_format_ = GBM_FORMAT_XRGB8888; | 31 fb_pixel_format_ = GBM_FORMAT_XRGB8888; |
39 | 32 |
40 // For now, we always create a frame buffer of 24 bit color depth and | 33 switch (fb_pixel_format_) { |
41 // support only XRGB format. | 34 case GBM_FORMAT_XRGB8888: |
42 DCHECK(fb_pixel_format_ == GBM_FORMAT_XRGB8888); | 35 if (!drm_->AddFramebuffer(gbm_bo_get_width(bo), gbm_bo_get_height(bo), |
kalyank
2015/10/22 22:22:28
As @marcheu1 pointed out we should just use AddFra
william.xie1
2015/10/23 00:23:32
Done.
| |
36 kColorDepth, kPixelDepth, | |
37 gbm_bo_get_stride(bo), | |
38 gbm_bo_get_handle(bo).u32, &framebuffer_)) { | |
39 PLOG(ERROR) << "Failed to register buffer"; | |
40 return; | |
41 } | |
42 break; | |
43 case GBM_FORMAT_UYVY: | |
44 uint32_t handles[4] = {0}; | |
45 handles[0] = gbm_bo_get_handle(bo).u32; | |
46 uint32_t strides[4] = {0}; | |
47 strides[0] = gbm_bo_get_stride(bo); | |
48 uint32_t offsets[4] = {0}; | |
49 | |
50 if (!drm_->AddFramebuffer2(gbm_bo_get_width(bo), gbm_bo_get_height(bo), | |
51 fb_pixel_format_, handles, strides, offsets, | |
52 &framebuffer_, 0)) { | |
53 PLOG(ERROR) << "Failed to register buffer"; | |
54 return; | |
55 } | |
56 break; | |
57 default: | |
58 NOTIMPLEMENTED(); | |
59 } | |
43 } | 60 } |
44 } | 61 } |
45 | 62 |
46 GbmBufferBase::~GbmBufferBase() { | 63 GbmBufferBase::~GbmBufferBase() { |
47 if (framebuffer_) | 64 if (framebuffer_) |
48 drm_->RemoveFramebuffer(framebuffer_); | 65 drm_->RemoveFramebuffer(framebuffer_); |
49 } | 66 } |
50 | 67 |
51 uint32_t GbmBufferBase::GetFramebufferId() const { | 68 uint32_t GbmBufferBase::GetFramebufferId() const { |
52 return framebuffer_; | 69 return framebuffer_; |
53 } | 70 } |
54 | 71 |
55 uint32_t GbmBufferBase::GetHandle() const { | 72 uint32_t GbmBufferBase::GetHandle() const { |
56 return gbm_bo_get_handle(bo_).u32; | 73 return gbm_bo_get_handle(bo_).u32; |
57 } | 74 } |
58 | 75 |
59 gfx::Size GbmBufferBase::GetSize() const { | 76 gfx::Size GbmBufferBase::GetSize() const { |
60 return gfx::Size(gbm_bo_get_width(bo_), gbm_bo_get_height(bo_)); | 77 return gfx::Size(gbm_bo_get_width(bo_), gbm_bo_get_height(bo_)); |
61 } | 78 } |
62 | 79 |
63 uint32_t GbmBufferBase::GetFramebufferPixelFormat() const { | 80 uint32_t GbmBufferBase::GetFramebufferPixelFormat() const { |
64 return fb_pixel_format_; | 81 return fb_pixel_format_; |
65 } | 82 } |
66 | 83 |
67 bool GbmBufferBase::RequiresGlFinish() const { | 84 bool GbmBufferBase::RequiresGlFinish() const { |
68 return !drm_->is_primary_device(); | 85 return !drm_->is_primary_device(); |
69 } | 86 } |
70 | 87 |
71 } // namespace ui | 88 } // namespace ui |
OLD | NEW |