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/common/drm_util.h" | 5 #include "ui/ozone/platform/drm/common/drm_util.h" |
6 | 6 |
7 #include <drm_fourcc.h> | 7 #include <drm_fourcc.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
11 #include <xf86drm.h> | 11 #include <xf86drm.h> |
12 #include <xf86drmMode.h> | 12 #include <xf86drmMode.h> |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "base/containers/small_map.h" | 16 #include "base/containers/small_map.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "ui/display/util/edid_parser.h" | 18 #include "ui/display/util/edid_parser.h" |
19 | 19 |
20 #if !defined(DRM_FORMAT_YV12) | |
21 // TODO(dcastagna): after libdrm has this definition, remove it. | |
22 #define DRM_FORMAT_YV12 fourcc_code('Y', 'V', '1', '2') | |
23 #endif | |
24 | |
25 namespace ui { | 20 namespace ui { |
26 | 21 |
27 namespace { | 22 namespace { |
28 | 23 |
29 static const size_t kDefaultCursorWidth = 64; | 24 static const size_t kDefaultCursorWidth = 64; |
30 static const size_t kDefaultCursorHeight = 64; | 25 static const size_t kDefaultCursorHeight = 64; |
31 | 26 |
32 bool IsCrtcInUse( | 27 bool IsCrtcInUse( |
33 uint32_t crtc, | 28 uint32_t crtc, |
34 const std::vector<std::unique_ptr<HardwareDisplayControllerInfo>>& | 29 const std::vector<std::unique_ptr<HardwareDisplayControllerInfo>>& |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 return DRM_FORMAT_XBGR8888; | 372 return DRM_FORMAT_XBGR8888; |
378 case gfx::BufferFormat::BGRA_8888: | 373 case gfx::BufferFormat::BGRA_8888: |
379 return DRM_FORMAT_ARGB8888; | 374 return DRM_FORMAT_ARGB8888; |
380 case gfx::BufferFormat::BGRX_8888: | 375 case gfx::BufferFormat::BGRX_8888: |
381 return DRM_FORMAT_XRGB8888; | 376 return DRM_FORMAT_XRGB8888; |
382 case gfx::BufferFormat::BGR_565: | 377 case gfx::BufferFormat::BGR_565: |
383 return DRM_FORMAT_RGB565; | 378 return DRM_FORMAT_RGB565; |
384 case gfx::BufferFormat::UYVY_422: | 379 case gfx::BufferFormat::UYVY_422: |
385 return DRM_FORMAT_UYVY; | 380 return DRM_FORMAT_UYVY; |
386 case gfx::BufferFormat::YVU_420: | 381 case gfx::BufferFormat::YVU_420: |
387 return DRM_FORMAT_YV12; | 382 return DRM_FORMAT_YVU420; |
388 case gfx::BufferFormat::YUV_420_BIPLANAR: | 383 case gfx::BufferFormat::YUV_420_BIPLANAR: |
389 return DRM_FORMAT_NV12; | 384 return DRM_FORMAT_NV12; |
390 default: | 385 default: |
391 NOTREACHED(); | 386 NOTREACHED(); |
392 return 0; | 387 return 0; |
393 } | 388 } |
394 } | 389 } |
395 | 390 |
396 gfx::BufferFormat GetBufferFormatFromFourCCFormat(int format) { | 391 gfx::BufferFormat GetBufferFormatFromFourCCFormat(int format) { |
397 switch (format) { | 392 switch (format) { |
398 case DRM_FORMAT_R8: | 393 case DRM_FORMAT_R8: |
399 return gfx::BufferFormat::R_8; | 394 return gfx::BufferFormat::R_8; |
400 case DRM_FORMAT_GR88: | 395 case DRM_FORMAT_GR88: |
401 return gfx::BufferFormat::RG_88; | 396 return gfx::BufferFormat::RG_88; |
402 case DRM_FORMAT_ABGR8888: | 397 case DRM_FORMAT_ABGR8888: |
403 return gfx::BufferFormat::RGBA_8888; | 398 return gfx::BufferFormat::RGBA_8888; |
404 case DRM_FORMAT_XBGR8888: | 399 case DRM_FORMAT_XBGR8888: |
405 return gfx::BufferFormat::RGBX_8888; | 400 return gfx::BufferFormat::RGBX_8888; |
406 case DRM_FORMAT_ARGB8888: | 401 case DRM_FORMAT_ARGB8888: |
407 return gfx::BufferFormat::BGRA_8888; | 402 return gfx::BufferFormat::BGRA_8888; |
408 case DRM_FORMAT_XRGB8888: | 403 case DRM_FORMAT_XRGB8888: |
409 return gfx::BufferFormat::BGRX_8888; | 404 return gfx::BufferFormat::BGRX_8888; |
410 case DRM_FORMAT_RGB565: | 405 case DRM_FORMAT_RGB565: |
411 return gfx::BufferFormat::BGR_565; | 406 return gfx::BufferFormat::BGR_565; |
412 case DRM_FORMAT_UYVY: | 407 case DRM_FORMAT_UYVY: |
413 return gfx::BufferFormat::UYVY_422; | 408 return gfx::BufferFormat::UYVY_422; |
414 case DRM_FORMAT_NV12: | 409 case DRM_FORMAT_NV12: |
415 return gfx::BufferFormat::YUV_420_BIPLANAR; | 410 return gfx::BufferFormat::YUV_420_BIPLANAR; |
416 case DRM_FORMAT_YV12: | 411 case DRM_FORMAT_YVU420: |
417 return gfx::BufferFormat::YVU_420; | 412 return gfx::BufferFormat::YVU_420; |
418 default: | 413 default: |
419 NOTREACHED(); | 414 NOTREACHED(); |
420 return gfx::BufferFormat::BGRA_8888; | 415 return gfx::BufferFormat::BGRA_8888; |
421 } | 416 } |
422 } | 417 } |
423 | 418 |
424 int GetFourCCFormatForOpaqueFramebuffer(gfx::BufferFormat format) { | 419 int GetFourCCFormatForOpaqueFramebuffer(gfx::BufferFormat format) { |
425 // DRM atomic interface doesn't currently support specifying an alpha | 420 // DRM atomic interface doesn't currently support specifying an alpha |
426 // blending. We can simulate disabling alpha bleding creating an fb | 421 // blending. We can simulate disabling alpha bleding creating an fb |
427 // with a format without the alpha channel. | 422 // with a format without the alpha channel. |
428 switch (format) { | 423 switch (format) { |
429 case gfx::BufferFormat::RGBA_8888: | 424 case gfx::BufferFormat::RGBA_8888: |
430 case gfx::BufferFormat::RGBX_8888: | 425 case gfx::BufferFormat::RGBX_8888: |
431 return DRM_FORMAT_XBGR8888; | 426 return DRM_FORMAT_XBGR8888; |
432 case gfx::BufferFormat::BGRA_8888: | 427 case gfx::BufferFormat::BGRA_8888: |
433 case gfx::BufferFormat::BGRX_8888: | 428 case gfx::BufferFormat::BGRX_8888: |
434 return DRM_FORMAT_XRGB8888; | 429 return DRM_FORMAT_XRGB8888; |
435 case gfx::BufferFormat::BGR_565: | 430 case gfx::BufferFormat::BGR_565: |
436 return DRM_FORMAT_RGB565; | 431 return DRM_FORMAT_RGB565; |
437 case gfx::BufferFormat::UYVY_422: | 432 case gfx::BufferFormat::UYVY_422: |
438 return DRM_FORMAT_UYVY; | 433 return DRM_FORMAT_UYVY; |
439 default: | 434 default: |
440 NOTREACHED(); | 435 NOTREACHED(); |
441 return 0; | 436 return 0; |
442 } | 437 } |
443 } | 438 } |
444 } // namespace ui | 439 } // namespace ui |
OLD | NEW |