cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / renderer / pepper / ppb_graphics_3d_impl.h
blobee9b2b0869313191474c81038a03a0a2dd643221
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
8 #include "base/memory/shared_memory.h"
9 #include "base/memory/weak_ptr.h"
10 #include "gpu/command_buffer/common/mailbox.h"
11 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h"
12 #include "ppapi/shared_impl/resource.h"
14 namespace content {
15 class CommandBufferProxyImpl;
16 class GpuChannelHost;
18 class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared {
19 public:
20 static PP_Resource Create(PP_Instance instance,
21 PP_Resource share_context,
22 const int32_t* attrib_list);
23 static PP_Resource CreateRaw(
24 PP_Instance instance,
25 PP_Resource share_context,
26 const int32_t* attrib_list,
27 base::SharedMemoryHandle* shared_state_handle);
29 // PPB_Graphics3D_API trusted implementation.
30 PP_Bool SetGetBuffer(int32_t transfer_buffer_id) override;
31 scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size,
32 int32* id) override;
33 PP_Bool DestroyTransferBuffer(int32_t id) override;
34 PP_Bool Flush(int32_t put_offset) override;
35 gpu::CommandBuffer::State WaitForTokenInRange(int32_t start,
36 int32_t end) override;
37 gpu::CommandBuffer::State WaitForGetOffsetInRange(int32_t start,
38 int32_t end) override;
39 uint32_t InsertSyncPoint() override;
40 uint32_t InsertFutureSyncPoint() override;
41 void RetireSyncPoint(uint32_t) override;
43 // Binds/unbinds the graphics of this context with the associated instance.
44 // Returns true if binding/unbinding is successful.
45 bool BindToInstance(bool bind);
47 // Returns true if the backing texture is always opaque.
48 bool IsOpaque();
50 // Notifications about the view's progress painting. See PluginInstance.
51 // These messages are used to send Flush callbacks to the plugin.
52 void ViewInitiatedPaint();
53 void ViewFlushedPaint();
55 void GetBackingMailbox(gpu::Mailbox* mailbox, uint32* sync_point) {
56 *mailbox = mailbox_;
57 *sync_point = sync_point_;
60 int GetCommandBufferRouteId();
62 GpuChannelHost* channel() { return channel_.get(); }
64 protected:
65 ~PPB_Graphics3D_Impl() override;
66 // ppapi::PPB_Graphics3D_Shared overrides.
67 gpu::CommandBuffer* GetCommandBuffer() override;
68 gpu::GpuControl* GetGpuControl() override;
69 int32 DoSwapBuffers() override;
71 private:
72 explicit PPB_Graphics3D_Impl(PP_Instance instance);
74 bool Init(PPB_Graphics3D_API* share_context, const int32_t* attrib_list);
75 bool InitRaw(PPB_Graphics3D_API* share_context,
76 const int32_t* attrib_list,
77 base::SharedMemoryHandle* shared_state_handle);
79 // Notifications received from the GPU process.
80 void OnSwapBuffers();
81 void OnContextLost();
82 void OnConsoleMessage(const std::string& msg, int id);
83 // Notifications sent to plugin.
84 void SendContextLost();
86 // True if context is bound to instance.
87 bool bound_to_instance_;
88 // True when waiting for compositor to commit our backing texture.
89 bool commit_pending_;
91 gpu::Mailbox mailbox_;
92 uint32 sync_point_;
93 bool has_alpha_;
94 scoped_refptr<GpuChannelHost> channel_;
95 CommandBufferProxyImpl* command_buffer_;
97 base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_;
99 DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl);
102 } // namespace content
104 #endif // CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_