OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/dbus/chrome_surface_service_provider_delegate.
h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/surfaces/surface_controller.h" |
| 9 #include "ash/surfaces/test_shell_surface_overlay_view.h" |
| 10 #include "base/logging.h" |
| 11 #include "ui/gfx/gpu_memory_buffer.h" |
| 12 |
| 13 namespace chromeos { |
| 14 namespace { |
| 15 |
| 16 #define FOURCC(a, b, c, d) \ |
| 17 ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ |
| 18 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) |
| 19 |
| 20 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') |
| 21 |
| 22 bool IsSupportedFormat(uint32 format) { |
| 23 switch (format) { |
| 24 case DRM_FORMAT_ABGR8888: |
| 25 return true; |
| 26 default: |
| 27 return false; |
| 28 } |
| 29 } |
| 30 |
| 31 gfx::BufferFormat BufferFormat(uint32 format) { |
| 32 switch (format) { |
| 33 case DRM_FORMAT_ABGR8888: |
| 34 return gfx::BufferFormat::RGBA_8888; |
| 35 default: |
| 36 NOTREACHED(); |
| 37 return gfx::BufferFormat::RGBA_8888; |
| 38 } |
| 39 } |
| 40 |
| 41 } // namespace |
| 42 |
| 43 ChromeSurfaceServiceProviderDelegate::ChromeSurfaceServiceProviderDelegate() |
| 44 : attached_test_shell_surface_buffer_id_(0) {} |
| 45 |
| 46 ChromeSurfaceServiceProviderDelegate::~ChromeSurfaceServiceProviderDelegate() {} |
| 47 |
| 48 void ChromeSurfaceServiceProviderDelegate::CreatePrimeBuffer( |
| 49 uint32 id, |
| 50 base::ScopedFD fd, |
| 51 int32 width, |
| 52 int32 height, |
| 53 uint32 format, |
| 54 int32 stride, |
| 55 const CreateBufferCallback& callback) { |
| 56 if (!IsSupportedFormat(format)) { |
| 57 LOG(ERROR) << "Failed to create prime buffer. Unsupported format 0x" |
| 58 << std::hex << format; |
| 59 callback.Run(false); |
| 60 return; |
| 61 } |
| 62 |
| 63 gfx::GpuMemoryBufferHandle handle; |
| 64 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
| 65 handle.native_pixmap_handle.fd = base::FileDescriptor(fd.Pass()); |
| 66 handle.native_pixmap_handle.stride = stride; |
| 67 ash::Shell::GetInstance() |
| 68 ->surface_controller() |
| 69 ->CreateGraphicsBufferFromGpuMemoryBufferHandle( |
| 70 id, handle, gfx::Size(width, height), BufferFormat(format), callback); |
| 71 } |
| 72 |
| 73 void ChromeSurfaceServiceProviderDelegate::DestroyBuffer(uint32 id) { |
| 74 ash::Shell::GetInstance()->surface_controller()->DestroyGraphicsBuffer(id); |
| 75 } |
| 76 |
| 77 void ChromeSurfaceServiceProviderDelegate::AttachBufferToTestShellSurface( |
| 78 uint32 buffer_id, |
| 79 const base::Closure& released_callback) { |
| 80 ash::Shell::GetInstance() |
| 81 ->surface_controller() |
| 82 ->AttachGraphicsBufferToTestShellSurface(buffer_id, released_callback); |
| 83 |
| 84 // Show overlay view when an initial buffer is attached. |
| 85 if (!attached_test_shell_surface_buffer_id_) |
| 86 ash::TestShellSurfaceOverlayView::Show(); |
| 87 |
| 88 attached_test_shell_surface_buffer_id_ = buffer_id; |
| 89 } |
| 90 |
| 91 } // namespace chromeos |
OLD | NEW |