diff options
author | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-28 18:02:10 +0000 |
---|---|---|
committer | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-28 18:02:10 +0000 |
commit | 900b20d4a4d98d511989879f90ef78f26d77e60e (patch) | |
tree | eeab6121361ae55f2344ec8bf823aaef9b2fc0a3 | |
parent | 37f858dbc0411f0b69f9a524ae6f4d89d3bc886b (diff) | |
download | chromium_src-900b20d4a4d98d511989879f90ef78f26d77e60e.zip chromium_src-900b20d4a4d98d511989879f90ef78f26d77e60e.tar.gz chromium_src-900b20d4a4d98d511989879f90ef78f26d77e60e.tar.bz2 |
Added ppapi::Surface3D. This CL completes the new Pepper3D interface. The implementation is still incomplete but all gpu demos still work!
Review URL: http://codereview.chromium.org/6047008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70229 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | gpu/demos/framework/pepper.cc | 14 | ||||
-rw-r--r-- | ppapi/c/dev/ppb_context_3d_dev.h | 6 | ||||
-rw-r--r-- | ppapi/c/dev/ppb_surface_3d_dev.h | 111 | ||||
-rw-r--r-- | ppapi/cpp/dev/context_3d_dev.cc | 18 | ||||
-rw-r--r-- | ppapi/cpp/dev/context_3d_dev.h | 6 | ||||
-rw-r--r-- | ppapi/cpp/dev/surface_3d_dev.cc | 50 | ||||
-rw-r--r-- | ppapi/cpp/dev/surface_3d_dev.h | 37 | ||||
-rw-r--r-- | ppapi/cpp/instance.cc | 4 | ||||
-rw-r--r-- | ppapi/cpp/instance.h | 5 | ||||
-rw-r--r-- | ppapi/ppapi.gyp | 3 | ||||
-rw-r--r-- | ppapi/tests/all_c_includes.h | 1 | ||||
-rw-r--r-- | ppapi/tests/all_cpp_includes.h | 2 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 30 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 8 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_context_3d_impl.cc | 115 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_context_3d_impl.h | 42 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_surface_3d_impl.cc | 139 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_surface_3d_impl.h | 71 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource.h | 1 |
21 files changed, 522 insertions, 146 deletions
diff --git a/gpu/demos/framework/pepper.cc b/gpu/demos/framework/pepper.cc index 8c9e43a..ce698d5 100644 --- a/gpu/demos/framework/pepper.cc +++ b/gpu/demos/framework/pepper.cc @@ -13,6 +13,7 @@ #include "ppapi/cpp/size.h" #include "ppapi/cpp/dev/context_3d_dev.h" #include "ppapi/cpp/dev/graphics_3d_dev.h" +#include "ppapi/cpp/dev/surface_3d_dev.h" #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" namespace gpu { @@ -50,13 +51,17 @@ class PluginInstance : public pp::Instance { if (context_.is_null()) return; - if (!pp::Instance::BindGraphics(context_)) - return; - glSetCurrentContextPPAPI(context_.pp_resource()); demo_->InitGL(); glSetCurrentContextPPAPI(0); + } else { + // Need to recreate surface. Unbind existing surface. + pp::Instance::BindGraphics(pp::Surface3D_Dev()); + context_.BindSurfaces(pp::Surface3D_Dev(), pp::Surface3D_Dev()); } + surface_ = pp::Surface3D_Dev(*this, 0, NULL); + context_.BindSurfaces(surface_, surface_); + pp::Instance::BindGraphics(surface_); if (demo_->IsAnimated()) Animate(0); @@ -67,7 +72,7 @@ class PluginInstance : public pp::Instance { void Paint() { glSetCurrentContextPPAPI(context_.pp_resource()); demo_->Draw(); - context_.SwapBuffers(); + surface_.SwapBuffers(); glSetCurrentContextPPAPI(0); } @@ -81,6 +86,7 @@ class PluginInstance : public pp::Instance { pp::Module* module_; Demo* demo_; pp::Context3D_Dev context_; + pp::Surface3D_Dev surface_; pp::Size size_; pp::CompletionCallbackFactory<PluginInstance> callback_factory_; }; diff --git a/ppapi/c/dev/ppb_context_3d_dev.h b/ppapi/c/dev/ppb_context_3d_dev.h index 79969a3..11a3b66 100644 --- a/ppapi/c/dev/ppb_context_3d_dev.h +++ b/ppapi/c/dev/ppb_context_3d_dev.h @@ -92,7 +92,7 @@ struct PPB_Context3D_Dev { // - PP_GRAPHICS3DERROR_BAD_CONTEXT: if context is not a valid context. // - PP_GRAPHICS3DERROR_BAD_SURFACE: if either draw or read are not valid // surfaces. - // - PP_GRAPHICS3DERROR_BAD_MATCH:fIf draw and read cannot fit into + // - PP_GRAPHICS3DERROR_BAD_MATCH: if draw and read cannot fit into // graphics memory simultaneously. // - PP_ERROR_NOMEMORY: if the ancillary buffers for draw and read cannot // be allocated. @@ -119,10 +119,6 @@ struct PPB_Context3D_Dev { int32_t (*GetBoundSurfaces)(PP_Resource context, PP_Resource* draw, PP_Resource* read); - - // TODO(alokp): Move to PPB_Surface3D_Dev - int32_t (*SwapBuffers)(PP_Resource context, - struct PP_CompletionCallback callback); }; #endif // PPAPI_C_DEV_PPB_CONTEXT_3D_DEV_H_ diff --git a/ppapi/c/dev/ppb_surface_3d_dev.h b/ppapi/c/dev/ppb_surface_3d_dev.h new file mode 100644 index 0000000..9618bdd --- /dev/null +++ b/ppapi/c/dev/ppb_surface_3d_dev.h @@ -0,0 +1,111 @@ +/* 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 PPAPI_C_DEV_PPB_SURFACE_3D_DEV_H_ +#define PPAPI_C_DEV_PPB_SURFACE_3D_DEV_H_ + +#include "ppapi/c/dev/pp_graphics_3d_dev.h" +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_resource.h" + +#define PPB_SURFACE_3D_DEV_INTERFACE "PPB_Surface3D(Dev);0.1" + +struct PPB_Surface3D_Dev { + // Creates a render surface and returns a handle to it. + // Any PPB_Context3D_Dev created with a compatible PP_Config3D_Dev + // can be used to render into this surface. The returned surface is + // off-screen to start with. It must be attached to a plugin instance + // using PPB_Instance::BindGraphics to draw on the web page. + // + // attrib_list specifies a list of attributes for the surface. The list has + // the same structure as described for PPB_Graphics3D_Dev::GetConfigAttribs. + // Attributes that can be specified in attrib_list include: + // - PP_GRAPHICS3DATTRIB_WIDTH + // - PP_GRAPHICS3DATTRIB_HEIGHT + // - PP_GRAPHICS3DATTRIB_LARGEST_SURFACE: If true, creates the largest + // possible surface when the allocation of the surface would otherwise fail. + // The width and height of the allocated surface will never exceed the + // values of PP_GRAPHICS3DATTRIB_WIDTH and PP_GRAPHICS3DATTRIB_HEIGHT, + // respectively. If this option is used, PPB_Surface3D_Dev::GetAttrib + // can be used to retrieve surface dimensions. + // - PP_GRAPHICS3DATTRIB_RENDER_BUFFER + PP_Resource (*Create)(PP_Instance instance, + PP_Config3D_Dev config, + const int32_t* attrib_list); + + // Returns PP_TRUE if the given resource is a valid Surface3D, PP_FALSE if it + // is an invalid resource or is a resource of another type. + PP_Bool (*IsSurface3D)(PP_Resource resource); + + // Sets an attribute for PPB_Surface3D_Dev. The specified attribute of + // surface is set to value. Attributes that can be specified are: + // - PP_GRAPHICS3DATTRIB_MULTISAMPLE_RESOLVE: If value + // is PP_GRAPHICS3DATTRIBVALUE_MULTISAMPLE_RESOLVE_BOX, and the + // PP_GRAPHICS3DATTRIB_SURFACE_TYPE attribute used to create surface does + // not contain PP_GRAPHICS3DATTRIBVALUE_MULTISAMPLE_RESOLVE_BOX_BIT, a + // PP_GRAPHICS3DERROR_BAD_MATCH error is returned. + // - PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR: If value is + // PP_GRAPHICS3DATTRIBVALUE_BUFFER_PRESERVED, and the + // PP_GRAPHICS3DATTRIB_SURFACE_TYPE attribute used to create surface + // does not contain PP_GRAPHICS3DATTRIBVALUE_SWAP_BEHAVIOR_PRESERVED_BIT, + // a PP_GRAPHICS3DERROR_BAD_MATCH error is returned. + int32_t (*SetAttrib)(PP_Resource surface, + int32_t attribute, + int32_t value); + + // Retrieves the value of attribute for surface. Attributes that can be + // queried for are: + // - PP_GRAPHICS3DATTRIB_CONFIG_ID: returns the ID of the + // PP_Config3D_Dev with respect to which the surface was created. + // - PP_GRAPHICS3DATTRIB_LARGEST_SURFACE: returns the same attribute value + // specified when the surface was created with PPB_Surface3D_Dev::Create. + // - PP_GRAPHICS3DATTRIB_WIDTH and PP_GRAPHICS3DATTRIB_HEIGHT: The returned + // size may be less than the requested size if + // PP_GRAPHICS3DATTRIB_LARGEST_SURFACE is true. + // - PP_GRAPHICS3DATTRIB_RENDER_BUFFER + // - PP_GRAPHICS3DATTRIB_MULTISAMPLE_RESOLVE + // - PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR + // + // If attribute is not a valid PPB_Surface3D_Dev surface attribute, + // then an PP_GRAPHICS3DERROR_BAD_ATTRIBUTE error is returned. If surface + // is not a valid PPB_Surface3D_Dev then an PP_GRAPHICS3DERROR_BAD_SURFACE + // error is returned. + int32_t (*GetAttrib)(PP_Resource surface, + int32_t attribute, + int32_t* value); + + // Makes the contents of the color buffer available for compositing. + // This function has no effect on off-screen surfaces - ones not bound + // to any plugin instance. The contents of ancillary buffers are always + // undefined after calling SwapBuffers. The contents of the color buffer are + // undefined if the value of the PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR attribute + // of surface is not PP_GRAPHICS3DATTRIBVALUE_BUFFER_PRESERVED. + // + // If surface is bound as the draw surface of a context then SwapBuffers + // performs an implicit flush operation on the context. + // + // This functions can run in two modes: + // - In synchronous mode, you specify NULL for the callback and the callback + // data. This function will block the calling thread until the image has + // been painted to the screen. It is not legal to block the main thread of + // the plugin, you can use synchronous mode only from background threads. + // - In asynchronous mode, you specify a callback function and the argument + // for that callback function. The callback function will be executed on + // the calling thread when the image has been painted to the screen. While + // you are waiting for a Flush callback, additional calls to Flush will + // fail. + // + // Because the callback is executed (or thread unblocked) only when the + // plugin's current state is actually on the screen, this function provides a + // way to rate limit animations. By waiting until the image is on the screen + // before painting the next frame, you can ensure you're not generating + // updates faster than the screen can be updated. + // + int32_t (*SwapBuffers)(PP_Resource surface, + struct PP_CompletionCallback callback); +}; + +#endif // PPAPI_C_DEV_PPB_SURFACE_3D_DEV_H_ diff --git a/ppapi/cpp/dev/context_3d_dev.cc b/ppapi/cpp/dev/context_3d_dev.cc index 47f51ac..4847642 100644 --- a/ppapi/cpp/dev/context_3d_dev.cc +++ b/ppapi/cpp/dev/context_3d_dev.cc @@ -4,9 +4,8 @@ #include "ppapi/cpp/dev/context_3d_dev.h" -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/dev/ppb_opengles_dev.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/dev/surface_3d_dev.h" #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module_impl.h" @@ -18,10 +17,6 @@ template <> const char* interface_name<PPB_Context3D_Dev>() { return PPB_CONTEXT_3D_DEV_INTERFACE; } -template <> const char* interface_name<PPB_OpenGLES2_Dev>() { - return PPB_OPENGLES2_DEV_INTERFACE; -} - } // namespace Context3D_Dev Context3D_Dev::FromResource(PP_Resource resource_id) { @@ -36,8 +31,7 @@ Context3D_Dev::Context3D_Dev(const Instance& instance, PP_Config3D_Dev config, const Context3D_Dev& share_context, const int32_t* attrib_list) { - if (has_interface<PPB_Context3D_Dev>() && - has_interface<PPB_OpenGLES2_Dev>()) { + if (has_interface<PPB_Context3D_Dev>()) { PassRefFromConstructor(get_interface<PPB_Context3D_Dev>()->Create( instance.pp_instance(), config, @@ -46,13 +40,13 @@ Context3D_Dev::Context3D_Dev(const Instance& instance, } } -int32_t Context3D_Dev::SwapBuffers() const { +int32_t Context3D_Dev::BindSurfaces(const Surface3D_Dev& draw, + const Surface3D_Dev& read) { if (!has_interface<PPB_Context3D_Dev>()) return PP_ERROR_NOINTERFACE; - return get_interface<PPB_Context3D_Dev>()->SwapBuffers( - pp_resource(), - PP_BlockUntilComplete()); + return get_interface<PPB_Context3D_Dev>()->BindSurfaces( + pp_resource(), draw.pp_resource(), read.pp_resource()); } } // namespace pp diff --git a/ppapi/cpp/dev/context_3d_dev.h b/ppapi/cpp/dev/context_3d_dev.h index 51881f3..60521d0 100644 --- a/ppapi/cpp/dev/context_3d_dev.h +++ b/ppapi/cpp/dev/context_3d_dev.h @@ -12,7 +12,7 @@ namespace pp { -class CompletionCallback; +class Surface3D_Dev; class Context3D_Dev : public Resource { public: @@ -24,8 +24,8 @@ class Context3D_Dev : public Resource { const Context3D_Dev& share_context, const int32_t* attrib_list); - // TODO(alokp): Move to Surface3D. - int32_t SwapBuffers() const; + int32_t BindSurfaces(const Surface3D_Dev& draw, + const Surface3D_Dev& read); protected: explicit Context3D_Dev(PP_Resource resource_id) : Resource(resource_id) {} diff --git a/ppapi/cpp/dev/surface_3d_dev.cc b/ppapi/cpp/dev/surface_3d_dev.cc new file mode 100644 index 0000000..a222683 --- /dev/null +++ b/ppapi/cpp/dev/surface_3d_dev.cc @@ -0,0 +1,50 @@ +// 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. + +#include "ppapi/cpp/dev/surface_3d_dev.h" + +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Surface3D_Dev>() { + return PPB_SURFACE_3D_DEV_INTERFACE; +} + +} // namespace + +Surface3D_Dev Surface3D_Dev::FromResource(PP_Resource resource_id) { + if (has_interface<PPB_Surface3D_Dev>() && + get_interface<PPB_Surface3D_Dev>()->IsSurface3D(resource_id)) + return Surface3D_Dev(resource_id); + + return Surface3D_Dev(); +} + +Surface3D_Dev::Surface3D_Dev(const Instance& instance, + PP_Config3D_Dev config, + const int32_t* attrib_list) { + if (has_interface<PPB_Surface3D_Dev>()) { + PassRefFromConstructor(get_interface<PPB_Surface3D_Dev>()->Create( + instance.pp_instance(), + config, + attrib_list)); + } +} + +int32_t Surface3D_Dev::SwapBuffers() const { + if (!has_interface<PPB_Surface3D_Dev>()) + return PP_ERROR_NOINTERFACE; + + return get_interface<PPB_Surface3D_Dev>()->SwapBuffers( + pp_resource(), + PP_BlockUntilComplete()); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/surface_3d_dev.h b/ppapi/cpp/dev/surface_3d_dev.h new file mode 100644 index 0000000..ff7c809 --- /dev/null +++ b/ppapi/cpp/dev/surface_3d_dev.h @@ -0,0 +1,37 @@ +// 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 PPAPI_CPP_DEV_SURFACE_3D_DEV_H_ +#define PPAPI_CPP_DEV_SURFACE_3D_DEV_H_ + +#include "ppapi/c/dev/ppb_surface_3d_dev.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; + +class Surface3D_Dev : public Resource { + public: + // Creates an is_null() Surface3D object. + Surface3D_Dev() {} + + Surface3D_Dev(const Instance& instance, + PP_Config3D_Dev config, + const int32_t* attrib_list); + + // TODO(alokp): Add completion callback. + int32_t SwapBuffers() const; + + protected: + explicit Surface3D_Dev(PP_Resource resource_id) : Resource(resource_id) {} + static Surface3D_Dev FromResource(PP_Resource resource_id); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_SURFACE_3D_DEV_H_ + diff --git a/ppapi/cpp/instance.cc b/ppapi/cpp/instance.cc index 369b277..72676d1 100644 --- a/ppapi/cpp/instance.cc +++ b/ppapi/cpp/instance.cc @@ -7,7 +7,7 @@ #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/ppb_instance.h" #include "ppapi/cpp/common.h" -#include "ppapi/cpp/dev/context_3d_dev.h" +#include "ppapi/cpp/dev/surface_3d_dev.h" #include "ppapi/cpp/graphics_2d.h" #include "ppapi/cpp/image_data.h" #include "ppapi/cpp/logging.h" @@ -91,7 +91,7 @@ bool Instance::BindGraphics(const Graphics2D& graphics) { pp_instance(), graphics.pp_resource())); } -bool Instance::BindGraphics(const Context3D_Dev& graphics) { +bool Instance::BindGraphics(const Surface3D_Dev& graphics) { if (!has_interface<PPB_Instance>()) return false; return PPBoolToBool(get_interface<PPB_Instance>()->BindGraphics( diff --git a/ppapi/cpp/instance.h b/ppapi/cpp/instance.h index 161d6b0..497189f 100644 --- a/ppapi/cpp/instance.h +++ b/ppapi/cpp/instance.h @@ -26,12 +26,12 @@ struct PP_InputEvent; namespace pp { class Graphics2D; -class Context3D_Dev; class ImageData; class Point; class Rect; class Rect; class Resource; +class Surface3D_Dev; class URLLoader; class Var; class Widget_Dev; @@ -89,8 +89,7 @@ class Instance { bool BindGraphics(const Graphics2D& graphics); /** See PPB_Instance.BindGraphics. */ - // TODO(alokp): Change it to Surface3D. - bool BindGraphics(const Context3D_Dev& graphics); + bool BindGraphics(const Surface3D_Dev& graphics); /** See PPB_Instance.IsFullFrame. */ bool IsFullFrame(); diff --git a/ppapi/ppapi.gyp b/ppapi/ppapi.gyp index 0bc5ea0..c8ce7d1 100644 --- a/ppapi/ppapi.gyp +++ b/ppapi/ppapi.gyp @@ -87,6 +87,7 @@ 'c/dev/ppb_graphics_3d_dev.h', 'c/dev/ppb_opengles_dev.h', 'c/dev/ppb_scrollbar_dev.h', + 'c/dev/ppb_surface_3d_dev.h', 'c/dev/ppb_testing_dev.h', 'c/dev/ppb_transport_dev.h', 'c/dev/ppb_url_util_dev.h', @@ -196,6 +197,8 @@ 'cpp/dev/scrollbar_dev.h', 'cpp/dev/selection_dev.cc', 'cpp/dev/selection_dev.h', + 'cpp/dev/surface_3d_dev.cc', + 'cpp/dev/surface_3d_dev.h', 'cpp/dev/transport_dev.cc', 'cpp/dev/transport_dev.h', 'cpp/dev/url_util_dev.cc', diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index 3661bfc..fde2c02 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -32,6 +32,7 @@ #include "ppapi/c/dev/ppb_graphics_3d_dev.h" #include "ppapi/c/dev/ppb_opengles_dev.h" #include "ppapi/c/dev/ppb_scrollbar_dev.h" +#include "ppapi/c/dev/ppb_surface_3d_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_transport_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" diff --git a/ppapi/tests/all_cpp_includes.h b/ppapi/tests/all_cpp_includes.h index b9e634a..c835195 100644 --- a/ppapi/tests/all_cpp_includes.h +++ b/ppapi/tests/all_cpp_includes.h @@ -14,6 +14,7 @@ #include "ppapi/cpp/dev/audio_config_dev.h" #include "ppapi/cpp/dev/audio_dev.h" #include "ppapi/cpp/dev/buffer_dev.h" +#include "ppapi/cpp/dev/context_3d_dev.h" #include "ppapi/cpp/dev/directory_entry_dev.h" #include "ppapi/cpp/dev/directory_reader_dev.h" #include "ppapi/cpp/dev/file_chooser_dev.h" @@ -29,6 +30,7 @@ #include "ppapi/cpp/dev/scriptable_object_deprecated.h" #include "ppapi/cpp/dev/scrollbar_dev.h" #include "ppapi/cpp/dev/selection_dev.h" +#include "ppapi/cpp/dev/surface_3d_dev.h" #include "ppapi/cpp/dev/transport_dev.h" #include "ppapi/cpp/dev/url_util_dev.h" #include "ppapi/cpp/dev/video_decoder_dev.h" diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 959f4e1..44761ba 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -302,6 +302,8 @@ '../plugins/ppapi/ppb_pdf_impl.h', '../plugins/ppapi/ppb_scrollbar_impl.cc', '../plugins/ppapi/ppb_scrollbar_impl.h', + '../plugins/ppapi/ppb_surface_3d_impl.cc', + '../plugins/ppapi/ppb_surface_3d_impl.h', '../plugins/ppapi/ppb_transport_impl.cc', '../plugins/ppapi/ppb_transport_impl.h', '../plugins/ppapi/ppb_url_loader_impl.cc', diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index a21cbf7..250261b 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -87,6 +87,7 @@ #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" #include "webkit/plugins/ppapi/ppb_opengles_impl.h" +#include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" #endif // ENABLE_GPU namespace webkit { @@ -290,6 +291,8 @@ const void* GetInterface(const char* name) { return PPB_Context3D_Impl::GetInterface(); if (strcmp(name, PPB_OPENGLES2_DEV_INTERFACE) == 0) return PPB_OpenGLES_Impl::GetInterface(); + if (strcmp(name, PPB_SURFACE_3D_DEV_INTERFACE) == 0) + return PPB_Surface3D_Impl::GetInterface(); } #endif // ENABLE_GPU diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index e0c8343..2682ac7 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -45,9 +45,9 @@ #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppb_buffer_impl.h" -#include "webkit/plugins/ppapi/ppb_context_3d_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" +#include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" #include "webkit/plugins/ppapi/ppp_pdf.h" #include "webkit/plugins/ppapi/string.h" @@ -430,8 +430,7 @@ bool PluginInstance::BindGraphics(PP_Resource graphics_id) { if (bound_graphics_2d()) { bound_graphics_2d()->BindToInstance(NULL); } else if (bound_graphics_.get()) { - bound_graphics_3d()->SetSwapBuffersCallback(NULL); - bound_graphics_3d()->BindToInstance(NULL); + bound_graphics_3d()->BindToInstance(false); } InvalidateRect(gfx::Rect()); } @@ -441,8 +440,8 @@ bool PluginInstance::BindGraphics(PP_Resource graphics_id) { scoped_refptr<PPB_Graphics2D_Impl> graphics_2d = Resource::GetAs<PPB_Graphics2D_Impl>(graphics_id); - scoped_refptr<PPB_Context3D_Impl> graphics_3d = - Resource::GetAs<PPB_Context3D_Impl>(graphics_id); + scoped_refptr<PPB_Surface3D_Impl> graphics_3d = + Resource::GetAs<PPB_Surface3D_Impl>(graphics_id); if (graphics_2d) { if (!graphics_2d->BindToInstance(this)) @@ -470,12 +469,14 @@ bool PluginInstance::BindGraphics(PP_Resource graphics_id) { bound_graphics_ = graphics_2d; // BindToInstance will have invalidated the plugin if necessary. } else if (graphics_3d) { - if (!graphics_3d->BindToInstance(this)) + // Make sure graphics can only be bound to the instance it is + // associated with. + if (graphics_3d->instance() != this) + return false; + if (!graphics_3d->BindToInstance(true)) return false; bound_graphics_ = graphics_3d; - bound_graphics_3d()->SetSwapBuffersCallback( - NewCallback(this, &PluginInstance::CommitBackingTexture)); } return true; @@ -585,15 +586,6 @@ PP_Var PluginInstance::GetInstanceObject() { void PluginInstance::ViewChanged(const gfx::Rect& position, const gfx::Rect& clip) { - if (position.size() != position_.size() && bound_graphics_3d()) { - // TODO(apatrick): This is a hack to force the back buffer to resize. - // It is obviously wrong to call SwapBuffers when a partial frame has - // potentially been rendered. Plan is to embed resize commands in the - // command buffer just before ViewChanged is called. - bound_graphics_3d()->ResizeBackingTexture(position.size()); - bound_graphics_3d()->SwapBuffers(); - } - position_ = position; if (clip.IsEmpty()) { @@ -1174,11 +1166,11 @@ PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { return bound_graphics_->Cast<PPB_Graphics2D_Impl>(); } -PPB_Context3D_Impl* PluginInstance::bound_graphics_3d() const { +PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { if (bound_graphics_.get() == NULL) return NULL; - return bound_graphics_->Cast<PPB_Context3D_Impl>(); + return bound_graphics_->Cast<PPB_Surface3D_Impl>(); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 801eca6..71a9fe2 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -53,8 +53,8 @@ class FullscreenContainer; class PluginDelegate; class PluginModule; class PPB_Graphics2D_Impl; -class PPB_Context3D_Impl; class PPB_ImageData_Impl; +class PPB_Surface3D_Impl; class PPB_URLLoader_Impl; class Resource; @@ -225,9 +225,9 @@ class PluginInstance : public base::RefCounted<PluginInstance> { // null if the context is not 2D. PPB_Graphics2D_Impl* bound_graphics_2d() const; - // Get the bound graphics context as a concrete 3D graphics context or returns - // null if the context is not 3D. - PPB_Context3D_Impl* bound_graphics_3d() const; + // Get the bound 3D graphics surface. + // Returns NULL if bound graphics is not a 3D surface. + PPB_Surface3D_Impl* bound_graphics_3d() const; PluginDelegate* delegate_; scoped_refptr<PluginModule> module_; diff --git a/webkit/plugins/ppapi/ppb_context_3d_impl.cc b/webkit/plugins/ppapi/ppb_context_3d_impl.cc index 4a7c961..0da5dca 100644 --- a/webkit/plugins/ppapi/ppb_context_3d_impl.cc +++ b/webkit/plugins/ppapi/ppb_context_3d_impl.cc @@ -5,9 +5,9 @@ #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" #include "gpu/command_buffer/common/command_buffer.h" -#include "ppapi/c/dev/ppb_graphics_3d_dev.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" namespace webkit { namespace ppapi { @@ -31,8 +31,8 @@ PP_Resource Create(PP_Instance instance_id, return 0; scoped_refptr<PPB_Context3D_Impl> context( - new PPB_Context3D_Impl(instance->module())); - if (!context->Init(instance, config, share_context, attrib_list)) + new PPB_Context3D_Impl(instance)); + if (!context->Init(config, share_context, attrib_list)) return 0; return context->GetReference(); @@ -49,11 +49,25 @@ int32_t GetAttrib(PP_Resource context, return 0; } -int32_t BindSurfaces(PP_Resource context, +int32_t BindSurfaces(PP_Resource context_id, PP_Resource draw, PP_Resource read) { - // TODO(alokp): Implement me. - return 0; + scoped_refptr<PPB_Context3D_Impl> context( + Resource::GetAs<PPB_Context3D_Impl>(context_id)); + if (!context.get()) + return PP_ERROR_BADRESOURCE; + + scoped_refptr<PPB_Surface3D_Impl> draw_surface( + Resource::GetAs<PPB_Surface3D_Impl>(draw)); + if (!draw_surface.get()) + return PP_ERROR_BADRESOURCE; + + scoped_refptr<PPB_Surface3D_Impl> read_surface( + Resource::GetAs<PPB_Surface3D_Impl>(read)); + if (!read_surface.get()) + return PP_ERROR_BADRESOURCE; + + return context->BindSurfaces(draw_surface.get(), read_surface.get()); } int32_t GetBoundSurfaces(PP_Resource context, @@ -63,28 +77,22 @@ int32_t GetBoundSurfaces(PP_Resource context, return 0; } -int32_t SwapBuffers(PP_Resource context_id, - PP_CompletionCallback callback) { - scoped_refptr<PPB_Context3D_Impl> context( - Resource::GetAs<PPB_Context3D_Impl>(context_id)); - return context->SwapBuffers(); -} - const PPB_Context3D_Dev ppb_context3d = { &Create, &IsContext3D, &GetAttrib, &BindSurfaces, &GetBoundSurfaces, - &SwapBuffers }; } // namespace -PPB_Context3D_Impl::PPB_Context3D_Impl(PluginModule* module) - : Resource(module), - bound_instance_(NULL), - gles2_impl_(NULL) { +PPB_Context3D_Impl::PPB_Context3D_Impl(PluginInstance* instance) + : Resource(instance->module()), + instance_(instance), + gles2_impl_(NULL), + draw_surface_(NULL), + read_surface_(NULL) { } PPB_Context3D_Impl::~PPB_Context3D_Impl() { @@ -99,13 +107,11 @@ PPB_Context3D_Impl* PPB_Context3D_Impl::AsPPB_Context3D_Impl() { return this; } -bool PPB_Context3D_Impl::Init(PluginInstance* instance, - PP_Config3D_Dev config, +bool PPB_Context3D_Impl::Init(PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list) { - DCHECK(instance); // Create and initialize the objects required to issue GLES2 calls. - platform_context_.reset(instance->delegate()->CreateContext3D()); + platform_context_.reset(instance()->delegate()->CreateContext3D()); if (!platform_context_.get()) { Destroy(); return false; @@ -121,58 +127,33 @@ bool PPB_Context3D_Impl::Init(PluginInstance* instance, return true; } -bool PPB_Context3D_Impl::BindToInstance(PluginInstance* new_instance) { - if (bound_instance_ == new_instance) - return true; // Rebinding the same device, nothing to do. - if (bound_instance_ && new_instance) - return false; // Can't change a bound device. - - if (new_instance) { - // Resize the backing texture to the size of the instance when it is bound. - platform_context_->ResizeBackingTexture(new_instance->position().size()); - - // This is a temporary hack. The SwapBuffers is issued to force the resize - // to take place before any subsequent rendering. This might lead to a - // partially rendered frame being displayed. It is also not thread safe - // since the SwapBuffers is written to the command buffer and that command - // buffer might be written to by another thread. - // TODO(apatrick): Figure out the semantics of binding and resizing. - platform_context_->SwapBuffers(); - } +int32_t PPB_Context3D_Impl::BindSurfaces(PPB_Surface3D_Impl* draw, + PPB_Surface3D_Impl* read) { + // TODO(alokp): Support separate draw-read surfaces. + DCHECK_EQ(draw, read); + if (draw != read) + return PP_GRAPHICS3DERROR_BAD_MATCH; - bound_instance_ = new_instance; - return true; -} - -bool PPB_Context3D_Impl::SwapBuffers() { - if (!platform_context_.get()) - return false; - - return platform_context_->SwapBuffers(); -} - -void PPB_Context3D_Impl::SetSwapBuffersCallback(Callback0::Type* callback) { - if (!platform_context_.get()) - return; + if (draw == draw_surface_) + return PP_OK; - platform_context_->SetSwapBuffersCallback(callback); -} - -unsigned int PPB_Context3D_Impl::GetBackingTextureId() { - if (!platform_context_.get()) - return 0; + if (draw && draw->context()) + return PP_GRAPHICS3DERROR_BAD_ACCESS; - return platform_context_->GetBackingTextureId(); -} - -void PPB_Context3D_Impl::ResizeBackingTexture(const gfx::Size& size) { - if (!platform_context_.get()) - return; + if (draw_surface_) + draw_surface_->BindToContext(NULL); + if (draw && !draw->BindToContext(platform_context_.get())) + return PP_ERROR_NOMEMORY; - platform_context_->ResizeBackingTexture(size); + draw_surface_ = draw; + read_surface_ = read; + return PP_OK; } void PPB_Context3D_Impl::Destroy() { + if (draw_surface_) + draw_surface_->BindToContext(NULL); + gles2_impl_ = NULL; platform_context_.reset(); } diff --git a/webkit/plugins/ppapi/ppb_context_3d_impl.h b/webkit/plugins/ppapi/ppb_context_3d_impl.h index f111005..9046368 100644 --- a/webkit/plugins/ppapi/ppb_context_3d_impl.h +++ b/webkit/plugins/ppapi/ppb_context_3d_impl.h @@ -5,16 +5,11 @@ #ifndef WEBKIT_PLUGINS_PPAPI_PPB_CONTEXT_3D_IMPL_H_ #define WEBKIT_PLUGINS_PPAPI_PPB_CONTEXT_3D_IMPL_H_ -#include "base/callback.h" #include "base/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" -namespace gfx { -class Size; -} - namespace gpu { namespace gles2 { class GLES2Implementation; @@ -24,9 +19,11 @@ class GLES2Implementation; namespace webkit { namespace ppapi { +class PPB_Surface3D_Impl; + class PPB_Context3D_Impl : public Resource { public: - explicit PPB_Context3D_Impl(PluginModule* module); + explicit PPB_Context3D_Impl(PluginInstance* instance); virtual ~PPB_Context3D_Impl(); static const PPB_Context3D_Dev* GetInterface(); @@ -34,38 +31,26 @@ class PPB_Context3D_Impl : public Resource { // Resource override. virtual PPB_Context3D_Impl* AsPPB_Context3D_Impl(); - bool Init(PluginInstance* instance, - PP_Config3D_Dev config, + bool Init(PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list); - // Associates this PPB_Context3D_Impl with the given plugin instance. - // You can pass NULL to clear the existing device. Returns true on success. - // In this case, the last rendered frame is displayed. - // - // TODO(alokp): This is confusing. This context is already associated with - // an instance. This function should rather be called BindToInstanceGraphics - // or something similar which means from this point on, anything drawn with - // this context appears on instance window. This function should also not - // take any argument. But this means modifying PPB_Instance::BindGraphics. - bool BindToInstance(PluginInstance* new_instance); - - bool SwapBuffers(); - void SetSwapBuffersCallback(Callback0::Type* callback); - - unsigned int GetBackingTextureId(); - void ResizeBackingTexture(const gfx::Size& size); + PluginInstance* instance() { + return instance_; + } gpu::gles2::GLES2Implementation* gles2_impl() { return gles2_impl_; } + int32_t BindSurfaces(PPB_Surface3D_Impl* draw, + PPB_Surface3D_Impl* read); + private: void Destroy(); - // Non-owning pointer to the plugin instance this context is currently bound - // to, if any. If the context is currently unbound, this will be NULL. - PluginInstance* bound_instance_; + // 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_; @@ -73,6 +58,9 @@ class PPB_Context3D_Impl : public Resource { // GLES2 Implementation instance. Owned by the platform context's GGL context. gpu::gles2::GLES2Implementation* gles2_impl_; + PPB_Surface3D_Impl* draw_surface_; + PPB_Surface3D_Impl* read_surface_; + DISALLOW_COPY_AND_ASSIGN(PPB_Context3D_Impl); }; diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc new file mode 100644 index 0000000..0283d3b --- /dev/null +++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc @@ -0,0 +1,139 @@ +// 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. + +#include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" + +#include "gpu/command_buffer/common/command_buffer.h" +#include "ppapi/c/dev/ppb_graphics_3d_dev.h" +#include "webkit/plugins/ppapi/common.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" + +namespace webkit { +namespace ppapi { + +namespace { + +PP_Resource 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; + + scoped_refptr<PPB_Surface3D_Impl> surface( + 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)); +} + +int32_t SetAttrib(PP_Resource surface_id, + 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) { + // 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(); +} + +const PPB_Surface3D_Dev ppb_surface3d = { + &Create, + &IsSurface3D, + &SetAttrib, + &GetAttrib, + &SwapBuffers +}; + +} // namespace + +PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance) + : Resource(instance->module()), + instance_(instance), + bound_to_instance_(false), + context_(NULL) { +} + +PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { +} + +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; +} + +bool PPB_Surface3D_Impl::BindToInstance(bool bind) { + bound_to_instance_ = bind; + return true; +} + +bool PPB_Surface3D_Impl::BindToContext( + PluginDelegate::PlatformContext3D* context) { + if (context == context_) + return true; + + // Unbind from the current context. + if (context_) { + context_->SetSwapBuffersCallback(NULL); + } + if (context) { + // Resize the backing texture to the size of the instance when it is bound. + // TODO(alokp): This should be the responsibility of plugins. + context->ResizeBackingTexture(instance()->position().size()); + + // This is a temporary hack. The SwapBuffers is issued to force the resize + // to take place before any subsequent rendering. This might lead to a + // partially rendered frame being displayed. It is also not thread safe + // since the SwapBuffers is written to the command buffer and that command + // buffer might be written to by another thread. + // TODO(apatrick): Figure out the semantics of binding and resizing. + context->SwapBuffers(); + + context->SetSwapBuffersCallback( + NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); + } + context_ = context; + return true; +} + +bool PPB_Surface3D_Impl::SwapBuffers() { + return context_ && context_->SwapBuffers(); +} + +unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { + return context_ ? context_->GetBackingTextureId() : 0; +} + +void PPB_Surface3D_Impl::OnSwapBuffers() { + if (bound_to_instance_) + instance()->CommitBackingTexture(); +} + +} // namespace ppapi +} // namespace webkit + diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.h b/webkit/plugins/ppapi/ppb_surface_3d_impl.h new file mode 100644 index 0000000..d09689e --- /dev/null +++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.h @@ -0,0 +1,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_ diff --git a/webkit/plugins/ppapi/resource.h b/webkit/plugins/ppapi/resource.h index be79136..28f19e3 100644 --- a/webkit/plugins/ppapi/resource.h +++ b/webkit/plugins/ppapi/resource.h @@ -31,6 +31,7 @@ namespace ppapi { F(PPB_Graphics3D_Impl) \ F(PPB_ImageData_Impl) \ F(PPB_Scrollbar_Impl) \ + F(PPB_Surface3D_Impl) \ F(PPB_Transport_Impl) \ F(PPB_URLLoader_Impl) \ F(PPB_URLRequestInfo_Impl) \ |