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.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" |
6 | 6 |
7 #include <drm.h> | 7 #include <drm.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <gbm.h> | 9 #include <gbm.h> |
10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "ui/gfx/geometry/size_conversions.h" | 14 #include "ui/gfx/geometry/size_conversions.h" |
15 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 15 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
16 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 16 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
17 | 17 |
18 namespace ui { | 18 namespace ui { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) { | 22 int GetGbmFormatFromPixmapFormat(PixmapFormat fmt) { |
23 switch (fmt) { | 23 switch (fmt) { |
24 case SurfaceFactoryOzone::BGRA_8888: | 24 case PIXMAP_FORMAT_BGRA_8888: |
25 return GBM_BO_FORMAT_ARGB8888; | 25 return GBM_BO_FORMAT_ARGB8888; |
26 case SurfaceFactoryOzone::RGBX_8888: | 26 case PIXMAP_FORMAT_RGBX_8888: |
27 return GBM_BO_FORMAT_XRGB8888; | 27 return GBM_BO_FORMAT_XRGB8888; |
28 default: | 28 default: |
29 NOTREACHED(); | 29 NOTREACHED(); |
30 return 0; | 30 return 0; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 } // namespace | 34 } // namespace |
35 | 35 |
36 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 36 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
37 gbm_bo* bo, | 37 gbm_bo* bo, |
38 bool scanout) | 38 bool scanout) |
39 : GbmBufferBase(gbm, bo, scanout) { | 39 : GbmBufferBase(gbm, bo, scanout) { |
40 } | 40 } |
41 | 41 |
42 GbmBuffer::~GbmBuffer() { | 42 GbmBuffer::~GbmBuffer() { |
43 if (bo()) | 43 if (bo()) |
44 gbm_bo_destroy(bo()); | 44 gbm_bo_destroy(bo()); |
45 } | 45 } |
46 | 46 |
47 // static | 47 // static |
48 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( | 48 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( |
49 const scoped_refptr<GbmDevice>& gbm, | 49 const scoped_refptr<GbmDevice>& gbm, |
50 SurfaceFactoryOzone::BufferFormat format, | 50 PixmapFormat format, |
51 const gfx::Size& size, | 51 const gfx::Size& size, |
52 bool scanout) { | 52 bool scanout) { |
53 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", | 53 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", |
54 gbm->device_path().value(), "size", size.ToString()); | 54 gbm->device_path().value(), "size", size.ToString()); |
55 unsigned flags = GBM_BO_USE_RENDERING; | 55 unsigned flags = GBM_BO_USE_RENDERING; |
56 if (scanout) | 56 if (scanout) |
57 flags |= GBM_BO_USE_SCANOUT; | 57 flags |= GBM_BO_USE_SCANOUT; |
58 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), | 58 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), |
59 GetGbmFormatFromBufferFormat(format), flags); | 59 GetGbmFormatFromPixmapFormat(format), flags); |
60 if (!bo) | 60 if (!bo) |
61 return NULL; | 61 return NULL; |
62 | 62 |
63 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, scanout)); | 63 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, scanout)); |
64 if (scanout && !buffer->GetFramebufferId()) | 64 if (scanout && !buffer->GetFramebufferId()) |
65 return NULL; | 65 return NULL; |
66 | 66 |
67 return buffer; | 67 return buffer; |
68 } | 68 } |
69 | 69 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 gfx::Size pixmap_size = buffer_->GetSize(); | 142 gfx::Size pixmap_size = buffer_->GetSize(); |
143 // If the required size is not integer-sized, round it to the next integer. | 143 // If the required size is not integer-sized, round it to the next integer. |
144 *required_size = gfx::ToCeiledSize( | 144 *required_size = gfx::ToCeiledSize( |
145 gfx::SizeF(display_bounds.width() / crop_rect.width(), | 145 gfx::SizeF(display_bounds.width() / crop_rect.width(), |
146 display_bounds.height() / crop_rect.height())); | 146 display_bounds.height() / crop_rect.height())); |
147 return pixmap_size != *required_size; | 147 return pixmap_size != *required_size; |
148 } | 148 } |
149 | 149 |
150 } // namespace ui | 150 } // namespace ui |
OLD | NEW |