| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_RENDERER_GPU_COMMAND_BUFFER_PROXY_H_ | 5 #ifndef CONTENT_RENDERER_GPU_COMMAND_BUFFER_PROXY_H_ |
| 6 #define CONTENT_RENDERER_GPU_COMMAND_BUFFER_PROXY_H_ | 6 #define CONTENT_RENDERER_GPU_COMMAND_BUFFER_PROXY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #if defined(ENABLE_GPU) | 9 #if defined(ENABLE_GPU) |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <queue> | 12 #include <queue> |
| 13 | 13 |
| 14 #include "base/callback_old.h" | 14 #include "base/callback_old.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/task.h" |
| 18 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" | 19 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" |
| 19 #include "gpu/command_buffer/common/command_buffer.h" | 20 #include "gpu/command_buffer/common/command_buffer.h" |
| 20 #include "ipc/ipc_channel.h" | 21 #include "ipc/ipc_channel.h" |
| 21 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class SharedMemory; | 25 class SharedMemory; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace gfx { | 28 namespace gfx { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 58 virtual void SetGetOffset(int32 get_offset); | 59 virtual void SetGetOffset(int32 get_offset); |
| 59 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); | 60 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); |
| 60 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | 61 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, |
| 61 size_t size, | 62 size_t size, |
| 62 int32 id_request); | 63 int32 id_request); |
| 63 virtual void DestroyTransferBuffer(int32 id); | 64 virtual void DestroyTransferBuffer(int32 id); |
| 64 virtual gpu::Buffer GetTransferBuffer(int32 handle); | 65 virtual gpu::Buffer GetTransferBuffer(int32 handle); |
| 65 virtual void SetToken(int32 token); | 66 virtual void SetToken(int32 token); |
| 66 virtual void SetParseError(gpu::error::Error error); | 67 virtual void SetParseError(gpu::error::Error error); |
| 67 virtual void SetContextLostReason(gpu::error::ContextLostReason reason); | 68 virtual void SetContextLostReason(gpu::error::ContextLostReason reason); |
| 68 virtual void OnSwapBuffers(); | 69 |
| 70 // Invoke the task when the channel has been flushed. Takes care of deleting |
| 71 // the task whether the echo succeeds or not. |
| 72 bool Echo(Task* task); |
| 69 | 73 |
| 70 // Reparent a command buffer. TODO(apatrick): going forward, the notion of | 74 // Reparent a command buffer. TODO(apatrick): going forward, the notion of |
| 71 // the parent / child relationship between command buffers is going away in | 75 // the parent / child relationship between command buffers is going away in |
| 72 // favor of the notion of surfaces that can be drawn to in one command buffer | 76 // favor of the notion of surfaces that can be drawn to in one command buffer |
| 73 // and bound as a texture in any other. | 77 // and bound as a texture in any other. |
| 74 virtual bool SetParent(CommandBufferProxy* parent_command_buffer, | 78 virtual bool SetParent(CommandBufferProxy* parent_command_buffer, |
| 75 uint32 parent_texture_id); | 79 uint32 parent_texture_id); |
| 76 | 80 |
| 77 // Set a callback that will be invoked when the SwapBuffers call has been | |
| 78 // issued. | |
| 79 void SetSwapBuffersCallback(Callback0::Type* callback); | |
| 80 void SetChannelErrorCallback(Callback0::Type* callback); | 81 void SetChannelErrorCallback(Callback0::Type* callback); |
| 81 | 82 |
| 82 // Set a task that will be invoked the next time the window becomes invalid | 83 // Set a task that will be invoked the next time the window becomes invalid |
| 83 // and needs to be repainted. Takes ownership of task. | 84 // and needs to be repainted. Takes ownership of task. |
| 84 void SetNotifyRepaintTask(Task* task); | 85 void SetNotifyRepaintTask(Task* task); |
| 85 | 86 |
| 86 // Sends an IPC message to create a GpuVideoDecodeAccelerator. Creates and | 87 // Sends an IPC message to create a GpuVideoDecodeAccelerator. Creates and |
| 87 // returns a pointer to a GpuVideoDecodeAcceleratorHost. | 88 // returns a pointer to a GpuVideoDecodeAcceleratorHost. |
| 88 // Returns NULL on failure to create the GpuVideoDecodeAcceleratorHost. | 89 // Returns NULL on failure to create the GpuVideoDecodeAcceleratorHost. |
| 89 // Note that the GpuVideoDecodeAccelerator may still fail to be created in | 90 // Note that the GpuVideoDecodeAccelerator may still fail to be created in |
| 90 // the GPU process, even if this returns non-NULL. In this case the client is | 91 // the GPU process, even if this returns non-NULL. In this case the client is |
| 91 // notified of an error later. | 92 // notified of an error later. |
| 92 scoped_refptr<GpuVideoDecodeAcceleratorHost> CreateVideoDecoder( | 93 scoped_refptr<GpuVideoDecodeAcceleratorHost> CreateVideoDecoder( |
| 93 const std::vector<int32>& configs, | 94 const std::vector<int32>& configs, |
| 94 media::VideoDecodeAccelerator::Client* client); | 95 media::VideoDecodeAccelerator::Client* client); |
| 95 | 96 |
| 96 private: | 97 private: |
| 97 | 98 |
| 98 // Send an IPC message over the GPU channel. This is private to fully | 99 // Send an IPC message over the GPU channel. This is private to fully |
| 99 // encapsulate the channel; all callers of this function must explicitly | 100 // encapsulate the channel; all callers of this function must explicitly |
| 100 // verify that the context has not been lost. | 101 // verify that the context has not been lost. |
| 101 bool Send(IPC::Message* msg); | 102 bool Send(IPC::Message* msg); |
| 102 | 103 |
| 103 // Message handlers: | 104 // Message handlers: |
| 104 void OnUpdateState(const gpu::CommandBuffer::State& state); | 105 void OnUpdateState(const gpu::CommandBuffer::State& state); |
| 105 void OnNotifyRepaint(); | 106 void OnNotifyRepaint(); |
| 106 void OnDestroyed(gpu::error::ContextLostReason reason); | 107 void OnDestroyed(gpu::error::ContextLostReason reason); |
| 108 void OnEchoAck(); |
| 107 | 109 |
| 108 // As with the service, the client takes ownership of the ring buffer. | 110 // As with the service, the client takes ownership of the ring buffer. |
| 109 int32 num_entries_; | 111 int32 num_entries_; |
| 110 scoped_ptr<base::SharedMemory> ring_buffer_; | 112 scoped_ptr<base::SharedMemory> ring_buffer_; |
| 111 | 113 |
| 112 // Local cache of id to transfer buffer mapping. | 114 // Local cache of id to transfer buffer mapping. |
| 113 typedef std::map<int32, gpu::Buffer> TransferBufferMap; | 115 typedef std::map<int32, gpu::Buffer> TransferBufferMap; |
| 114 TransferBufferMap transfer_buffers_; | 116 TransferBufferMap transfer_buffers_; |
| 115 | 117 |
| 116 // Zero or more video decoder hosts owned by this proxy, keyed by their | 118 // Zero or more video decoder hosts owned by this proxy, keyed by their |
| 117 // decoder_route_id. | 119 // decoder_route_id. |
| 118 typedef std::map<int, scoped_refptr<GpuVideoDecodeAcceleratorHost> > Decoders; | 120 typedef std::map<int, scoped_refptr<GpuVideoDecodeAcceleratorHost> > Decoders; |
| 119 Decoders video_decoder_hosts_; | 121 Decoders video_decoder_hosts_; |
| 120 | 122 |
| 121 // The last cached state received from the service. | 123 // The last cached state received from the service. |
| 122 State last_state_; | 124 State last_state_; |
| 123 | 125 |
| 124 // |*this| is owned by |*channel_| and so is always outlived by it, so using a | 126 // |*this| is owned by |*channel_| and so is always outlived by it, so using a |
| 125 // raw pointer is ok. | 127 // raw pointer is ok. |
| 126 GpuChannelHost* channel_; | 128 GpuChannelHost* channel_; |
| 127 int route_id_; | 129 int route_id_; |
| 128 unsigned int flush_count_; | 130 unsigned int flush_count_; |
| 129 | 131 |
| 132 // Tasks to be invoked in echo responses. |
| 133 std::queue<linked_ptr<Task> > echo_tasks_; |
| 134 |
| 130 scoped_ptr<Task> notify_repaint_task_; | 135 scoped_ptr<Task> notify_repaint_task_; |
| 131 | 136 |
| 132 scoped_ptr<Callback0::Type> swap_buffers_callback_; | |
| 133 scoped_ptr<Callback0::Type> channel_error_callback_; | 137 scoped_ptr<Callback0::Type> channel_error_callback_; |
| 134 | 138 |
| 135 DISALLOW_COPY_AND_ASSIGN(CommandBufferProxy); | 139 DISALLOW_COPY_AND_ASSIGN(CommandBufferProxy); |
| 136 }; | 140 }; |
| 137 | 141 |
| 138 #endif // ENABLE_GPU | 142 #endif // ENABLE_GPU |
| 139 | 143 |
| 140 #endif // CONTENT_RENDERER_GPU_COMMAND_BUFFER_PROXY_H_ | 144 #endif // CONTENT_RENDERER_GPU_COMMAND_BUFFER_PROXY_H_ |
| OLD | NEW |