| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
| 12 #include "base/task.h" |
| 12 #include "gfx/native_widget_types.h" | 13 #include "gfx/native_widget_types.h" |
| 14 #include "gfx/size.h" |
| 13 #include "gpu/command_buffer/common/command_buffer.h" | 15 #include "gpu/command_buffer/common/command_buffer.h" |
| 14 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 16 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 15 #include "gpu/command_buffer/service/cmd_parser.h" | 17 #include "gpu/command_buffer/service/cmd_parser.h" |
| 16 #include "gpu/command_buffer/service/context_group.h" | 18 #include "gpu/command_buffer/service/context_group.h" |
| 17 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 18 | 20 |
| 19 namespace gpu { | 21 namespace gpu { |
| 20 | 22 |
| 21 // This class processes commands in a command buffer. It is event driven and | 23 // This class processes commands in a command buffer. It is event driven and |
| 22 // posts tasks to the current message loop to do additional work. | 24 // posts tasks to the current message loop to do additional work. |
| 23 class GPUProcessor : public base::RefCounted<GPUProcessor>, | 25 class GPUProcessor : public CommandBufferEngine { |
| 24 public CommandBufferEngine { | |
| 25 public: | 26 public: |
| 26 explicit GPUProcessor(CommandBuffer* command_buffer); | 27 explicit GPUProcessor(CommandBuffer* command_buffer); |
| 27 | 28 |
| 28 // This constructor is for unit tests. | 29 // This constructor is for unit tests. |
| 29 GPUProcessor(CommandBuffer* command_buffer, | 30 GPUProcessor(CommandBuffer* command_buffer, |
| 30 gles2::GLES2Decoder* decoder, | 31 gles2::GLES2Decoder* decoder, |
| 31 CommandParser* parser, | 32 CommandParser* parser, |
| 32 int commands_per_update); | 33 int commands_per_update); |
| 33 | 34 |
| 34 virtual bool Initialize(gfx::PluginWindowHandle hwnd); | 35 virtual bool Initialize(gfx::PluginWindowHandle hwnd, |
| 36 GPUProcessor* parent, |
| 37 const gfx::Size& size, |
| 38 uint32 parent_texture_id); |
| 35 | 39 |
| 36 virtual ~GPUProcessor(); | 40 virtual ~GPUProcessor(); |
| 37 | 41 |
| 38 virtual void Destroy(); | 42 virtual void Destroy(); |
| 39 | 43 |
| 40 virtual void ProcessCommands(); | 44 virtual void ProcessCommands(); |
| 41 | 45 |
| 42 // Implementation of CommandBufferEngine. | 46 // Implementation of CommandBufferEngine. |
| 43 virtual Buffer GetSharedMemoryBuffer(int32 shm_id); | 47 virtual Buffer GetSharedMemoryBuffer(int32 shm_id); |
| 44 virtual void set_token(int32 token); | 48 virtual void set_token(int32 token); |
| 45 virtual bool SetGetOffset(int32 offset); | 49 virtual bool SetGetOffset(int32 offset); |
| 46 virtual int32 GetGetOffset(); | 50 virtual int32 GetGetOffset(); |
| 47 | 51 |
| 52 // Asynchronously resizes an offscreen frame buffer. |
| 53 void ResizeOffscreenFrameBuffer(const gfx::Size& size); |
| 54 |
| 48 #if defined(OS_MACOSX) | 55 #if defined(OS_MACOSX) |
| 49 // Needed only on Mac OS X, which does not render into an on-screen | 56 // Needed only on Mac OS X, which does not render into an on-screen |
| 50 // window and therefore requires the backing store to be resized | 57 // window and therefore requires the backing store to be resized |
| 51 // manually. Returns an opaque identifier for the new backing store. | 58 // manually. Returns an opaque identifier for the new backing store. |
| 52 // There are two versions of this method: one for use with the IOSurface | 59 // There are two versions of this method: one for use with the IOSurface |
| 53 // available in Mac OS X 10.6; and, one for use with the | 60 // available in Mac OS X 10.6; and, one for use with the |
| 54 // TransportDIB-based version used on Mac OS X 10.5. | 61 // TransportDIB-based version used on Mac OS X 10.5. |
| 55 virtual uint64 SetWindowSizeForIOSurface(int32 width, int32 height); | 62 virtual uint64 SetWindowSizeForIOSurface(int32 width, int32 height); |
| 56 virtual TransportDIB::Handle SetWindowSizeForTransportDIB(int32 width, | 63 virtual TransportDIB::Handle SetWindowSizeForTransportDIB(int32 width, |
| 57 int32 height); | 64 int32 height); |
| 58 virtual void SetTransportDIBAllocAndFree( | 65 virtual void SetTransportDIBAllocAndFree( |
| 59 Callback2<size_t, TransportDIB::Handle*>::Type* allocator, | 66 Callback2<size_t, TransportDIB::Handle*>::Type* allocator, |
| 60 Callback1<TransportDIB::Id>::Type* deallocator); | 67 Callback1<TransportDIB::Id>::Type* deallocator); |
| 61 #endif | 68 #endif |
| 62 | 69 |
| 63 // Sets a callback which is called when a SwapBuffers command is processed. | 70 // Sets a callback which is called when a SwapBuffers command is processed. |
| 64 // Must be called after Initialize(). | 71 // Must be called after Initialize(). |
| 65 // It is not defined on which thread this callback is called. | 72 // It is not defined on which thread this callback is called. |
| 66 virtual void SetSwapBuffersCallback(Callback0::Type* callback); | 73 virtual void SetSwapBuffersCallback(Callback0::Type* callback); |
| 67 | 74 |
| 68 private: | 75 private: |
| 69 // The GPUProcessor holds a weak reference to the CommandBuffer. The | 76 // The GPUProcessor holds a weak reference to the CommandBuffer. The |
| 70 // CommandBuffer owns the GPUProcessor and holds a strong reference to it | 77 // CommandBuffer owns the GPUProcessor and holds a strong reference to it |
| 71 // through the ProcessCommands callback. | 78 // through the ProcessCommands callback. |
| 72 CommandBuffer* command_buffer_; | 79 CommandBuffer* command_buffer_; |
| 73 | 80 |
| 74 scoped_ptr< ::base::SharedMemory> mapped_ring_buffer_; | |
| 75 int commands_per_update_; | 81 int commands_per_update_; |
| 76 | 82 |
| 77 gles2::ContextGroup group_; | 83 gles2::ContextGroup group_; |
| 78 scoped_ptr<gles2::GLES2Decoder> decoder_; | 84 scoped_ptr<gles2::GLES2Decoder> decoder_; |
| 79 scoped_ptr<CommandParser> parser_; | 85 scoped_ptr<CommandParser> parser_; |
| 86 |
| 87 ScopedRunnableMethodFactory<GPUProcessor> method_factory_; |
| 80 }; | 88 }; |
| 81 | 89 |
| 82 } // namespace gpu | 90 } // namespace gpu |
| 83 | 91 |
| 84 // Callbacks to the GPUProcessor hold a reference count. | |
| 85 template <typename Method> | |
| 86 class CallbackStorage<gpu::GPUProcessor, Method> { | |
| 87 public: | |
| 88 CallbackStorage(gpu::GPUProcessor* obj, Method method) | |
| 89 : obj_(obj), | |
| 90 meth_(method) { | |
| 91 DCHECK(obj_); | |
| 92 obj_->AddRef(); | |
| 93 } | |
| 94 | |
| 95 ~CallbackStorage() { | |
| 96 obj_->Release(); | |
| 97 } | |
| 98 | |
| 99 protected: | |
| 100 gpu::GPUProcessor* obj_; | |
| 101 Method meth_; | |
| 102 | |
| 103 private: | |
| 104 DISALLOW_COPY_AND_ASSIGN(CallbackStorage); | |
| 105 }; | |
| 106 | |
| 107 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ | 92 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_PROCESSOR_H_ |
| OLD | NEW |