blob: 250911b326de382e583ef764999211fef33dc8cf [file] [log] [blame]
[email protected]eeb4e4a2011-07-19 16:22:061// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]5bba4dc22010-08-17 19:45:282// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]0bd753682010-12-16 18:15:525#ifndef WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_
6#define WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_
[email protected]5bba4dc22010-08-17 19:45:287
[email protected]fa48a62b2011-10-07 21:45:328#include "base/memory/weak_ptr.h"
[email protected]eeb4e4a2011-07-19 16:22:069#include "ppapi/shared_impl/graphics_3d_impl.h"
[email protected]bbf076f12011-08-24 15:19:3710#include "ppapi/shared_impl/resource.h"
[email protected]eeb4e4a2011-07-19 16:22:0611#include "webkit/plugins/ppapi/plugin_delegate.h"
[email protected]5bba4dc22010-08-17 19:45:2812
[email protected]0bd753682010-12-16 18:15:5213namespace webkit {
14namespace ppapi {
[email protected]5bba4dc22010-08-17 19:45:2815
[email protected]bbf076f12011-08-24 15:19:3716class PPB_Graphics3D_Impl : public ::ppapi::Resource,
[email protected]eeb4e4a2011-07-19 16:22:0617 public ::ppapi::Graphics3DImpl {
[email protected]5bba4dc22010-08-17 19:45:2818 public:
[email protected]66789462011-04-07 20:07:1819 virtual ~PPB_Graphics3D_Impl();
20
[email protected]bbf076f12011-08-24 15:19:3721 static PP_Resource Create(PP_Instance instance,
[email protected]e18e6392011-06-22 20:57:0022 PP_Resource share_context,
23 const int32_t* attrib_list);
[email protected]bbf076f12011-08-24 15:19:3724 static PP_Resource CreateRaw(PP_Instance instance,
[email protected]eeb4e4a2011-07-19 16:22:0625 PP_Resource share_context,
26 const int32_t* attrib_list);
[email protected]66789462011-04-07 20:07:1827
[email protected]7f8b26b2011-08-18 15:41:0128 // Resource override.
[email protected]e18e6392011-06-22 20:57:0029 virtual ::ppapi::thunk::PPB_Graphics3D_API* AsPPB_Graphics3D_API() OVERRIDE;
30
[email protected]eeb4e4a2011-07-19 16:22:0631 // PPB_Graphics3D_API trusted implementation.
32 virtual PP_Bool InitCommandBuffer(int32_t size) OVERRIDE;
33 virtual PP_Bool GetRingBuffer(int* shm_handle,
34 uint32_t* shm_size) OVERRIDE;
35 virtual PP_Graphics3DTrustedState GetState() OVERRIDE;
36 virtual int32_t CreateTransferBuffer(uint32_t size) OVERRIDE;
37 virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE;
38 virtual PP_Bool GetTransferBuffer(int32_t id,
39 int* shm_handle,
40 uint32_t* shm_size) OVERRIDE;
41 virtual PP_Bool Flush(int32_t put_offset) OVERRIDE;
42 virtual PP_Graphics3DTrustedState FlushSync(int32_t put_offset) OVERRIDE;
43 virtual PP_Graphics3DTrustedState FlushSyncFast(
44 int32_t put_offset,
45 int32_t last_known_get) OVERRIDE;
46
47 // Binds/unbinds the graphics of this context with the associated instance.
48 // Returns true if binding/unbinding is successful.
49 bool BindToInstance(bool bind);
50
51 // Returns the id of texture that can be used by the compositor.
52 unsigned int GetBackingTextureId();
53
54 // Notifications that the view has rendered the page and that it has been
55 // flushed to the screen. These messages are used to send Flush callbacks to
56 // the plugin.
57 void ViewInitiatedPaint();
58 void ViewFlushedPaint();
59
[email protected]1b2ec22e2011-08-30 00:48:3360 PluginDelegate::PlatformContext3D* platform_context() {
61 return platform_context_.get();
62 }
63
[email protected]eeb4e4a2011-07-19 16:22:0664 protected:
65 // ppapi::Graphics3DImpl overrides.
66 virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE;
67 virtual int32 DoSwapBuffers() OVERRIDE;
[email protected]e18e6392011-06-22 20:57:0068
69 private:
[email protected]bbf076f12011-08-24 15:19:3770 explicit PPB_Graphics3D_Impl(PP_Instance instance);
[email protected]66789462011-04-07 20:07:1871
[email protected]9d8fe822011-08-16 21:02:5272 bool Init(PP_Resource share_context,
[email protected]66789462011-04-07 20:07:1873 const int32_t* attrib_list);
[email protected]9d8fe822011-08-16 21:02:5274 bool InitRaw(PP_Resource share_context,
[email protected]eeb4e4a2011-07-19 16:22:0675 const int32_t* attrib_list);
76
77 // Notifications received from the GPU process.
78 void OnSwapBuffers();
79 void OnContextLost();
80 // Notifications sent to plugin.
81 void SendContextLost();
82
83 // True if context is bound to instance.
84 bool bound_to_instance_;
85 // True when waiting for compositor to commit our backing texture.
86 bool commit_pending_;
87 // PluginDelegate's 3D Context. Responsible for providing the command buffer.
88 scoped_ptr<PluginDelegate::PlatformContext3D> platform_context_;
[email protected]fa48a62b2011-10-07 21:45:3289 base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_;
[email protected]66789462011-04-07 20:07:1890
[email protected]66789462011-04-07 20:07:1891 DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl);
[email protected]5bba4dc22010-08-17 19:45:2892};
93
[email protected]0bd753682010-12-16 18:15:5294} // namespace ppapi
95} // namespace webkit
[email protected]5bba4dc22010-08-17 19:45:2896
[email protected]0bd753682010-12-16 18:15:5297#endif // WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_