summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppb_context_3d_impl.h
blob: 2b3e66eaa16deeb1f3dc3ab905ec5298048803c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBKIT_PLUGINS_PPAPI_PPB_CONTEXT_3D_IMPL_H_
#define WEBKIT_PLUGINS_PPAPI_PPB_CONTEXT_3D_IMPL_H_

#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
#include "ppapi/c/dev/ppb_context_3d_dev.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/resource.h"

struct PPB_Context3DTrusted_Dev;

namespace gpu {
class CommandBuffer;
namespace gles2 {
class GLES2CmdHelper;
class GLES2Implementation;
}  // namespace gles2
}  // namespace gpu

namespace webkit {
namespace ppapi {

class PPB_Surface3D_Impl;

class PPB_Context3D_Impl : public Resource {
 public:
  explicit PPB_Context3D_Impl(PluginInstance* instance);
  virtual ~PPB_Context3D_Impl();

  static const PPB_Context3D_Dev* GetInterface();
  static const PPB_Context3DTrusted_Dev* GetTrustedInterface();

  // Resource override.
  virtual PPB_Context3D_Impl* AsPPB_Context3D_Impl();

  bool Init(PP_Config3D_Dev config,
            PP_Resource share_context,
            const int32_t* attrib_list);
  bool InitRaw(PP_Config3D_Dev config,
               PP_Resource share_context,
               const int32_t* attrib_list);

  PluginInstance* instance() {
    return instance_;
  }

  PluginDelegate::PlatformContext3D* platform_context() {
    return platform_context_.get();
  }

  gpu::gles2::GLES2Implementation* gles2_impl() {
    return gles2_impl_.get();
  }

  gpu::CommandBuffer* command_buffer();

  int32_t BindSurfaces(PPB_Surface3D_Impl* draw,
                       PPB_Surface3D_Impl* read);

 private:
  void Destroy();
  bool CreateImplementation();
  void OnContextLost();

  // Plugin instance this context is associated with.
  PluginInstance* instance_;

  // PluginDelegate's 3D Context. Responsible for providing the command buffer.
  scoped_ptr<PluginDelegate::PlatformContext3D> platform_context_;

  scoped_ptr<gpu::gles2::GLES2CmdHelper> helper_;
  int32 transfer_buffer_id_;
  scoped_ptr<gpu::gles2::GLES2Implementation> gles2_impl_;

  PPB_Surface3D_Impl* draw_surface_;
  PPB_Surface3D_Impl* read_surface_;

  base::ScopedCallbackFactory<PPB_Context3D_Impl> callback_factory_;

  DISALLOW_COPY_AND_ASSIGN(PPB_Context3D_Impl);
};

}  // namespace ppapi
}  // namespace webkit

#endif  // WEBKIT_PLUGINS_PPAPI_PPB_CONTEXT_3D_IMPL_H_