| 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 <linux/input.h> | 7 #include <linux/input.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <wayland-server-core.h> | 10 #include <wayland-server-core.h> |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void surface_destroy(wl_client* client, wl_resource* resource) { | 100 void surface_destroy(wl_client* client, wl_resource* resource) { |
| 101 wl_resource_destroy(resource); | 101 wl_resource_destroy(resource); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void surface_attach(wl_client* client, | 104 void surface_attach(wl_client* client, |
| 105 wl_resource* resource, | 105 wl_resource* resource, |
| 106 wl_resource* buffer, | 106 wl_resource* buffer, |
| 107 int32_t x, | 107 int32_t x, |
| 108 int32_t y) { | 108 int32_t y) { |
| 109 // TODO(reveman): Implement buffer offset support. | 109 // TODO(reveman): Implement buffer offset support. |
| 110 if (x || y) { | 110 DLOG_IF(WARNING, x || y) << "Unsupported buffer offset: " |
| 111 wl_resource_post_no_memory(resource); | 111 << gfx::Point(x, y).ToString(); |
| 112 return; | |
| 113 } | |
| 114 | 112 |
| 115 GetUserDataAs<Surface>(resource) | 113 GetUserDataAs<Surface>(resource) |
| 116 ->Attach(buffer ? GetUserDataAs<Buffer>(buffer) : nullptr); | 114 ->Attach(buffer ? GetUserDataAs<Buffer>(buffer) : nullptr); |
| 117 } | 115 } |
| 118 | 116 |
| 119 void surface_damage(wl_client* client, | 117 void surface_damage(wl_client* client, |
| 120 wl_resource* resource, | 118 wl_resource* resource, |
| 121 int32_t x, | 119 int32_t x, |
| 122 int32_t y, | 120 int32_t y, |
| 123 int32_t width, | 121 int32_t width, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 135 wl_client_flush(wl_resource_get_client(resource)); | 133 wl_client_flush(wl_resource_get_client(resource)); |
| 136 } | 134 } |
| 137 wl_resource_destroy(resource); | 135 wl_resource_destroy(resource); |
| 138 } | 136 } |
| 139 | 137 |
| 140 void surface_frame(wl_client* client, | 138 void surface_frame(wl_client* client, |
| 141 wl_resource* resource, | 139 wl_resource* resource, |
| 142 uint32_t callback) { | 140 uint32_t callback) { |
| 143 wl_resource* callback_resource = | 141 wl_resource* callback_resource = |
| 144 wl_resource_create(client, &wl_callback_interface, 1, callback); | 142 wl_resource_create(client, &wl_callback_interface, 1, callback); |
| 145 if (!callback_resource) { | |
| 146 wl_resource_post_no_memory(resource); | |
| 147 return; | |
| 148 } | |
| 149 | 143 |
| 150 // base::Unretained is safe as the resource owns the callback. | 144 // base::Unretained is safe as the resource owns the callback. |
| 151 scoped_ptr<base::CancelableCallback<void(base::TimeTicks)>> | 145 scoped_ptr<base::CancelableCallback<void(base::TimeTicks)>> |
| 152 cancelable_callback( | 146 cancelable_callback( |
| 153 new base::CancelableCallback<void(base::TimeTicks)>(base::Bind( | 147 new base::CancelableCallback<void(base::TimeTicks)>(base::Bind( |
| 154 &HandleSurfaceFrameCallback, base::Unretained(callback_resource)))); | 148 &HandleSurfaceFrameCallback, base::Unretained(callback_resource)))); |
| 155 | 149 |
| 156 GetUserDataAs<Surface>(resource) | 150 GetUserDataAs<Surface>(resource) |
| 157 ->RequestFrameCallback(cancelable_callback->callback()); | 151 ->RequestFrameCallback(cancelable_callback->callback()); |
| 158 | 152 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 region_destroy, region_add, region_subtract}; | 235 region_destroy, region_add, region_subtract}; |
| 242 | 236 |
| 243 //////////////////////////////////////////////////////////////////////////////// | 237 //////////////////////////////////////////////////////////////////////////////// |
| 244 // wl_compositor_interface: | 238 // wl_compositor_interface: |
| 245 | 239 |
| 246 void compositor_create_surface(wl_client* client, | 240 void compositor_create_surface(wl_client* client, |
| 247 wl_resource* resource, | 241 wl_resource* resource, |
| 248 uint32_t id) { | 242 uint32_t id) { |
| 249 scoped_ptr<Surface> surface = | 243 scoped_ptr<Surface> surface = |
| 250 GetUserDataAs<Display>(resource)->CreateSurface(); | 244 GetUserDataAs<Display>(resource)->CreateSurface(); |
| 251 DCHECK(surface); | |
| 252 | 245 |
| 253 wl_resource* surface_resource = wl_resource_create( | 246 wl_resource* surface_resource = wl_resource_create( |
| 254 client, &wl_surface_interface, wl_resource_get_version(resource), id); | 247 client, &wl_surface_interface, wl_resource_get_version(resource), id); |
| 255 if (!surface_resource) { | |
| 256 wl_resource_post_no_memory(resource); | |
| 257 return; | |
| 258 } | |
| 259 | 248 |
| 260 // Set the surface resource property for type-checking downcast support. | 249 // Set the surface resource property for type-checking downcast support. |
| 261 surface->SetProperty(kSurfaceResourceKey, surface_resource); | 250 surface->SetProperty(kSurfaceResourceKey, surface_resource); |
| 262 | 251 |
| 263 SetImplementation(surface_resource, &surface_implementation, | 252 SetImplementation(surface_resource, &surface_implementation, |
| 264 std::move(surface)); | 253 std::move(surface)); |
| 265 } | 254 } |
| 266 | 255 |
| 267 void compositor_create_region(wl_client* client, | 256 void compositor_create_region(wl_client* client, |
| 268 wl_resource* resource, | 257 wl_resource* resource, |
| 269 uint32_t id) { | 258 uint32_t id) { |
| 270 scoped_ptr<SkRegion> region(new SkRegion); | |
| 271 | |
| 272 wl_resource* region_resource = | 259 wl_resource* region_resource = |
| 273 wl_resource_create(client, &wl_region_interface, 1, id); | 260 wl_resource_create(client, &wl_region_interface, 1, id); |
| 274 if (!region_resource) { | |
| 275 wl_resource_post_no_memory(resource); | |
| 276 return; | |
| 277 } | |
| 278 | 261 |
| 279 SetImplementation(region_resource, ®ion_implementation, std::move(region)); | 262 SetImplementation(region_resource, ®ion_implementation, |
| 263 make_scoped_ptr(new SkRegion)); |
| 280 } | 264 } |
| 281 | 265 |
| 282 const struct wl_compositor_interface compositor_implementation = { | 266 const struct wl_compositor_interface compositor_implementation = { |
| 283 compositor_create_surface, compositor_create_region}; | 267 compositor_create_surface, compositor_create_region}; |
| 284 | 268 |
| 285 const uint32_t compositor_version = 3; | 269 const uint32_t compositor_version = 3; |
| 286 | 270 |
| 287 void bind_compositor(wl_client* client, | 271 void bind_compositor(wl_client* client, |
| 288 void* data, | 272 void* data, |
| 289 uint32_t version, | 273 uint32_t version, |
| 290 uint32_t id) { | 274 uint32_t id) { |
| 291 wl_resource* resource = | 275 wl_resource* resource = |
| 292 wl_resource_create(client, &wl_compositor_interface, | 276 wl_resource_create(client, &wl_compositor_interface, |
| 293 std::min(version, compositor_version), id); | 277 std::min(version, compositor_version), id); |
| 294 if (!resource) { | |
| 295 wl_client_post_no_memory(client); | |
| 296 return; | |
| 297 } | |
| 298 | 278 |
| 299 wl_resource_set_implementation(resource, &compositor_implementation, data, | 279 wl_resource_set_implementation(resource, &compositor_implementation, data, |
| 300 nullptr); | 280 nullptr); |
| 301 } | 281 } |
| 302 | 282 |
| 303 //////////////////////////////////////////////////////////////////////////////// | 283 //////////////////////////////////////////////////////////////////////////////// |
| 304 // wl_shm_pool_interface: | 284 // wl_shm_pool_interface: |
| 305 | 285 |
| 306 const struct shm_supported_format { | 286 const struct shm_supported_format { |
| 307 uint32_t shm_format; | 287 uint32_t shm_format; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 GetUserDataAs<SharedMemory>(resource) | 323 GetUserDataAs<SharedMemory>(resource) |
| 344 ->CreateBuffer(gfx::Size(width, height), | 324 ->CreateBuffer(gfx::Size(width, height), |
| 345 supported_format->buffer_format, offset, stride); | 325 supported_format->buffer_format, offset, stride); |
| 346 if (!buffer) { | 326 if (!buffer) { |
| 347 wl_resource_post_no_memory(resource); | 327 wl_resource_post_no_memory(resource); |
| 348 return; | 328 return; |
| 349 } | 329 } |
| 350 | 330 |
| 351 wl_resource* buffer_resource = | 331 wl_resource* buffer_resource = |
| 352 wl_resource_create(client, &wl_buffer_interface, 1, id); | 332 wl_resource_create(client, &wl_buffer_interface, 1, id); |
| 353 if (!buffer_resource) { | |
| 354 wl_resource_post_no_memory(resource); | |
| 355 return; | |
| 356 } | |
| 357 | 333 |
| 358 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, | 334 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, |
| 359 base::Unretained(buffer_resource))); | 335 base::Unretained(buffer_resource))); |
| 360 | 336 |
| 361 SetImplementation(buffer_resource, &buffer_implementation, std::move(buffer)); | 337 SetImplementation(buffer_resource, &buffer_implementation, std::move(buffer)); |
| 362 } | 338 } |
| 363 | 339 |
| 364 void shm_pool_destroy(wl_client* client, wl_resource* resource) { | 340 void shm_pool_destroy(wl_client* client, wl_resource* resource) { |
| 365 wl_resource_destroy(resource); | 341 wl_resource_destroy(resource); |
| 366 } | 342 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 383 scoped_ptr<SharedMemory> shared_memory = | 359 scoped_ptr<SharedMemory> shared_memory = |
| 384 GetUserDataAs<Display>(resource) | 360 GetUserDataAs<Display>(resource) |
| 385 ->CreateSharedMemory(base::FileDescriptor(fd, true), size); | 361 ->CreateSharedMemory(base::FileDescriptor(fd, true), size); |
| 386 if (!shared_memory) { | 362 if (!shared_memory) { |
| 387 wl_resource_post_no_memory(resource); | 363 wl_resource_post_no_memory(resource); |
| 388 return; | 364 return; |
| 389 } | 365 } |
| 390 | 366 |
| 391 wl_resource* shm_pool_resource = | 367 wl_resource* shm_pool_resource = |
| 392 wl_resource_create(client, &wl_shm_pool_interface, 1, id); | 368 wl_resource_create(client, &wl_shm_pool_interface, 1, id); |
| 393 if (!shm_pool_resource) { | |
| 394 wl_resource_post_no_memory(resource); | |
| 395 return; | |
| 396 } | |
| 397 | 369 |
| 398 SetImplementation(shm_pool_resource, &shm_pool_implementation, | 370 SetImplementation(shm_pool_resource, &shm_pool_implementation, |
| 399 std::move(shared_memory)); | 371 std::move(shared_memory)); |
| 400 } | 372 } |
| 401 | 373 |
| 402 const struct wl_shm_interface shm_implementation = {shm_create_pool}; | 374 const struct wl_shm_interface shm_implementation = {shm_create_pool}; |
| 403 | 375 |
| 404 void bind_shm(wl_client* client, void* data, uint32_t version, uint32_t id) { | 376 void bind_shm(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 405 wl_resource* resource = wl_resource_create(client, &wl_shm_interface, 1, id); | 377 wl_resource* resource = wl_resource_create(client, &wl_shm_interface, 1, id); |
| 406 if (!resource) { | |
| 407 wl_client_post_no_memory(client); | |
| 408 return; | |
| 409 } | |
| 410 | 378 |
| 411 wl_resource_set_implementation(resource, &shm_implementation, data, nullptr); | 379 wl_resource_set_implementation(resource, &shm_implementation, data, nullptr); |
| 412 | 380 |
| 413 for (const auto& supported_format : shm_supported_formats) | 381 for (const auto& supported_format : shm_supported_formats) |
| 414 wl_shm_send_format(resource, supported_format.shm_format); | 382 wl_shm_send_format(resource, supported_format.shm_format); |
| 415 } | 383 } |
| 416 | 384 |
| 417 #if defined(USE_OZONE) | 385 #if defined(USE_OZONE) |
| 418 | 386 |
| 419 //////////////////////////////////////////////////////////////////////////////// | 387 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 GetUserDataAs<Display>(resource) | 459 GetUserDataAs<Display>(resource) |
| 492 ->CreatePrimeBuffer(base::ScopedFD(name), gfx::Size(width, height), | 460 ->CreatePrimeBuffer(base::ScopedFD(name), gfx::Size(width, height), |
| 493 supported_format->buffer_format, stride0); | 461 supported_format->buffer_format, stride0); |
| 494 if (!buffer) { | 462 if (!buffer) { |
| 495 wl_resource_post_no_memory(resource); | 463 wl_resource_post_no_memory(resource); |
| 496 return; | 464 return; |
| 497 } | 465 } |
| 498 | 466 |
| 499 wl_resource* buffer_resource = | 467 wl_resource* buffer_resource = |
| 500 wl_resource_create(client, &wl_buffer_interface, 1, id); | 468 wl_resource_create(client, &wl_buffer_interface, 1, id); |
| 501 if (!buffer_resource) { | |
| 502 wl_resource_post_no_memory(resource); | |
| 503 return; | |
| 504 } | |
| 505 | 469 |
| 506 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, | 470 buffer->set_release_callback(base::Bind(&HandleBufferReleaseCallback, |
| 507 base::Unretained(buffer_resource))); | 471 base::Unretained(buffer_resource))); |
| 508 | 472 |
| 509 SetImplementation(buffer_resource, &buffer_implementation, std::move(buffer)); | 473 SetImplementation(buffer_resource, &buffer_implementation, std::move(buffer)); |
| 510 } | 474 } |
| 511 | 475 |
| 512 const struct wl_drm_interface drm_implementation = { | 476 const struct wl_drm_interface drm_implementation = { |
| 513 drm_authenticate, drm_create_buffer, drm_create_planar_buffer, | 477 drm_authenticate, drm_create_buffer, drm_create_planar_buffer, |
| 514 drm_create_prime_buffer}; | 478 drm_create_prime_buffer}; |
| 515 | 479 |
| 516 const uint32_t drm_version = 2; | 480 const uint32_t drm_version = 2; |
| 517 | 481 |
| 518 void bind_drm(wl_client* client, void* data, uint32_t version, uint32_t id) { | 482 void bind_drm(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 519 wl_resource* resource = wl_resource_create( | 483 wl_resource* resource = wl_resource_create( |
| 520 client, &wl_drm_interface, std::min(version, drm_version), id); | 484 client, &wl_drm_interface, std::min(version, drm_version), id); |
| 521 if (!resource) { | 485 |
| 522 wl_client_post_no_memory(client); | |
| 523 return; | |
| 524 } | |
| 525 wl_resource_set_implementation(resource, &drm_implementation, data, nullptr); | 486 wl_resource_set_implementation(resource, &drm_implementation, data, nullptr); |
| 526 | 487 |
| 527 if (version >= 2) | 488 if (version >= 2) |
| 528 wl_drm_send_capabilities(resource, WL_DRM_CAPABILITY_PRIME); | 489 wl_drm_send_capabilities(resource, WL_DRM_CAPABILITY_PRIME); |
| 529 | 490 |
| 530 for (const auto& supported_format : drm_supported_formats) | 491 for (const auto& supported_format : drm_supported_formats) |
| 531 wl_drm_send_format(resource, supported_format.drm_format); | 492 wl_drm_send_format(resource, supported_format.drm_format); |
| 532 } | 493 } |
| 533 #endif | 494 #endif |
| 534 | 495 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 542 |
| 582 void subcompositor_get_subsurface(wl_client* client, | 543 void subcompositor_get_subsurface(wl_client* client, |
| 583 wl_resource* resource, | 544 wl_resource* resource, |
| 584 uint32_t id, | 545 uint32_t id, |
| 585 wl_resource* surface, | 546 wl_resource* surface, |
| 586 wl_resource* parent) { | 547 wl_resource* parent) { |
| 587 scoped_ptr<SubSurface> subsurface = | 548 scoped_ptr<SubSurface> subsurface = |
| 588 GetUserDataAs<Display>(resource)->CreateSubSurface( | 549 GetUserDataAs<Display>(resource)->CreateSubSurface( |
| 589 GetUserDataAs<Surface>(surface), GetUserDataAs<Surface>(parent)); | 550 GetUserDataAs<Surface>(surface), GetUserDataAs<Surface>(parent)); |
| 590 if (!subsurface) { | 551 if (!subsurface) { |
| 591 wl_resource_post_no_memory(resource); | 552 wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 553 "invalid surface"); |
| 592 return; | 554 return; |
| 593 } | 555 } |
| 594 | 556 |
| 595 wl_resource* subsurface_resource = | 557 wl_resource* subsurface_resource = |
| 596 wl_resource_create(client, &wl_subsurface_interface, 1, id); | 558 wl_resource_create(client, &wl_subsurface_interface, 1, id); |
| 597 if (!subsurface_resource) { | |
| 598 wl_resource_post_no_memory(resource); | |
| 599 return; | |
| 600 } | |
| 601 | 559 |
| 602 SetImplementation(subsurface_resource, &subsurface_implementation, | 560 SetImplementation(subsurface_resource, &subsurface_implementation, |
| 603 std::move(subsurface)); | 561 std::move(subsurface)); |
| 604 } | 562 } |
| 605 | 563 |
| 606 const struct wl_subcompositor_interface subcompositor_implementation = { | 564 const struct wl_subcompositor_interface subcompositor_implementation = { |
| 607 subcompositor_destroy, subcompositor_get_subsurface}; | 565 subcompositor_destroy, subcompositor_get_subsurface}; |
| 608 | 566 |
| 609 void bind_subcompositor(wl_client* client, | 567 void bind_subcompositor(wl_client* client, |
| 610 void* data, | 568 void* data, |
| 611 uint32_t version, | 569 uint32_t version, |
| 612 uint32_t id) { | 570 uint32_t id) { |
| 613 wl_resource* resource = | 571 wl_resource* resource = |
| 614 wl_resource_create(client, &wl_subcompositor_interface, 1, id); | 572 wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
| 615 if (!resource) { | 573 |
| 616 wl_client_post_no_memory(client); | |
| 617 return; | |
| 618 } | |
| 619 wl_resource_set_implementation(resource, &subcompositor_implementation, data, | 574 wl_resource_set_implementation(resource, &subcompositor_implementation, data, |
| 620 nullptr); | 575 nullptr); |
| 621 } | 576 } |
| 622 | 577 |
| 623 //////////////////////////////////////////////////////////////////////////////// | 578 //////////////////////////////////////////////////////////////////////////////// |
| 624 // wl_shell_surface_interface: | 579 // wl_shell_surface_interface: |
| 625 | 580 |
| 626 void shell_surface_pong(wl_client* client, | 581 void shell_surface_pong(wl_client* client, |
| 627 wl_resource* resource, | 582 wl_resource* resource, |
| 628 uint32_t serial) { | 583 uint32_t serial) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 } | 672 } |
| 718 | 673 |
| 719 void shell_get_shell_surface(wl_client* client, | 674 void shell_get_shell_surface(wl_client* client, |
| 720 wl_resource* resource, | 675 wl_resource* resource, |
| 721 uint32_t id, | 676 uint32_t id, |
| 722 wl_resource* surface) { | 677 wl_resource* surface) { |
| 723 scoped_ptr<ShellSurface> shell_surface = | 678 scoped_ptr<ShellSurface> shell_surface = |
| 724 GetUserDataAs<Display>(resource) | 679 GetUserDataAs<Display>(resource) |
| 725 ->CreateShellSurface(GetUserDataAs<Surface>(surface)); | 680 ->CreateShellSurface(GetUserDataAs<Surface>(surface)); |
| 726 if (!shell_surface) { | 681 if (!shell_surface) { |
| 727 wl_resource_post_no_memory(resource); | 682 wl_resource_post_error(resource, WL_SHELL_ERROR_ROLE, |
| 683 "surface has already been assigned a role"); |
| 728 return; | 684 return; |
| 729 } | 685 } |
| 730 | 686 |
| 731 wl_resource* shell_surface_resource = | 687 wl_resource* shell_surface_resource = |
| 732 wl_resource_create(client, &wl_shell_surface_interface, 1, id); | 688 wl_resource_create(client, &wl_shell_surface_interface, 1, id); |
| 733 if (!shell_surface_resource) { | |
| 734 wl_resource_post_no_memory(resource); | |
| 735 return; | |
| 736 } | |
| 737 | 689 |
| 738 // Shell surfaces are initially disabled and needs to be explicitly mapped | 690 // Shell surfaces are initially disabled and needs to be explicitly mapped |
| 739 // before they are enabled and can become visible. | 691 // before they are enabled and can become visible. |
| 740 shell_surface->SetEnabled(false); | 692 shell_surface->SetEnabled(false); |
| 741 | 693 |
| 742 shell_surface->set_surface_destroyed_callback(base::Bind( | 694 shell_surface->set_surface_destroyed_callback(base::Bind( |
| 743 &wl_resource_destroy, base::Unretained(shell_surface_resource))); | 695 &wl_resource_destroy, base::Unretained(shell_surface_resource))); |
| 744 | 696 |
| 745 shell_surface->set_configure_callback( | 697 shell_surface->set_configure_callback( |
| 746 base::Bind(&HandleShellSurfaceConfigureCallback, | 698 base::Bind(&HandleShellSurfaceConfigureCallback, |
| 747 base::Unretained(shell_surface_resource))); | 699 base::Unretained(shell_surface_resource))); |
| 748 | 700 |
| 749 SetImplementation(shell_surface_resource, &shell_surface_implementation, | 701 SetImplementation(shell_surface_resource, &shell_surface_implementation, |
| 750 std::move(shell_surface)); | 702 std::move(shell_surface)); |
| 751 } | 703 } |
| 752 | 704 |
| 753 const struct wl_shell_interface shell_implementation = { | 705 const struct wl_shell_interface shell_implementation = { |
| 754 shell_get_shell_surface}; | 706 shell_get_shell_surface}; |
| 755 | 707 |
| 756 void bind_shell(wl_client* client, void* data, uint32_t version, uint32_t id) { | 708 void bind_shell(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 757 wl_resource* resource = | 709 wl_resource* resource = |
| 758 wl_resource_create(client, &wl_shell_interface, 1, id); | 710 wl_resource_create(client, &wl_shell_interface, 1, id); |
| 759 if (!resource) { | 711 |
| 760 wl_client_post_no_memory(client); | |
| 761 return; | |
| 762 } | |
| 763 wl_resource_set_implementation(resource, &shell_implementation, data, | 712 wl_resource_set_implementation(resource, &shell_implementation, data, |
| 764 nullptr); | 713 nullptr); |
| 765 } | 714 } |
| 766 | 715 |
| 767 //////////////////////////////////////////////////////////////////////////////// | 716 //////////////////////////////////////////////////////////////////////////////// |
| 768 // wl_output_interface: | 717 // wl_output_interface: |
| 769 | 718 |
| 770 const uint32_t output_version = 2; | 719 const uint32_t output_version = 2; |
| 771 | 720 |
| 772 void bind_output(wl_client* client, void* data, uint32_t version, uint32_t id) { | 721 void bind_output(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 773 wl_resource* resource = wl_resource_create( | 722 wl_resource* resource = wl_resource_create( |
| 774 client, &wl_output_interface, std::min(version, output_version), id); | 723 client, &wl_output_interface, std::min(version, output_version), id); |
| 775 if (!resource) { | |
| 776 wl_client_post_no_memory(client); | |
| 777 return; | |
| 778 } | |
| 779 | 724 |
| 780 // TODO(reveman): Watch for display changes and report them. | 725 // TODO(reveman): Watch for display changes and report them. |
| 781 // TODO(reveman): Multi-display support. | 726 // TODO(reveman): Multi-display support. |
| 782 ash::DisplayManager* display_manager = | 727 ash::DisplayManager* display_manager = |
| 783 ash::Shell::GetInstance()->display_manager(); | 728 ash::Shell::GetInstance()->display_manager(); |
| 784 const gfx::Display& primary = display_manager->GetPrimaryDisplayCandidate(); | 729 const gfx::Display& primary = display_manager->GetPrimaryDisplayCandidate(); |
| 785 | 730 |
| 786 const ash::DisplayInfo& info = display_manager->GetDisplayInfo(primary.id()); | 731 const ash::DisplayInfo& info = display_manager->GetDisplayInfo(primary.id()); |
| 787 const float kInchInMm = 25.4f; | 732 const float kInchInMm = 25.4f; |
| 788 const char* kUnknownMake = "unknown"; | 733 const char* kUnknownMake = "unknown"; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 } | 918 } |
| 974 | 919 |
| 975 void xdg_shell_get_xdg_surface(wl_client* client, | 920 void xdg_shell_get_xdg_surface(wl_client* client, |
| 976 wl_resource* resource, | 921 wl_resource* resource, |
| 977 uint32_t id, | 922 uint32_t id, |
| 978 wl_resource* surface) { | 923 wl_resource* surface) { |
| 979 scoped_ptr<ShellSurface> shell_surface = | 924 scoped_ptr<ShellSurface> shell_surface = |
| 980 GetUserDataAs<Display>(resource) | 925 GetUserDataAs<Display>(resource) |
| 981 ->CreateShellSurface(GetUserDataAs<Surface>(surface)); | 926 ->CreateShellSurface(GetUserDataAs<Surface>(surface)); |
| 982 if (!shell_surface) { | 927 if (!shell_surface) { |
| 983 wl_resource_post_no_memory(resource); | 928 wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 929 "surface has already been assigned a role"); |
| 984 return; | 930 return; |
| 985 } | 931 } |
| 986 | 932 |
| 987 wl_resource* xdg_surface_resource = | 933 wl_resource* xdg_surface_resource = |
| 988 wl_resource_create(client, &xdg_surface_interface, 1, id); | 934 wl_resource_create(client, &xdg_surface_interface, 1, id); |
| 989 if (!xdg_surface_resource) { | |
| 990 wl_resource_post_no_memory(resource); | |
| 991 return; | |
| 992 } | |
| 993 | 935 |
| 994 shell_surface->set_close_callback(base::Bind( | 936 shell_surface->set_close_callback(base::Bind( |
| 995 &HandleXdgSurfaceCloseCallback, base::Unretained(xdg_surface_resource))); | 937 &HandleXdgSurfaceCloseCallback, base::Unretained(xdg_surface_resource))); |
| 996 | 938 |
| 997 shell_surface->set_configure_callback( | 939 shell_surface->set_configure_callback( |
| 998 base::Bind(&HandleXdgSurfaceConfigureCallback, | 940 base::Bind(&HandleXdgSurfaceConfigureCallback, |
| 999 base::Unretained(xdg_surface_resource))); | 941 base::Unretained(xdg_surface_resource))); |
| 1000 | 942 |
| 1001 SetImplementation(xdg_surface_resource, &xdg_surface_implementation, | 943 SetImplementation(xdg_surface_resource, &xdg_surface_implementation, |
| 1002 std::move(shell_surface)); | 944 std::move(shell_surface)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1021 const struct xdg_shell_interface xdg_shell_implementation = { | 963 const struct xdg_shell_interface xdg_shell_implementation = { |
| 1022 xdg_shell_destroy, xdg_shell_use_unstable_version, | 964 xdg_shell_destroy, xdg_shell_use_unstable_version, |
| 1023 xdg_shell_get_xdg_surface, xdg_shell_get_xdg_popup, xdg_shell_pong}; | 965 xdg_shell_get_xdg_surface, xdg_shell_get_xdg_popup, xdg_shell_pong}; |
| 1024 | 966 |
| 1025 void bind_xdg_shell(wl_client* client, | 967 void bind_xdg_shell(wl_client* client, |
| 1026 void* data, | 968 void* data, |
| 1027 uint32_t version, | 969 uint32_t version, |
| 1028 uint32_t id) { | 970 uint32_t id) { |
| 1029 wl_resource* resource = | 971 wl_resource* resource = |
| 1030 wl_resource_create(client, &xdg_shell_interface, 1, id); | 972 wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 1031 if (!resource) { | 973 |
| 1032 wl_client_post_no_memory(client); | |
| 1033 return; | |
| 1034 } | |
| 1035 wl_resource_set_implementation(resource, &xdg_shell_implementation, data, | 974 wl_resource_set_implementation(resource, &xdg_shell_implementation, data, |
| 1036 nullptr); | 975 nullptr); |
| 1037 } | 976 } |
| 1038 | 977 |
| 1039 //////////////////////////////////////////////////////////////////////////////// | 978 //////////////////////////////////////////////////////////////////////////////// |
| 1040 // wl_data_device_interface: | 979 // wl_data_device_interface: |
| 1041 | 980 |
| 1042 void data_device_start_drag(wl_client* client, | 981 void data_device_start_drag(wl_client* client, |
| 1043 wl_resource* resource, | 982 wl_resource* resource, |
| 1044 wl_resource* source_resource, | 983 wl_resource* source_resource, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1066 uint32_t id) { | 1005 uint32_t id) { |
| 1067 NOTIMPLEMENTED(); | 1006 NOTIMPLEMENTED(); |
| 1068 } | 1007 } |
| 1069 | 1008 |
| 1070 void data_device_manager_get_data_device(wl_client* client, | 1009 void data_device_manager_get_data_device(wl_client* client, |
| 1071 wl_resource* resource, | 1010 wl_resource* resource, |
| 1072 uint32_t id, | 1011 uint32_t id, |
| 1073 wl_resource* seat_resource) { | 1012 wl_resource* seat_resource) { |
| 1074 wl_resource* data_device_resource = | 1013 wl_resource* data_device_resource = |
| 1075 wl_resource_create(client, &wl_data_device_interface, 1, id); | 1014 wl_resource_create(client, &wl_data_device_interface, 1, id); |
| 1076 if (!data_device_resource) { | |
| 1077 wl_client_post_no_memory(client); | |
| 1078 return; | |
| 1079 } | |
| 1080 | 1015 |
| 1081 wl_resource_set_implementation(data_device_resource, | 1016 wl_resource_set_implementation(data_device_resource, |
| 1082 &data_device_implementation, nullptr, nullptr); | 1017 &data_device_implementation, nullptr, nullptr); |
| 1083 } | 1018 } |
| 1084 | 1019 |
| 1085 const struct wl_data_device_manager_interface | 1020 const struct wl_data_device_manager_interface |
| 1086 data_device_manager_implementation = { | 1021 data_device_manager_implementation = { |
| 1087 data_device_manager_create_data_source, | 1022 data_device_manager_create_data_source, |
| 1088 data_device_manager_get_data_device}; | 1023 data_device_manager_get_data_device}; |
| 1089 | 1024 |
| 1090 void bind_data_device_manager(wl_client* client, | 1025 void bind_data_device_manager(wl_client* client, |
| 1091 void* data, | 1026 void* data, |
| 1092 uint32_t version, | 1027 uint32_t version, |
| 1093 uint32_t id) { | 1028 uint32_t id) { |
| 1094 wl_resource* resource = | 1029 wl_resource* resource = |
| 1095 wl_resource_create(client, &wl_data_device_manager_interface, 1, id); | 1030 wl_resource_create(client, &wl_data_device_manager_interface, 1, id); |
| 1096 if (!resource) { | |
| 1097 wl_client_post_no_memory(client); | |
| 1098 return; | |
| 1099 } | |
| 1100 | 1031 |
| 1101 wl_resource_set_implementation(resource, &data_device_manager_implementation, | 1032 wl_resource_set_implementation(resource, &data_device_manager_implementation, |
| 1102 data, nullptr); | 1033 data, nullptr); |
| 1103 } | 1034 } |
| 1104 | 1035 |
| 1105 //////////////////////////////////////////////////////////////////////////////// | 1036 //////////////////////////////////////////////////////////////////////////////// |
| 1106 // wl_pointer_interface: | 1037 // wl_pointer_interface: |
| 1107 | 1038 |
| 1108 // Pointer delegate class that accepts events for surfaces owned by the same | 1039 // Pointer delegate class that accepts events for surfaces owned by the same |
| 1109 // client as a pointer resource. | 1040 // client as a pointer resource. |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 } | 1377 } |
| 1447 | 1378 |
| 1448 const struct wl_touch_interface touch_implementation = {touch_release}; | 1379 const struct wl_touch_interface touch_implementation = {touch_release}; |
| 1449 | 1380 |
| 1450 //////////////////////////////////////////////////////////////////////////////// | 1381 //////////////////////////////////////////////////////////////////////////////// |
| 1451 // wl_seat_interface: | 1382 // wl_seat_interface: |
| 1452 | 1383 |
| 1453 void seat_get_pointer(wl_client* client, wl_resource* resource, uint32_t id) { | 1384 void seat_get_pointer(wl_client* client, wl_resource* resource, uint32_t id) { |
| 1454 wl_resource* pointer_resource = wl_resource_create( | 1385 wl_resource* pointer_resource = wl_resource_create( |
| 1455 client, &wl_pointer_interface, wl_resource_get_version(resource), id); | 1386 client, &wl_pointer_interface, wl_resource_get_version(resource), id); |
| 1456 if (!pointer_resource) { | |
| 1457 wl_resource_post_no_memory(resource); | |
| 1458 return; | |
| 1459 } | |
| 1460 | 1387 |
| 1461 SetImplementation(pointer_resource, &pointer_implementation, | 1388 SetImplementation(pointer_resource, &pointer_implementation, |
| 1462 make_scoped_ptr(new Pointer( | 1389 make_scoped_ptr(new Pointer( |
| 1463 new WaylandPointerDelegate(pointer_resource)))); | 1390 new WaylandPointerDelegate(pointer_resource)))); |
| 1464 } | 1391 } |
| 1465 | 1392 |
| 1466 void seat_get_keyboard(wl_client* client, wl_resource* resource, uint32_t id) { | 1393 void seat_get_keyboard(wl_client* client, wl_resource* resource, uint32_t id) { |
| 1467 #if defined(USE_XKBCOMMON) | 1394 #if defined(USE_XKBCOMMON) |
| 1468 uint32_t version = wl_resource_get_version(resource); | 1395 uint32_t version = wl_resource_get_version(resource); |
| 1469 wl_resource* keyboard_resource = | 1396 wl_resource* keyboard_resource = |
| 1470 wl_resource_create(client, &wl_keyboard_interface, version, id); | 1397 wl_resource_create(client, &wl_keyboard_interface, version, id); |
| 1471 if (!keyboard_resource) { | |
| 1472 wl_resource_post_no_memory(resource); | |
| 1473 return; | |
| 1474 } | |
| 1475 | 1398 |
| 1476 SetImplementation(keyboard_resource, &keyboard_implementation, | 1399 SetImplementation(keyboard_resource, &keyboard_implementation, |
| 1477 make_scoped_ptr(new Keyboard( | 1400 make_scoped_ptr(new Keyboard( |
| 1478 new WaylandKeyboardDelegate(keyboard_resource)))); | 1401 new WaylandKeyboardDelegate(keyboard_resource)))); |
| 1479 | 1402 |
| 1480 // TODO(reveman): Keep repeat info synchronized with chromium and the host OS. | 1403 // TODO(reveman): Keep repeat info synchronized with chromium and the host OS. |
| 1481 if (version >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) | 1404 if (version >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) |
| 1482 wl_keyboard_send_repeat_info(keyboard_resource, 40, 500); | 1405 wl_keyboard_send_repeat_info(keyboard_resource, 40, 500); |
| 1483 #else | 1406 #else |
| 1484 NOTIMPLEMENTED(); | 1407 NOTIMPLEMENTED(); |
| 1485 #endif | 1408 #endif |
| 1486 } | 1409 } |
| 1487 | 1410 |
| 1488 void seat_get_touch(wl_client* client, wl_resource* resource, uint32_t id) { | 1411 void seat_get_touch(wl_client* client, wl_resource* resource, uint32_t id) { |
| 1489 wl_resource* touch_resource = wl_resource_create( | 1412 wl_resource* touch_resource = wl_resource_create( |
| 1490 client, &wl_touch_interface, wl_resource_get_version(resource), id); | 1413 client, &wl_touch_interface, wl_resource_get_version(resource), id); |
| 1491 if (!touch_resource) { | |
| 1492 wl_resource_post_no_memory(resource); | |
| 1493 return; | |
| 1494 } | |
| 1495 | 1414 |
| 1496 SetImplementation( | 1415 SetImplementation( |
| 1497 touch_resource, &touch_implementation, | 1416 touch_resource, &touch_implementation, |
| 1498 make_scoped_ptr(new Touch(new WaylandTouchDelegate(touch_resource)))); | 1417 make_scoped_ptr(new Touch(new WaylandTouchDelegate(touch_resource)))); |
| 1499 } | 1418 } |
| 1500 | 1419 |
| 1501 const struct wl_seat_interface seat_implementation = { | 1420 const struct wl_seat_interface seat_implementation = { |
| 1502 seat_get_pointer, seat_get_keyboard, seat_get_touch}; | 1421 seat_get_pointer, seat_get_keyboard, seat_get_touch}; |
| 1503 | 1422 |
| 1504 const uint32_t seat_version = 4; | 1423 const uint32_t seat_version = 4; |
| 1505 | 1424 |
| 1506 void bind_seat(wl_client* client, void* data, uint32_t version, uint32_t id) { | 1425 void bind_seat(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 1507 wl_resource* resource = wl_resource_create( | 1426 wl_resource* resource = wl_resource_create( |
| 1508 client, &wl_seat_interface, std::min(version, seat_version), id); | 1427 client, &wl_seat_interface, std::min(version, seat_version), id); |
| 1509 if (!resource) { | |
| 1510 wl_client_post_no_memory(client); | |
| 1511 return; | |
| 1512 } | |
| 1513 | 1428 |
| 1514 wl_resource_set_implementation(resource, &seat_implementation, data, nullptr); | 1429 wl_resource_set_implementation(resource, &seat_implementation, data, nullptr); |
| 1515 | 1430 |
| 1516 if (version >= WL_SEAT_NAME_SINCE_VERSION) | 1431 if (version >= WL_SEAT_NAME_SINCE_VERSION) |
| 1517 wl_seat_send_name(resource, "default"); | 1432 wl_seat_send_name(resource, "default"); |
| 1518 | 1433 |
| 1519 uint32_t capabilities = WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH; | 1434 uint32_t capabilities = WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH; |
| 1520 #if defined(USE_XKBCOMMON) | 1435 #if defined(USE_XKBCOMMON) |
| 1521 capabilities |= WL_SEAT_CAPABILITY_KEYBOARD; | 1436 capabilities |= WL_SEAT_CAPABILITY_KEYBOARD; |
| 1522 #endif | 1437 #endif |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 DCHECK(event_loop); | 1492 DCHECK(event_loop); |
| 1578 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 1493 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 1579 } | 1494 } |
| 1580 | 1495 |
| 1581 void Server::Flush() { | 1496 void Server::Flush() { |
| 1582 wl_display_flush_clients(wl_display_.get()); | 1497 wl_display_flush_clients(wl_display_.get()); |
| 1583 } | 1498 } |
| 1584 | 1499 |
| 1585 } // namespace wayland | 1500 } // namespace wayland |
| 1586 } // namespace exo | 1501 } // namespace exo |
| OLD | NEW |