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 WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_
6 #define WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_
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 #include "webkit/plugins/ppapi/plugin_delegate.h"
16 class PPB_Graphics3D_Impl
: public ::ppapi::PPB_Graphics3D_Shared
{
18 virtual ~PPB_Graphics3D_Impl();
20 static PP_Resource
Create(PP_Instance instance
,
21 PP_Resource share_context
,
22 const int32_t* attrib_list
);
23 static PP_Resource
CreateRaw(PP_Instance instance
,
24 PP_Resource share_context
,
25 const int32_t* attrib_list
);
27 // PPB_Graphics3D_API trusted implementation.
28 virtual PP_Bool
InitCommandBuffer() OVERRIDE
;
29 virtual PP_Bool
SetGetBuffer(int32_t transfer_buffer_id
) OVERRIDE
;
30 virtual PP_Graphics3DTrustedState
GetState() OVERRIDE
;
31 virtual int32_t CreateTransferBuffer(uint32_t size
) OVERRIDE
;
32 virtual PP_Bool
DestroyTransferBuffer(int32_t id
) OVERRIDE
;
33 virtual PP_Bool
GetTransferBuffer(int32_t id
,
35 uint32_t* shm_size
) OVERRIDE
;
36 virtual PP_Bool
Flush(int32_t put_offset
) OVERRIDE
;
37 virtual PP_Graphics3DTrustedState
FlushSync(int32_t put_offset
) OVERRIDE
;
38 virtual PP_Graphics3DTrustedState
FlushSyncFast(
40 int32_t last_known_get
) OVERRIDE
;
41 virtual uint32_t InsertSyncPoint() 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 the id of texture that can be used by the compositor.
48 unsigned int GetBackingTextureId();
50 // Returns true if the backing texture is always opaque.
53 // Notifications about the view's progress painting. See PluginInstance.
54 // These messages are used to send Flush callbacks to the plugin.
55 void ViewWillInitiatePaint();
56 void ViewInitiatedPaint();
57 void ViewFlushedPaint();
59 PluginDelegate::PlatformContext3D
* platform_context() {
60 return platform_context_
.get();
64 // ppapi::PPB_Graphics3D_Shared overrides.
65 virtual gpu::CommandBuffer
* GetCommandBuffer() OVERRIDE
;
66 virtual int32
DoSwapBuffers() OVERRIDE
;
69 explicit PPB_Graphics3D_Impl(PP_Instance instance
);
71 static PP_Bool
IsGpuBlacklisted();
73 bool Init(PPB_Graphics3D_API
* share_context
,
74 const int32_t* attrib_list
);
75 bool InitRaw(PPB_Graphics3D_API
* share_context
,
76 const int32_t* attrib_list
);
78 // Notifications received from the GPU process.
81 void OnConsoleMessage(const std::string
& msg
, int id
);
82 // Notifications sent to plugin.
83 void SendContextLost();
85 // True if context is bound to instance.
86 bool bound_to_instance_
;
87 // True when waiting for compositor to commit our backing texture.
89 // PluginDelegate's 3D Context. Responsible for providing the command buffer.
90 scoped_ptr
<PluginDelegate::PlatformContext3D
> platform_context_
;
91 base::WeakPtrFactory
<PPB_Graphics3D_Impl
> weak_ptr_factory_
;
93 DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl
);
99 #endif // WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_