summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppb_surface_3d_impl.h
blob: d09689ed48d984d035b70daaf54afdec7aa9544b (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
// Copyright (c) 2010 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_SURFACE_3D_IMPL_H_
#define WEBKIT_PLUGINS_PPAPI_PPB_SURFACE_3D_IMPL_H_

#include "base/callback.h"
#include "ppapi/c/dev/ppb_surface_3d_dev.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/resource.h"

namespace gfx {
class Size;
}

namespace webkit {
namespace ppapi {

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

  static const PPB_Surface3D_Dev* GetInterface();

  // Resource override.
  virtual PPB_Surface3D_Impl* AsPPB_Surface3D_Impl();

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

  PluginInstance* instance() const {
    return instance_;
  }
  PluginDelegate::PlatformContext3D* context() const {
    return context_;
  }

  // Binds/unbinds the graphics of this surface with the associated instance.
  // If the surface is bound, anything drawn on the surface appears on instance
  // window. Returns true if binding/unbinding is successful.
  bool BindToInstance(bool bind);

  // Binds the context such that all draw calls to context
  // affect this surface. To unbind call this function will NULL context.
  // Returns true if successful.
  bool BindToContext(PluginDelegate::PlatformContext3D* context);

  unsigned int GetBackingTextureId();

  bool SwapBuffers();

 private:
  // Called when SwapBuffers is complete.
  void OnSwapBuffers();

  // Plugin instance this surface is associated with.
  PluginInstance* instance_;
  bool bound_to_instance_;

  // The context this surface is currently bound to.
  PluginDelegate::PlatformContext3D* context_;

  DISALLOW_COPY_AND_ASSIGN(PPB_Surface3D_Impl);
};

}  // namespace ppapi
}  // namespace webkit

#endif  // WEBKIT_PLUGINS_PPAPI_PPB_SURFACE_3D_IMPL_H_