summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppb_surface_3d_impl.h
blob: 7f4a7d1993815d747f67c9660d2c7a6fdd1ab983 (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
// 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/thunk/ppb_surface_3d_api.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/resource.h"

namespace gfx {
class Size;
}

namespace webkit {
namespace ppapi {

class PPB_Context3D_Impl;

class PPB_Surface3D_Impl : public Resource,
                           public ::ppapi::thunk::PPB_Surface3D_API {
 public:
  virtual ~PPB_Surface3D_Impl();

  static PP_Resource Create(PluginInstance* instance_id,
                            PP_Config3D_Dev config,
                            const int32_t* attrib_list);

  // ResourceObjectBase override.
  virtual ::ppapi::thunk::PPB_Surface3D_API* AsPPB_Surface3D_API() OVERRIDE;

  // PPB_Surface3D_API implementation.
  virtual int32_t SetAttrib(int32_t attribute, int32_t value) OVERRIDE;
  virtual int32_t GetAttrib(int32_t attribute, int32_t* value) OVERRIDE;
  virtual int32_t SwapBuffers(PP_CompletionCallback callback) OVERRIDE;

  PPB_Context3D_Impl* 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(PPB_Context3D_Impl* context);

  unsigned int GetBackingTextureId();

  void ViewInitiatedPaint();
  void ViewFlushedPaint();
  void OnContextLost();

 private:
  explicit PPB_Surface3D_Impl(PluginInstance* instance);

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

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

  bool bound_to_instance_;

  // True when the page's SwapBuffers has been issued but not returned yet.
  bool swap_initiated_;
  PP_CompletionCallback swap_callback_;

  // The context this surface is currently bound to.
  PPB_Context3D_Impl* context_;

  DISALLOW_COPY_AND_ASSIGN(PPB_Surface3D_Impl);
};

}  // namespace ppapi
}  // namespace webkit

#endif  // WEBKIT_PLUGINS_PPAPI_PPB_SURFACE_3D_IMPL_H_