Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / ppb_graphics_3d_impl.h
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.
4
5 #ifndef CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
7
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"
13
14 namespace gpu {
15 struct Capabilities;
16 }
17
18 namespace content {
19 class CommandBufferProxyImpl;
20 class GpuChannelHost;
21
22 class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared {
23  public:
24   static PP_Resource Create(PP_Instance instance,
25                             PP_Resource share_context,
26                             const int32_t* attrib_list);
27   static PP_Resource CreateRaw(
28       PP_Instance instance,
29       PP_Resource share_context,
30       const int32_t* attrib_list,
31       gpu::Capabilities* capabilities,
32       base::SharedMemoryHandle* shared_state_handle);
33
34   // PPB_Graphics3D_API trusted implementation.
35   PP_Bool SetGetBuffer(int32_t transfer_buffer_id) override;
36   scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size,
37                                                   int32* id) override;
38   PP_Bool DestroyTransferBuffer(int32_t id) override;
39   PP_Bool Flush(int32_t put_offset) override;
40   gpu::CommandBuffer::State WaitForTokenInRange(int32_t start,
41                                                 int32_t end) override;
42   gpu::CommandBuffer::State WaitForGetOffsetInRange(int32_t start,
43                                                     int32_t end) override;
44   uint32_t InsertSyncPoint() override;
45   uint32_t InsertFutureSyncPoint() override;
46   void RetireSyncPoint(uint32_t) override;
47
48   // Binds/unbinds the graphics of this context with the associated instance.
49   // Returns true if binding/unbinding is successful.
50   bool BindToInstance(bool bind);
51
52   // Returns true if the backing texture is always opaque.
53   bool IsOpaque();
54
55   // Notifications about the view's progress painting.  See PluginInstance.
56   // These messages are used to send Flush callbacks to the plugin.
57   void ViewInitiatedPaint();
58   void ViewFlushedPaint();
59
60   void GetBackingMailbox(gpu::Mailbox* mailbox, uint32* sync_point) {
61     *mailbox = mailbox_;
62     *sync_point = sync_point_;
63   }
64
65   int GetCommandBufferRouteId();
66
67   GpuChannelHost* channel() { return channel_.get(); }
68
69  protected:
70   ~PPB_Graphics3D_Impl() override;
71   // ppapi::PPB_Graphics3D_Shared overrides.
72   gpu::CommandBuffer* GetCommandBuffer() override;
73   gpu::GpuControl* GetGpuControl() override;
74   int32 DoSwapBuffers() override;
75
76  private:
77   explicit PPB_Graphics3D_Impl(PP_Instance instance);
78
79   bool Init(PPB_Graphics3D_API* share_context, const int32_t* attrib_list);
80   bool InitRaw(PPB_Graphics3D_API* share_context,
81                const int32_t* attrib_list,
82                gpu::Capabilities* capabilities,
83                base::SharedMemoryHandle* shared_state_handle);
84
85   // Notifications received from the GPU process.
86   void OnSwapBuffers();
87   void OnContextLost();
88   void OnConsoleMessage(const std::string& msg, int id);
89   // Notifications sent to plugin.
90   void SendContextLost();
91
92   // True if context is bound to instance.
93   bool bound_to_instance_;
94   // True when waiting for compositor to commit our backing texture.
95   bool commit_pending_;
96
97   gpu::Mailbox mailbox_;
98   uint32 sync_point_;
99   bool has_alpha_;
100   scoped_refptr<GpuChannelHost> channel_;
101   CommandBufferProxyImpl* command_buffer_;
102
103   base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_;
104
105   DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl);
106 };
107
108 }  // namespace content
109
110 #endif  // CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_