Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: webkit/plugins/ppapi/ppb_surface_3d_impl.cc

Issue 6047008: Added ppapi::Surface3D. This CL completes the new Pepper3D interface. The imp... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h"
6
7 #include "gpu/command_buffer/common/command_buffer.h"
8 #include "ppapi/c/dev/ppb_graphics_3d_dev.h"
9 #include "webkit/plugins/ppapi/common.h"
10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
11
12 namespace webkit {
13 namespace ppapi {
14
15 namespace {
16
17 PP_Resource Create(PP_Instance instance_id,
18 PP_Config3D_Dev config,
19 const int32_t* attrib_list) {
20 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
21 if (!instance)
22 return 0;
23
24 scoped_refptr<PPB_Surface3D_Impl> surface(
25 new PPB_Surface3D_Impl(instance));
26 if (!surface->Init(config, attrib_list))
27 return 0;
28
29 return surface->GetReference();
30 }
31
32 PP_Bool IsSurface3D(PP_Resource resource) {
33 return BoolToPPBool(!!Resource::GetAs<PPB_Surface3D_Impl>(resource));
34 }
35
36 int32_t SetAttrib(PP_Resource surface_id,
37 int32_t attribute,
38 int32_t value) {
39 // TODO(alokp): Implement me.
40 return 0;
41 }
42
43 int32_t GetAttrib(PP_Resource surface_id,
44 int32_t attribute,
45 int32_t* value) {
46 // TODO(alokp): Implement me.
47 return 0;
48 }
49
50 int32_t SwapBuffers(PP_Resource surface_id,
51 PP_CompletionCallback callback) {
52 scoped_refptr<PPB_Surface3D_Impl> surface(
53 Resource::GetAs<PPB_Surface3D_Impl>(surface_id));
54 return surface->SwapBuffers();
55 }
56
57 const PPB_Surface3D_Dev ppb_surface3d = {
58 &Create,
59 &IsSurface3D,
60 &SetAttrib,
61 &GetAttrib,
62 &SwapBuffers
63 };
64
65 } // namespace
66
67 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance)
68 : Resource(instance->module()),
69 instance_(instance),
70 bound_to_instance_(false),
71 context_(NULL) {
72 }
73
74 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() {
75 }
76
77 const PPB_Surface3D_Dev* PPB_Surface3D_Impl::GetInterface() {
78 return &ppb_surface3d;
79 }
80
81 PPB_Surface3D_Impl* PPB_Surface3D_Impl::AsPPB_Surface3D_Impl() {
82 return this;
83 }
84
85 bool PPB_Surface3D_Impl::Init(PP_Config3D_Dev config,
86 const int32_t* attrib_list) {
87 return true;
88 }
89
90 bool PPB_Surface3D_Impl::BindToInstance(bool bind) {
91 bound_to_instance_ = bind;
92 return true;
93 }
94
95 bool PPB_Surface3D_Impl::BindToContext(
96 PluginDelegate::PlatformContext3D* context) {
97 if (context == context_)
98 return true;
99
100 // Unbind from the current context.
101 if (context_) {
102 context_->SetSwapBuffersCallback(NULL);
103 }
104 if (context) {
105 // Resize the backing texture to the size of the instance when it is bound.
106 // TODO(alokp): This should be the responsibility of plugins.
107 context->ResizeBackingTexture(instance()->position().size());
108
109 // This is a temporary hack. The SwapBuffers is issued to force the resize
110 // to take place before any subsequent rendering. This might lead to a
111 // partially rendered frame being displayed. It is also not thread safe
112 // since the SwapBuffers is written to the command buffer and that command
113 // buffer might be written to by another thread.
114 // TODO(apatrick): Figure out the semantics of binding and resizing.
115 context->SwapBuffers();
116
117 context->SetSwapBuffersCallback(
118 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers));
119 }
120 context_ = context;
121 return true;
122 }
123
124 bool PPB_Surface3D_Impl::SwapBuffers() {
125 return context_ && context_->SwapBuffers();
126 }
127
128 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() {
129 return context_ ? context_->GetBackingTextureId() : 0;
130 }
131
132 void PPB_Surface3D_Impl::OnSwapBuffers() {
133 if (bound_to_instance_)
134 instance()->CommitBackingTexture();
135 }
136
137 } // namespace ppapi
138 } // namespace webkit
139
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698