| 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 #ifndef MEDIA_GPU_IPC_SERVICE_GPU_JPEG_DECODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_GPU_IPC_SERVICE_GPU_JPEG_DECODE_ACCELERATOR_H_ |
| 6 #define MEDIA_GPU_IPC_SERVICE_GPU_JPEG_DECODE_ACCELERATOR_H_ | 6 #define MEDIA_GPU_IPC_SERVICE_GPU_JPEG_DECODE_ACCELERATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "ipc/ipc_listener.h" | 17 #include "ipc/ipc_listener.h" |
| 18 #include "ipc/ipc_sender.h" | 18 #include "ipc/ipc_sender.h" |
| 19 #include "media/gpu/mojo/jpeg_decoder.mojom.h" |
| 19 #include "media/video/jpeg_decode_accelerator.h" | 20 #include "media/video/jpeg_decode_accelerator.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class SingleThreadTaskRunner; | 23 class SingleThreadTaskRunner; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace gpu { | 26 namespace gpu { |
| 26 class FilteredSender; | 27 class FilteredSender; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace media { | 30 namespace media { |
| 30 | 31 |
| 31 class GpuJpegDecodeAcceleratorFactoryProvider { | 32 class GpuJpegDecodeAcceleratorFactoryProvider { |
| 32 public: | 33 public: |
| 33 using CreateAcceleratorCB = | 34 using CreateAcceleratorCB = |
| 34 base::Callback<std::unique_ptr<JpegDecodeAccelerator>( | 35 base::Callback<std::unique_ptr<JpegDecodeAccelerator>( |
| 35 scoped_refptr<base::SingleThreadTaskRunner>)>; | 36 scoped_refptr<base::SingleThreadTaskRunner>)>; |
| 36 | 37 |
| 37 // Static query for JPEG supported. This query calls the appropriate | 38 // Static query for JPEG supported. This query calls the appropriate |
| 38 // platform-specific version. | 39 // platform-specific version. |
| 39 static bool IsAcceleratedJpegDecodeSupported(); | 40 static bool IsAcceleratedJpegDecodeSupported(); |
| 40 | 41 |
| 41 static std::vector<CreateAcceleratorCB> GetAcceleratorFactories(); | 42 static std::vector<CreateAcceleratorCB> GetAcceleratorFactories(); |
| 42 }; | 43 }; |
| 43 | 44 |
| 45 // TODO(c.padhi): Move GpuJpegDecodeAccelerator to media/gpu/mojo, see |
| 46 // http://crbug.com/699255. |
| 44 class GpuJpegDecodeAccelerator | 47 class GpuJpegDecodeAccelerator |
| 45 : public IPC::Sender, | 48 : public mojom::GpuJpegDecodeAccelerator, |
| 46 public base::NonThreadSafe, | 49 public IPC::Sender, |
| 47 public base::SupportsWeakPtr<GpuJpegDecodeAccelerator> { | 50 public base::SupportsWeakPtr<GpuJpegDecodeAccelerator> { |
| 48 public: | 51 public: |
| 49 // |channel| must outlive this object. | 52 // |channel| must outlive this object. |
| 50 // This convenience constructor internally calls | 53 // This convenience constructor internally calls |
| 51 // GpuJpegDecodeAcceleratorFactoryProvider::GetAcceleratorFactories() to | 54 // GpuJpegDecodeAcceleratorFactoryProvider::GetAcceleratorFactories() to |
| 52 // fill |accelerator_factory_functions_|. | 55 // fill |accelerator_factory_functions_|. |
| 53 GpuJpegDecodeAccelerator( | 56 GpuJpegDecodeAccelerator( |
| 54 gpu::FilteredSender* channel, | 57 gpu::FilteredSender* channel, |
| 55 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); | 58 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
| 56 | 59 |
| 57 // |channel| must outlive this object. | 60 // |channel| must outlive this object. |
| 58 GpuJpegDecodeAccelerator( | 61 GpuJpegDecodeAccelerator( |
| 59 gpu::FilteredSender* channel, | 62 gpu::FilteredSender* channel, |
| 60 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 63 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 61 std::vector<GpuJpegDecodeAcceleratorFactoryProvider::CreateAcceleratorCB> | 64 std::vector<GpuJpegDecodeAcceleratorFactoryProvider::CreateAcceleratorCB> |
| 62 accelerator_factory_functions); | 65 accelerator_factory_functions); |
| 63 ~GpuJpegDecodeAccelerator() override; | 66 ~GpuJpegDecodeAccelerator() override; |
| 64 | 67 |
| 65 void AddClient(int32_t route_id, base::Callback<void(bool)> response); | 68 void AddClient(int32_t route_id, base::Callback<void(bool)> response); |
| 66 | 69 |
| 67 void NotifyDecodeStatus(int32_t route_id, | 70 void NotifyDecodeStatus(int32_t route_id, |
| 68 int32_t bitstream_buffer_id, | 71 int32_t bitstream_buffer_id, |
| 69 JpegDecodeAccelerator::Error error); | 72 JpegDecodeAccelerator::Error error); |
| 70 | 73 |
| 74 // mojom::GpuJpegDecodeAccelerator implementation. |
| 75 void Initialize(mojom::GpuJpegDecodeAcceleratorClientPtr client, |
| 76 InitializeCallback callback) override; |
| 77 void Decode(mojom::JpegDecodeInfoPtr info) override; |
| 78 void Uninitialize() override; |
| 79 |
| 71 // Function to delegate sending to actual sender. | 80 // Function to delegate sending to actual sender. |
| 72 bool Send(IPC::Message* message) override; | 81 bool Send(IPC::Message* message) override; |
| 73 | 82 |
| 74 private: | 83 private: |
| 75 class Client; | 84 class Client; |
| 76 class MessageFilter; | 85 class MessageFilter; |
| 77 | 86 |
| 78 void ClientRemoved(); | 87 void ClientRemoved(); |
| 79 | 88 |
| 80 std::vector<GpuJpegDecodeAcceleratorFactoryProvider::CreateAcceleratorCB> | 89 std::vector<GpuJpegDecodeAcceleratorFactoryProvider::CreateAcceleratorCB> |
| 81 accelerator_factory_functions_; | 90 accelerator_factory_functions_; |
| 82 | 91 |
| 83 gpu::FilteredSender* channel_; | 92 gpu::FilteredSender* channel_; |
| 84 | 93 |
| 85 // The message filter to run JpegDecodeAccelerator::Decode on IO thread. | 94 // The message filter to run JpegDecodeAccelerator::Decode on IO thread. |
| 86 scoped_refptr<MessageFilter> filter_; | 95 scoped_refptr<MessageFilter> filter_; |
| 87 | 96 |
| 88 // GPU child task runner. | 97 // GPU child task runner. |
| 89 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | 98 scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
| 90 | 99 |
| 91 // GPU IO task runner. | 100 // GPU IO task runner. |
| 92 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 101 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 93 | 102 |
| 94 // Number of clients added to |filter_|. | 103 // Number of clients added to |filter_|. |
| 95 int client_number_; | 104 int client_number_; |
| 96 | 105 |
| 106 THREAD_CHECKER(thread_checker_); |
| 97 DISALLOW_IMPLICIT_CONSTRUCTORS(GpuJpegDecodeAccelerator); | 107 DISALLOW_IMPLICIT_CONSTRUCTORS(GpuJpegDecodeAccelerator); |
| 98 }; | 108 }; |
| 99 | 109 |
| 100 } // namespace media | 110 } // namespace media |
| 101 | 111 |
| 102 #endif // MEDIA_GPU_IPC_SERVICE_GPU_JPEG_DECODE_ACCELERATOR_H_ | 112 #endif // MEDIA_GPU_IPC_SERVICE_GPU_JPEG_DECODE_ACCELERATOR_H_ |
| OLD | NEW |