OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/wayland/server.h" | 5 #include "components/exo/wayland/server.h" |
6 | 6 |
7 #include <wayland-server-core.h> | 7 #include <wayland-server-core.h> |
8 #include <wayland-server-protocol-core.h> | 8 #include <wayland-server-protocol-core.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "components/exo/buffer.h" | 15 #include "components/exo/buffer.h" |
16 #include "components/exo/display.h" | 16 #include "components/exo/display.h" |
17 #include "components/exo/shared_memory.h" | 17 #include "components/exo/shared_memory.h" |
18 #include "components/exo/shell_surface.h" | 18 #include "components/exo/shell_surface.h" |
19 #include "components/exo/sub_surface.h" | 19 #include "components/exo/sub_surface.h" |
20 #include "components/exo/surface.h" | 20 #include "components/exo/surface.h" |
21 #include "third_party/skia/include/core/SkRegion.h" | 21 #include "third_party/skia/include/core/SkRegion.h" |
22 | 22 |
23 #if defined(USE_OZONE) | |
24 #include <wayland-drm-server-protocol.h> | |
25 #endif | |
26 | |
23 namespace exo { | 27 namespace exo { |
24 namespace wayland { | 28 namespace wayland { |
25 namespace { | 29 namespace { |
26 | 30 |
27 template <class T> | 31 template <class T> |
28 T* GetUserDataAs(wl_resource* resource) { | 32 T* GetUserDataAs(wl_resource* resource) { |
29 return static_cast<T*>(wl_resource_get_user_data(resource)); | 33 return static_cast<T*>(wl_resource_get_user_data(resource)); |
30 } | 34 } |
31 | 35 |
32 template <class T> | 36 template <class T> |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 return; | 362 return; |
359 } | 363 } |
360 | 364 |
361 wl_resource_set_implementation(resource, &shm_implementation, data, nullptr); | 365 wl_resource_set_implementation(resource, &shm_implementation, data, nullptr); |
362 | 366 |
363 for (const auto& supported_format : shm_supported_formats) | 367 for (const auto& supported_format : shm_supported_formats) |
364 wl_shm_send_format(resource, supported_format.shm_format); | 368 wl_shm_send_format(resource, supported_format.shm_format); |
365 } | 369 } |
366 | 370 |
367 //////////////////////////////////////////////////////////////////////////////// | 371 //////////////////////////////////////////////////////////////////////////////// |
372 // wl_drm_interface: | |
373 | |
374 #if defined(USE_OZONE) | |
375 const struct drm_supported_format { | |
376 uint32_t drm_format; | |
377 gfx::BufferFormat buffer_format; | |
378 } drm_supported_formats[] = { | |
379 {WL_DRM_FORMAT_XBGR8888, gfx::BufferFormat::RGBX_8888}, | |
380 {WL_DRM_FORMAT_ABGR8888, gfx::BufferFormat::RGBA_8888}, | |
381 {WL_DRM_FORMAT_XRGB8888, gfx::BufferFormat::BGRX_8888}, | |
382 {WL_DRM_FORMAT_ARGB8888, gfx::BufferFormat::BGRA_8888}}; | |
383 | |
384 void drm_authenticate(wl_client* client, wl_resource* resource, uint32_t id) { | |
385 wl_drm_send_authenticated(resource); | |
386 } | |
387 | |
388 void drm_create_buffer(wl_client* client, | |
389 wl_resource* resource, | |
390 uint32_t id, | |
391 uint32_t name, | |
392 int32_t width, | |
393 int32_t height, | |
394 uint32_t stride, | |
395 uint32_t format) { | |
396 wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_NAME, | |
397 "GEM names are not supported"); | |
398 } | |
399 | |
400 void drm_create_planar_buffer(wl_client* client, | |
401 wl_resource* resource, | |
402 uint32_t id, | |
403 uint32_t name, | |
404 int32_t width, | |
405 int32_t height, | |
406 uint32_t format, | |
407 int32_t offset0, | |
408 int32_t stride0, | |
409 int32_t offset1, | |
410 int32_t stride1, | |
411 int32_t offset2, | |
412 int32_t stride3) { | |
413 wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_NAME, | |
414 "GEM names are not supported"); | |
415 } | |
416 | |
417 void drm_create_prime_buffer(wl_client* client, | |
418 wl_resource* resource, | |
419 uint32_t id, | |
420 int32_t name, | |
421 int32_t width, | |
422 int32_t height, | |
423 uint32_t format, | |
424 int32_t offset0, | |
425 int32_t stride0, | |
426 int32_t offset1, | |
427 int32_t stride1, | |
428 int32_t offset2, | |
429 int32_t stride2) { | |
430 const auto supported_format = | |
piman
2015/11/20 19:40:34
nit: const auto*
reveman
2015/11/20 20:53:52
Done.
| |
431 std::find_if(drm_supported_formats, | |
432 drm_supported_formats + arraysize(drm_supported_formats), | |
433 [format](const drm_supported_format& supported_format) { | |
434 return supported_format.drm_format == format; | |
435 }); | |
436 if (supported_format == | |
437 (drm_supported_formats + arraysize(drm_supported_formats))) { | |
438 wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT, | |
439 "invalid format 0x%x", format); | |
440 return; | |
441 } | |
442 | |
443 scoped_ptr<Buffer> buffer = | |
444 GetUserDataAs<Display>(resource) | |
445 ->CreatePrimeBuffer(base::ScopedFD(name), gfx::Size(width, height), | |
446 supported_format->buffer_format, stride0); | |
447 if (!buffer) { | |
448 wl_resource_post_no_memory(resource); | |
449 return; | |
450 } | |
451 | |
452 wl_resource* buffer_resource = | |
453 wl_resource_create(client, &wl_buffer_interface, 1, id); | |
454 if (!buffer_resource) { | |
455 wl_resource_post_no_memory(resource); | |
456 return; | |
457 } | |
458 | |
459 buffer->set_release_callback( | |
460 base::Bind(&wl_buffer_send_release, base::Unretained(buffer_resource))); | |
461 | |
462 SetImplementation(buffer_resource, &buffer_implementation, buffer.Pass()); | |
463 } | |
464 | |
465 const struct wl_drm_interface drm_implementation = { | |
466 drm_authenticate, drm_create_buffer, drm_create_planar_buffer, | |
467 drm_create_prime_buffer}; | |
468 | |
469 const uint32_t drm_version = 2; | |
470 | |
471 void bind_drm(wl_client* client, void* data, uint32_t version, uint32_t id) { | |
472 wl_resource* resource = wl_resource_create( | |
473 client, &wl_drm_interface, std::min(version, drm_version), id); | |
474 if (!resource) { | |
475 wl_client_post_no_memory(client); | |
476 return; | |
477 } | |
478 wl_resource_set_implementation(resource, &drm_implementation, data, nullptr); | |
479 | |
480 if (version >= 2) | |
481 wl_drm_send_capabilities(resource, WL_DRM_CAPABILITY_PRIME); | |
482 | |
483 for (const auto& supported_format : drm_supported_formats) | |
484 wl_drm_send_format(resource, supported_format.drm_format); | |
485 } | |
486 #endif | |
487 | |
488 //////////////////////////////////////////////////////////////////////////////// | |
368 // wl_subsurface_interface: | 489 // wl_subsurface_interface: |
369 | 490 |
370 void subsurface_destroy(wl_client* client, wl_resource* resource) { | 491 void subsurface_destroy(wl_client* client, wl_resource* resource) { |
371 wl_resource_destroy(resource); | 492 wl_resource_destroy(resource); |
372 } | 493 } |
373 | 494 |
374 void subsurface_set_position(wl_client* client, | 495 void subsurface_set_position(wl_client* client, |
375 wl_resource* resource, | 496 wl_resource* resource, |
376 int32_t x, | 497 int32_t x, |
377 int32_t y) { | 498 int32_t y) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 } // namespace | 698 } // namespace |
578 | 699 |
579 //////////////////////////////////////////////////////////////////////////////// | 700 //////////////////////////////////////////////////////////////////////////////// |
580 // Server, public: | 701 // Server, public: |
581 | 702 |
582 Server::Server(Display* display) | 703 Server::Server(Display* display) |
583 : display_(display), wl_display_(wl_display_create()) { | 704 : display_(display), wl_display_(wl_display_create()) { |
584 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 705 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
585 compositor_version, display_, bind_compositor); | 706 compositor_version, display_, bind_compositor); |
586 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 707 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
708 #if defined(USE_OZONE) | |
709 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_, | |
710 bind_drm); | |
711 #endif | |
587 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, | 712 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, |
588 bind_subcompositor); | 713 bind_subcompositor); |
589 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, | 714 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, |
590 bind_shell); | 715 bind_shell); |
591 } | 716 } |
592 | 717 |
593 Server::~Server() {} | 718 Server::~Server() {} |
594 | 719 |
595 // static | 720 // static |
596 scoped_ptr<Server> Server::Create(Display* display) { | 721 scoped_ptr<Server> Server::Create(Display* display) { |
(...skipping 19 matching lines...) Expand all Loading... | |
616 DCHECK(event_loop); | 741 DCHECK(event_loop); |
617 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 742 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
618 } | 743 } |
619 | 744 |
620 void Server::Flush() { | 745 void Server::Flush() { |
621 wl_display_flush_clients(wl_display_.get()); | 746 wl_display_flush_clients(wl_display_.get()); |
622 } | 747 } |
623 | 748 |
624 } // namespace wayland | 749 } // namespace wayland |
625 } // namespace exo | 750 } // namespace exo |
OLD | NEW |