| Index: webkit/plugins/ppapi/ppb_surface_3d_impl.cc
|
| ===================================================================
|
| --- webkit/plugins/ppapi/ppb_surface_3d_impl.cc (revision 89672)
|
| +++ webkit/plugins/ppapi/ppb_surface_3d_impl.cc (working copy)
|
| @@ -14,14 +14,28 @@
|
| #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
|
| #include "webkit/plugins/ppapi/ppb_context_3d_impl.h"
|
|
|
| +using ppapi::thunk::PPB_Surface3D_API;
|
| +
|
| namespace webkit {
|
| namespace ppapi {
|
|
|
| -namespace {
|
| +PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance)
|
| + : Resource(instance),
|
| + bound_to_instance_(false),
|
| + swap_initiated_(false),
|
| + swap_callback_(PP_BlockUntilComplete()),
|
| + context_(NULL) {
|
| +}
|
|
|
| -PP_Resource Create(PP_Instance instance_id,
|
| - PP_Config3D_Dev config,
|
| - const int32_t* attrib_list) {
|
| +PPB_Surface3D_Impl::~PPB_Surface3D_Impl() {
|
| + if (context_)
|
| + context_->BindSurfaces(NULL, NULL);
|
| +}
|
| +
|
| +// static
|
| +PP_Resource PPB_Surface3D_Impl::Create(PP_Instance instance_id,
|
| + PP_Config3D_Dev config,
|
| + const int32_t* attrib_list) {
|
| PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
|
| if (!instance)
|
| return 0;
|
| @@ -30,66 +44,45 @@
|
| new PPB_Surface3D_Impl(instance));
|
| if (!surface->Init(config, attrib_list))
|
| return 0;
|
| -
|
| return surface->GetReference();
|
| }
|
|
|
| -PP_Bool IsSurface3D(PP_Resource resource) {
|
| - return BoolToPPBool(!!Resource::GetAs<PPB_Surface3D_Impl>(resource));
|
| +PPB_Surface3D_API* PPB_Surface3D_Impl::AsPPB_Surface3D_API() {
|
| + return this;
|
| }
|
|
|
| -int32_t SetAttrib(PP_Resource surface_id,
|
| - int32_t attribute,
|
| - int32_t value) {
|
| +int32_t PPB_Surface3D_Impl::SetAttrib(int32_t attribute, int32_t value) {
|
| // TODO(alokp): Implement me.
|
| return 0;
|
| }
|
|
|
| -int32_t GetAttrib(PP_Resource surface_id,
|
| - int32_t attribute,
|
| - int32_t* value) {
|
| +int32_t PPB_Surface3D_Impl::GetAttrib(int32_t attribute, int32_t* value) {
|
| // TODO(alokp): Implement me.
|
| return 0;
|
| }
|
|
|
| -int32_t SwapBuffers(PP_Resource surface_id,
|
| - PP_CompletionCallback callback) {
|
| - scoped_refptr<PPB_Surface3D_Impl> surface(
|
| - Resource::GetAs<PPB_Surface3D_Impl>(surface_id));
|
| - return surface->SwapBuffers(callback);
|
| -}
|
| +int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) {
|
| + if (!context_)
|
| + return PP_ERROR_FAILED;
|
|
|
| -const PPB_Surface3D_Dev ppb_surface3d = {
|
| - &Create,
|
| - &IsSurface3D,
|
| - &SetAttrib,
|
| - &GetAttrib,
|
| - &SwapBuffers
|
| -};
|
| + if (swap_callback_.func) {
|
| + // Already a pending SwapBuffers that hasn't returned yet.
|
| + return PP_ERROR_INPROGRESS;
|
| + }
|
|
|
| -} // namespace
|
| + if (!callback.func) {
|
| + // Blocking SwapBuffers isn't supported (since we have to be on the main
|
| + // thread).
|
| + return PP_ERROR_BADARGUMENT;
|
| + }
|
|
|
| -PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance)
|
| - : Resource(instance),
|
| - bound_to_instance_(false),
|
| - swap_initiated_(false),
|
| - swap_callback_(PP_BlockUntilComplete()),
|
| - context_(NULL) {
|
| + swap_callback_ = callback;
|
| + gpu::gles2::GLES2Implementation* impl = context_->gles2_impl();
|
| + if (impl)
|
| + context_->gles2_impl()->SwapBuffers();
|
| + return PP_OK_COMPLETIONPENDING;
|
| }
|
|
|
| -PPB_Surface3D_Impl::~PPB_Surface3D_Impl() {
|
| - if (context_)
|
| - context_->BindSurfaces(NULL, NULL);
|
| -}
|
| -
|
| -const PPB_Surface3D_Dev* PPB_Surface3D_Impl::GetInterface() {
|
| - return &ppb_surface3d;
|
| -}
|
| -
|
| -PPB_Surface3D_Impl* PPB_Surface3D_Impl::AsPPB_Surface3D_Impl() {
|
| - return this;
|
| -}
|
| -
|
| bool PPB_Surface3D_Impl::Init(PP_Config3D_Dev config,
|
| const int32_t* attrib_list) {
|
| return true;
|
| @@ -100,16 +93,14 @@
|
| return true;
|
| }
|
|
|
| -bool PPB_Surface3D_Impl::BindToContext(
|
| - PPB_Context3D_Impl* context) {
|
| +bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) {
|
| if (context == context_)
|
| return true;
|
|
|
| // Unbind from the current context.
|
| - if (context_) {
|
| + if (context_ && context_->platform_context())
|
| context_->platform_context()->SetSwapBuffersCallback(NULL);
|
| - }
|
| - if (context) {
|
| + if (context && context->platform_context()) {
|
| // Resize the backing texture to the size of the instance when it is bound.
|
| // TODO(alokp): This should be the responsibility of plugins.
|
| gpu::gles2::GLES2Implementation* impl = context->gles2_impl();
|
| @@ -125,29 +116,6 @@
|
| return true;
|
| }
|
|
|
| -int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) {
|
| - if (!context_)
|
| - return PP_ERROR_FAILED;
|
| -
|
| - if (swap_callback_.func) {
|
| - // Already a pending SwapBuffers that hasn't returned yet.
|
| - return PP_ERROR_INPROGRESS;
|
| - }
|
| -
|
| - if (!callback.func) {
|
| - // Blocking SwapBuffers isn't supported (since we have to be on the main
|
| - // thread).
|
| - return PP_ERROR_BADARGUMENT;
|
| - }
|
| -
|
| - swap_callback_ = callback;
|
| - gpu::gles2::GLES2Implementation* impl = context_->gles2_impl();
|
| - if (impl) {
|
| - context_->gles2_impl()->SwapBuffers();
|
| - }
|
| - return PP_OK_COMPLETIONPENDING;
|
| -}
|
| -
|
| void PPB_Surface3D_Impl::ViewInitiatedPaint() {
|
| }
|
|
|
|
|