- add sources.
[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/weak_ptr.h"
9 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h"
10 #include "ppapi/shared_impl/resource.h"
11
12 namespace content {
13 class PlatformContext3D;
14
15 class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared {
16  public:
17   static PP_Resource Create(PP_Instance instance,
18                             PP_Resource share_context,
19                             const int32_t* attrib_list);
20   static PP_Resource CreateRaw(PP_Instance instance,
21                                PP_Resource share_context,
22                                const int32_t* attrib_list);
23
24   // PPB_Graphics3D_API trusted implementation.
25   virtual PP_Bool SetGetBuffer(int32_t transfer_buffer_id) OVERRIDE;
26   virtual gpu::CommandBuffer::State GetState() OVERRIDE;
27   virtual int32_t CreateTransferBuffer(uint32_t size) OVERRIDE;
28   virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE;
29   virtual PP_Bool GetTransferBuffer(int32_t id,
30                                     int* shm_handle,
31                                     uint32_t* shm_size) OVERRIDE;
32   virtual PP_Bool Flush(int32_t put_offset) OVERRIDE;
33   virtual gpu::CommandBuffer::State FlushSync(int32_t put_offset) OVERRIDE;
34   virtual gpu::CommandBuffer::State FlushSyncFast(
35       int32_t put_offset,
36       int32_t last_known_get) OVERRIDE;
37   virtual uint32_t InsertSyncPoint() OVERRIDE;
38
39   // Binds/unbinds the graphics of this context with the associated instance.
40   // Returns true if binding/unbinding is successful.
41   bool BindToInstance(bool bind);
42
43   // Returns true if the backing texture is always opaque.
44   bool IsOpaque();
45
46   // Notifications about the view's progress painting.  See PluginInstance.
47   // These messages are used to send Flush callbacks to the plugin.
48   void ViewInitiatedPaint();
49   void ViewFlushedPaint();
50
51   PlatformContext3D* platform_context() { return platform_context_.get(); }
52
53  protected:
54   virtual ~PPB_Graphics3D_Impl();
55   // ppapi::PPB_Graphics3D_Shared overrides.
56   virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE;
57   virtual gpu::GpuControl* GetGpuControl() OVERRIDE;
58   virtual int32 DoSwapBuffers() OVERRIDE;
59
60  private:
61   explicit PPB_Graphics3D_Impl(PP_Instance instance);
62
63   static PP_Bool IsGpuBlacklisted();
64
65   bool Init(PPB_Graphics3D_API* share_context,
66             const int32_t* attrib_list);
67   bool InitRaw(PPB_Graphics3D_API* share_context,
68                const int32_t* attrib_list);
69
70   // Notifications received from the GPU process.
71   void OnSwapBuffers();
72   void OnContextLost();
73   void OnConsoleMessage(const std::string& msg, int id);
74   // Notifications sent to plugin.
75   void SendContextLost();
76
77   // True if context is bound to instance.
78   bool bound_to_instance_;
79   // True when waiting for compositor to commit our backing texture.
80   bool commit_pending_;
81   // The 3D Context. Responsible for providing the command buffer.
82   scoped_ptr<PlatformContext3D> platform_context_;
83   base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_;
84
85   DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl);
86 };
87
88 }  // namespace content
89
90 #endif  // CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_