Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/clients/client_base.h" | 5 #include "components/exo/wayland/clients/client_base.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <linux-dmabuf-unstable-v1-client-protocol.h> | 8 #include <linux-dmabuf-unstable-v1-client-protocol.h> |
| 9 #include <presentation-time-client-protocol.h> | 9 #include <presentation-time-client-protocol.h> |
| 10 #include <wayland-client-core.h> | 10 #include <wayland-client-core.h> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 | 50 |
| 51 // Specifies if the background should be transparent. | 51 // Specifies if the background should be transparent. |
| 52 const char kTransparentBackground[] = "transparent-background"; | 52 const char kTransparentBackground[] = "transparent-background"; |
| 53 | 53 |
| 54 // Use drm buffer instead of shared memory. | 54 // Use drm buffer instead of shared memory. |
| 55 const char kUseDrm[] = "use-drm"; | 55 const char kUseDrm[] = "use-drm"; |
| 56 | 56 |
| 57 // Specifies if client should be fullscreen. | 57 // Specifies if client should be fullscreen. |
| 58 const char kFullscreen[] = "fullscreen"; | 58 const char kFullscreen[] = "fullscreen"; |
| 59 | 59 |
| 60 // Specifies if no-roundtrip dmabuf import path should be used. | |
| 61 const char kNoRoundtripImport[] = "no-roundtrip-import"; | |
|
reveman
2017/04/28 17:21:24
No need for this flag. Please refactor the code so
| |
| 62 | |
| 60 } // namespace switches | 63 } // namespace switches |
| 61 | 64 |
| 62 namespace { | 65 namespace { |
| 63 | 66 |
| 64 // Buffer format. | 67 // Buffer format. |
| 65 const int32_t kShmFormat = WL_SHM_FORMAT_ARGB8888; | 68 const int32_t kShmFormat = WL_SHM_FORMAT_ARGB8888; |
| 66 const SkColorType kColorType = kBGRA_8888_SkColorType; | 69 const SkColorType kColorType = kBGRA_8888_SkColorType; |
| 67 #if defined(OZONE_PLATFORM_GBM) | 70 #if defined(OZONE_PLATFORM_GBM) |
| 68 const GrPixelConfig kGrPixelConfig = kBGRA_8888_GrPixelConfig; | 71 const GrPixelConfig kGrPixelConfig = kBGRA_8888_GrPixelConfig; |
| 69 #endif | 72 #endif |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 return false; | 170 return false; |
| 168 } | 171 } |
| 169 | 172 |
| 170 use_drm = command_line.HasSwitch(switches::kUseDrm); | 173 use_drm = command_line.HasSwitch(switches::kUseDrm); |
| 171 if (use_drm) | 174 if (use_drm) |
| 172 use_drm_value = command_line.GetSwitchValueASCII(switches::kUseDrm); | 175 use_drm_value = command_line.GetSwitchValueASCII(switches::kUseDrm); |
| 173 | 176 |
| 174 fullscreen = command_line.HasSwitch(switches::kFullscreen); | 177 fullscreen = command_line.HasSwitch(switches::kFullscreen); |
| 175 transparent_background = | 178 transparent_background = |
| 176 command_line.HasSwitch(switches::kTransparentBackground); | 179 command_line.HasSwitch(switches::kTransparentBackground); |
| 180 immed = command_line.HasSwitch(switches::kNoRoundtripImport); | |
| 177 return true; | 181 return true; |
| 178 } | 182 } |
| 179 | 183 |
| 180 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
| 181 // ClientBase::Globals, public: | 185 // ClientBase::Globals, public: |
| 182 | 186 |
| 183 ClientBase::Globals::Globals() {} | 187 ClientBase::Globals::Globals() {} |
| 184 | 188 |
| 185 ClientBase::Globals::~Globals() {} | 189 ClientBase::Globals::~Globals() {} |
| 186 | 190 |
| 187 //////////////////////////////////////////////////////////////////////////////// | 191 //////////////////////////////////////////////////////////////////////////////// |
| 188 // ClientBase::Buffer, public: | 192 // ClientBase::Buffer, public: |
| 189 | 193 |
| 190 ClientBase::Buffer::Buffer() {} | 194 ClientBase::Buffer::Buffer() {} |
| 191 | 195 |
| 192 ClientBase::Buffer::~Buffer() {} | 196 ClientBase::Buffer::~Buffer() {} |
| 193 | 197 |
| 194 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
| 195 // ClientBase, public: | 199 // ClientBase, public: |
| 196 | 200 |
| 197 bool ClientBase::Init(const InitParams& params) { | 201 bool ClientBase::Init(const InitParams& params) { |
| 198 width_ = params.width; | 202 width_ = params.width; |
| 199 height_ = params.height; | 203 height_ = params.height; |
| 200 scale_ = params.scale; | 204 scale_ = params.scale; |
| 201 fullscreen_ = params.fullscreen; | 205 fullscreen_ = params.fullscreen; |
| 202 transparent_background_ = params.transparent_background; | 206 transparent_background_ = params.transparent_background; |
| 207 immed_ = params.immed; | |
| 203 | 208 |
| 204 display_.reset(wl_display_connect(nullptr)); | 209 display_.reset(wl_display_connect(nullptr)); |
| 205 if (!display_) { | 210 if (!display_) { |
| 206 LOG(ERROR) << "wl_display_connect failed"; | 211 LOG(ERROR) << "wl_display_connect failed"; |
| 207 return false; | 212 return false; |
| 208 } | 213 } |
| 209 wl_registry* registry = wl_display_get_registry(display_.get()); | 214 wl_registry* registry = wl_display_get_registry(display_.get()); |
| 210 wl_registry_add_listener(registry, &g_registry_listener, &globals_); | 215 wl_registry_add_listener(registry, &g_registry_listener, &globals_); |
| 211 | 216 |
| 212 wl_display_roundtrip(display_.get()); | 217 wl_display_roundtrip(display_.get()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 #endif | 311 #endif |
| 307 for (size_t i = 0; i < params.num_buffers; ++i) { | 312 for (size_t i = 0; i < params.num_buffers; ++i) { |
| 308 auto buffer = CreateBuffer(params.drm_format); | 313 auto buffer = CreateBuffer(params.drm_format); |
| 309 if (!buffer) { | 314 if (!buffer) { |
| 310 LOG(ERROR) << "Failed to create buffer"; | 315 LOG(ERROR) << "Failed to create buffer"; |
| 311 return false; | 316 return false; |
| 312 } | 317 } |
| 313 buffers_.push_back(std::move(buffer)); | 318 buffers_.push_back(std::move(buffer)); |
| 314 } | 319 } |
| 315 | 320 |
| 316 wl_display_roundtrip(display_.get()); | 321 if (!immed_) |
| 322 wl_display_roundtrip(display_.get()); | |
| 317 for (size_t i = 0; i < buffers_.size(); ++i) { | 323 for (size_t i = 0; i < buffers_.size(); ++i) { |
| 318 if (!buffers_[i]->buffer) { | 324 if (!buffers_[i]->buffer) { |
| 319 LOG(ERROR) << "LinuxBufferParamsCreated was not called on the buffer."; | 325 LOG(ERROR) << "LinuxBufferParamsCreated was not called on the buffer."; |
| 320 return false; | 326 return false; |
| 321 } | 327 } |
| 322 | 328 |
| 323 wl_buffer_add_listener(buffers_[i]->buffer.get(), &g_buffer_listener, | 329 wl_buffer_add_listener(buffers_[i]->buffer.get(), &g_buffer_listener, |
| 324 buffers_[i].get()); | 330 buffers_[i].get()); |
| 325 } | 331 } |
| 326 | 332 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 zwp_linux_dmabuf_v1_create_params(globals_.linux_dmabuf.get())); | 396 zwp_linux_dmabuf_v1_create_params(globals_.linux_dmabuf.get())); |
| 391 zwp_linux_buffer_params_v1_add_listener(buffer->params.get(), | 397 zwp_linux_buffer_params_v1_add_listener(buffer->params.get(), |
| 392 &g_params_listener, buffer.get()); | 398 &g_params_listener, buffer.get()); |
| 393 for (size_t i = 0; i < gbm_bo_get_num_planes(buffer->bo.get()); ++i) { | 399 for (size_t i = 0; i < gbm_bo_get_num_planes(buffer->bo.get()); ++i) { |
| 394 base::ScopedFD fd(gbm_bo_get_plane_fd(buffer->bo.get(), i)); | 400 base::ScopedFD fd(gbm_bo_get_plane_fd(buffer->bo.get(), i)); |
| 395 uint32_t stride = gbm_bo_get_plane_stride(buffer->bo.get(), i); | 401 uint32_t stride = gbm_bo_get_plane_stride(buffer->bo.get(), i); |
| 396 uint32_t offset = gbm_bo_get_plane_offset(buffer->bo.get(), i); | 402 uint32_t offset = gbm_bo_get_plane_offset(buffer->bo.get(), i); |
| 397 zwp_linux_buffer_params_v1_add(buffer->params.get(), fd.get(), i, offset, | 403 zwp_linux_buffer_params_v1_add(buffer->params.get(), fd.get(), i, offset, |
| 398 stride, 0, 0); | 404 stride, 0, 0); |
| 399 } | 405 } |
| 400 zwp_linux_buffer_params_v1_create(buffer->params.get(), width_, height_, | 406 if (immed_) |
| 401 drm_format, 0); | 407 buffer->buffer.reset(zwp_linux_buffer_params_v1_create_immed( |
| 408 buffer->params.get(), width_, height_, drm_format, 0)); | |
| 409 else | |
| 410 zwp_linux_buffer_params_v1_create(buffer->params.get(), width_, height_, | |
| 411 drm_format, 0); | |
| 402 | 412 |
| 403 if (gbm_bo_get_num_planes(buffer->bo.get()) != 1) | 413 if (gbm_bo_get_num_planes(buffer->bo.get()) != 1) |
| 404 return buffer; | 414 return buffer; |
| 405 | 415 |
| 406 EGLint khr_image_attrs[] = {EGL_DMA_BUF_PLANE0_FD_EXT, | 416 EGLint khr_image_attrs[] = {EGL_DMA_BUF_PLANE0_FD_EXT, |
| 407 fd.get(), | 417 fd.get(), |
| 408 EGL_WIDTH, | 418 EGL_WIDTH, |
| 409 width_, | 419 width_, |
| 410 EGL_HEIGHT, | 420 EGL_HEIGHT, |
| 411 height_, | 421 height_, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 buffer->sk_surface = SkSurface::MakeRasterDirect( | 474 buffer->sk_surface = SkSurface::MakeRasterDirect( |
| 465 SkImageInfo::Make(width_, height_, kColorType, kOpaque_SkAlphaType), | 475 SkImageInfo::Make(width_, height_, kColorType, kOpaque_SkAlphaType), |
| 466 static_cast<uint8_t*>(buffer->shared_memory->memory()), stride); | 476 static_cast<uint8_t*>(buffer->shared_memory->memory()), stride); |
| 467 DCHECK(buffer->sk_surface); | 477 DCHECK(buffer->sk_surface); |
| 468 return buffer; | 478 return buffer; |
| 469 } | 479 } |
| 470 | 480 |
| 471 } // namespace clients | 481 } // namespace clients |
| 472 } // namespace wayland | 482 } // namespace wayland |
| 473 } // namespace exo | 483 } // namespace exo |
| OLD | NEW |