Commit 1b2ec22e authored by piman@chromium.org's avatar piman@chromium.org

Allow both Context3D and Graphics3D with the video decoder

BUG=none
TEST=Pepper Flash


Review URL: http://codereview.chromium.org/7765011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98742 0039d316-1c4b-4281-b951-d872f2087c98
parent 2854079e
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ppapi/c/dev/ppp_video_decoder_dev.h" #include "ppapi/c/dev/ppp_video_decoder_dev.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/dev/context_3d_dev.h" #include "ppapi/cpp/dev/context_3d_dev.h"
#include "ppapi/cpp/dev/graphics_3d_dev.h"
#include "ppapi/cpp/instance.h" #include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h" #include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/module_impl.h"
...@@ -31,6 +32,15 @@ VideoDecoder_Dev::VideoDecoder_Dev(const Instance& instance, ...@@ -31,6 +32,15 @@ VideoDecoder_Dev::VideoDecoder_Dev(const Instance& instance,
instance.pp_instance(), context.pp_resource(), config)); instance.pp_instance(), context.pp_resource(), config));
} }
VideoDecoder_Dev::VideoDecoder_Dev(const Instance& instance,
const Graphics3D_Dev& context,
const PP_VideoConfigElement* config) {
if (!has_interface<PPB_VideoDecoder_Dev>())
return;
PassRefFromConstructor(get_interface<PPB_VideoDecoder_Dev>()->Create(
instance.pp_instance(), context.pp_resource(), config));
}
VideoDecoder_Dev::VideoDecoder_Dev(PP_Resource resource) : Resource(resource) { VideoDecoder_Dev::VideoDecoder_Dev(PP_Resource resource) : Resource(resource) {
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
namespace pp { namespace pp {
class Context3D_Dev; class Context3D_Dev;
class Graphics3D_Dev;
class Instance; class Instance;
// C++ wrapper for the Pepper Video Decoder interface. For more detailed // C++ wrapper for the Pepper Video Decoder interface. For more detailed
...@@ -24,9 +25,12 @@ class Instance; ...@@ -24,9 +25,12 @@ class Instance;
class VideoDecoder_Dev : public Resource { class VideoDecoder_Dev : public Resource {
public: public:
// See PPB_VideoDecoder_Dev::Create. // See PPB_VideoDecoder_Dev::Create.
explicit VideoDecoder_Dev(const Instance& instance, VideoDecoder_Dev(const Instance& instance,
const Context3D_Dev& context, const Context3D_Dev& context,
const PP_VideoConfigElement* config); const PP_VideoConfigElement* config);
VideoDecoder_Dev(const Instance& instance,
const Graphics3D_Dev& context,
const PP_VideoConfigElement* config);
explicit VideoDecoder_Dev(PP_Resource resource); explicit VideoDecoder_Dev(PP_Resource resource);
virtual ~VideoDecoder_Dev(); virtual ~VideoDecoder_Dev();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppb_buffer_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h"
#include "ppapi/proxy/ppb_context_3d_proxy.h" #include "ppapi/proxy/ppb_context_3d_proxy.h"
#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
#include "ppapi/thunk/enter.h" #include "ppapi/thunk/enter.h"
#include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/resource_creation_api.h"
#include "ppapi/thunk/thunk.h" #include "ppapi/thunk/thunk.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Buffer_API; using ppapi::thunk::PPB_Buffer_API;
using ppapi::thunk::PPB_Context3D_API; using ppapi::thunk::PPB_Context3D_API;
using ppapi::thunk::PPB_Graphics3D_API;
using ppapi::thunk::PPB_VideoDecoder_API; using ppapi::thunk::PPB_VideoDecoder_API;
namespace ppapi { namespace ppapi {
...@@ -30,7 +32,7 @@ class VideoDecoder : public Resource, public VideoDecoderImpl { ...@@ -30,7 +32,7 @@ class VideoDecoder : public Resource, public VideoDecoderImpl {
virtual ~VideoDecoder(); virtual ~VideoDecoder();
static VideoDecoder* Create(const HostResource& resource, static VideoDecoder* Create(const HostResource& resource,
PP_Resource context3d_id, PP_Resource graphics_context,
const PP_VideoConfigElement* config); const PP_VideoConfigElement* config);
// Resource overrides. // Resource overrides.
...@@ -206,7 +208,8 @@ bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) { ...@@ -206,7 +208,8 @@ bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) {
} }
PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource(
PP_Instance instance, PP_Resource context3d_id, PP_Instance instance,
PP_Resource graphics_context,
const PP_VideoConfigElement* config) { const PP_VideoConfigElement* config) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
// Dispatcher is null if it cannot find the instance passed to it (i.e. if the // Dispatcher is null if it cannot find the instance passed to it (i.e. if the
...@@ -218,12 +221,23 @@ PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( ...@@ -218,12 +221,23 @@ PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource(
if (!VideoDecoderImpl::CopyConfigsToVector(config, &copied)) if (!VideoDecoderImpl::CopyConfigsToVector(config, &copied))
return 0; return 0;
EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); HostResource host_context;
if (enter_context.failed()) gpu::gles2::GLES2Implementation* gles2_impl = NULL;
return 0;
Context3D* ppb_context = EnterResourceNoLock<PPB_Context3D_API> enter_context(graphics_context, false);
static_cast<Context3D*>(enter_context.object()); if (enter_context.succeeded()) {
HostResource host_context = ppb_context->host_resource(); Context3D* context = static_cast<Context3D*>(enter_context.object());
host_context = context->host_resource();
gles2_impl = context->gles2_impl();
} else {
EnterResourceNoLock<PPB_Graphics3D_API> enter_context(graphics_context,
true);
if (enter_context.failed())
return 0;
Graphics3D* context = static_cast<Graphics3D*>(enter_context.object());
host_context = context->host_resource();
gles2_impl = context->gles2_impl();
}
HostResource result; HostResource result;
dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create( dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create(
...@@ -234,13 +248,12 @@ PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( ...@@ -234,13 +248,12 @@ PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource(
// Need a scoped_refptr to keep the object alive during the Init call. // Need a scoped_refptr to keep the object alive during the Init call.
scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result)); scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result));
if (!decoder->Init(context3d_id, enter_context.object(), config)) decoder->InitCommon(graphics_context, gles2_impl);
return 0;
return decoder->GetReference(); return decoder->GetReference();
} }
void PPB_VideoDecoder_Proxy::OnMsgCreate( void PPB_VideoDecoder_Proxy::OnMsgCreate(
PP_Instance instance, const HostResource& context3d_id, PP_Instance instance, const HostResource& graphics_context,
const std::vector<PP_VideoConfigElement>& config, const std::vector<PP_VideoConfigElement>& config,
HostResource* result) { HostResource* result) {
thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation(instance, thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation(instance,
...@@ -254,7 +267,7 @@ void PPB_VideoDecoder_Proxy::OnMsgCreate( ...@@ -254,7 +267,7 @@ void PPB_VideoDecoder_Proxy::OnMsgCreate(
// Make the resource and get the API pointer to its interface. // Make the resource and get the API pointer to its interface.
result->SetHostResource( result->SetHostResource(
instance, resource_creation.functions()->CreateVideoDecoder( instance, resource_creation.functions()->CreateVideoDecoder(
instance, context3d_id.host_resource(), &copied.front())); instance, graphics_context.host_resource(), &copied.front()));
} }
void PPB_VideoDecoder_Proxy::OnMsgDecode( void PPB_VideoDecoder_Proxy::OnMsgDecode(
...@@ -275,7 +288,7 @@ void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers( ...@@ -275,7 +288,7 @@ void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers(
const PP_PictureBuffer_Dev* buffer_array = &buffers.front(); const PP_PictureBuffer_Dev* buffer_array = &buffers.front();
ppb_video_decoder_target()->AssignPictureBuffers( ppb_video_decoder_target()->AssignPictureBuffers(
decoder.host_resource(), buffers.size(), buffer_array); decoder.host_resource(), buffers.size(), buffer_array);
} }
void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer( void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer(
......
...@@ -24,7 +24,8 @@ class PPB_VideoDecoder_Proxy : public InterfaceProxy { ...@@ -24,7 +24,8 @@ class PPB_VideoDecoder_Proxy : public InterfaceProxy {
// Creates a VideoDecoder object in the plugin process. // Creates a VideoDecoder object in the plugin process.
static PP_Resource CreateProxyResource(PP_Instance instance, static PP_Resource CreateProxyResource(PP_Instance instance,
PP_Resource context3d_id, const PP_VideoConfigElement* config); PP_Resource graphics_context,
const PP_VideoConfigElement* config);
// InterfaceProxy implementation. // InterfaceProxy implementation.
virtual bool OnMessageReceived(const IPC::Message& msg); virtual bool OnMessageReceived(const IPC::Message& msg);
...@@ -37,7 +38,7 @@ class PPB_VideoDecoder_Proxy : public InterfaceProxy { ...@@ -37,7 +38,7 @@ class PPB_VideoDecoder_Proxy : public InterfaceProxy {
// Message handlers in the renderer process to receive messages from the // Message handlers in the renderer process to receive messages from the
// plugin process. // plugin process.
void OnMsgCreate(PP_Instance instance, void OnMsgCreate(PP_Instance instance,
const ppapi::HostResource& context3d_id, const ppapi::HostResource& graphics_context,
const std::vector<PP_VideoConfigElement>& config, const std::vector<PP_VideoConfigElement>& config,
ppapi::HostResource* result); ppapi::HostResource* result);
void OnMsgDecode( void OnMsgDecode(
......
...@@ -19,30 +19,27 @@ namespace ppapi { ...@@ -19,30 +19,27 @@ namespace ppapi {
VideoDecoderImpl::VideoDecoderImpl() VideoDecoderImpl::VideoDecoderImpl()
: flush_callback_(PP_MakeCompletionCallback(NULL, NULL)), : flush_callback_(PP_MakeCompletionCallback(NULL, NULL)),
reset_callback_(PP_MakeCompletionCallback(NULL, NULL)), reset_callback_(PP_MakeCompletionCallback(NULL, NULL)),
context3d_id_(0), graphics_context_(0),
gles2_impl_(NULL) { gles2_impl_(NULL) {
} }
VideoDecoderImpl::~VideoDecoderImpl() { VideoDecoderImpl::~VideoDecoderImpl() {
} }
bool VideoDecoderImpl::Init(PP_Resource context3d_id, void VideoDecoderImpl::InitCommon(
PPB_Context3D_API* context3d, PP_Resource graphics_context,
const PP_VideoConfigElement* decoder_config) { gpu::gles2::GLES2Implementation* gles2_impl) {
if (!context3d || !decoder_config || !context3d_id) DCHECK(graphics_context);
return false; DCHECK(!gles2_impl_ && !graphics_context_);
gles2_impl_ = gles2_impl;
DCHECK(!gles2_impl_ && !context3d_id_); TrackerBase::Get()->GetResourceTracker()->AddRefResource(graphics_context);
gles2_impl_ = context3d->GetGLES2Impl(); graphics_context_ = graphics_context;
TrackerBase::Get()->GetResourceTracker()->AddRefResource(context3d_id);
context3d_id_ = context3d_id;
return true;
} }
void VideoDecoderImpl::Destroy() { void VideoDecoderImpl::Destroy() {
context3d_id_ = 0; graphics_context_ = 0;
gles2_impl_ = NULL; gles2_impl_ = NULL;
TrackerBase::Get()->GetResourceTracker()->ReleaseResource(context3d_id_); TrackerBase::Get()->GetResourceTracker()->ReleaseResource(graphics_context_);
} }
bool VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { bool VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) {
......
...@@ -57,10 +57,9 @@ class PPAPI_SHARED_EXPORT VideoDecoderImpl ...@@ -57,10 +57,9 @@ class PPAPI_SHARED_EXPORT VideoDecoderImpl
// Tell command buffer to process all commands it has received so far. // Tell command buffer to process all commands it has received so far.
void FlushCommandBuffer(); void FlushCommandBuffer();
// Initialize the underlying decoder and return success status. // Initialize the underlying decoder.
virtual bool Init(PP_Resource context3d_id, void InitCommon(PP_Resource graphics_context,
thunk::PPB_Context3D_API* context, gpu::gles2::GLES2Implementation* gles2_impl);
const PP_VideoConfigElement* dec_config);
private: private:
// Key: bitstream_buffer_id, value: callback to run when bitstream decode is // Key: bitstream_buffer_id, value: callback to run when bitstream decode is
...@@ -73,7 +72,7 @@ class PPAPI_SHARED_EXPORT VideoDecoderImpl ...@@ -73,7 +72,7 @@ class PPAPI_SHARED_EXPORT VideoDecoderImpl
// The resource ID of the underlying Context3d object being used. Used only // The resource ID of the underlying Context3d object being used. Used only
// for reference counting to keep it alive for the lifetime of |*this|. // for reference counting to keep it alive for the lifetime of |*this|.
PP_Resource context3d_id_; PP_Resource graphics_context_;
// Reference to the GLES2Implementation owned by |context3d_id_|. // Reference to the GLES2Implementation owned by |context3d_id_|.
// Context3D is guaranteed to be alive for the lifetime of this class. // Context3D is guaranteed to be alive for the lifetime of this class.
......
...@@ -57,6 +57,10 @@ class PPB_Graphics3D_Impl : public ::ppapi::Resource, ...@@ -57,6 +57,10 @@ class PPB_Graphics3D_Impl : public ::ppapi::Resource,
void ViewInitiatedPaint(); void ViewInitiatedPaint();
void ViewFlushedPaint(); void ViewFlushedPaint();
PluginDelegate::PlatformContext3D* platform_context() {
return platform_context_.get();
}
protected: protected:
// ppapi::Graphics3DImpl overrides. // ppapi::Graphics3DImpl overrides.
virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE; virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE;
......
...@@ -22,11 +22,13 @@ ...@@ -22,11 +22,13 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_buffer_impl.h" #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
#include "webkit/plugins/ppapi/ppb_context_3d_impl.h" #include "webkit/plugins/ppapi/ppb_context_3d_impl.h"
#include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
#include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/plugins/ppapi/resource_tracker.h"
using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Buffer_API; using ppapi::thunk::PPB_Buffer_API;
using ppapi::thunk::PPB_Context3D_API; using ppapi::thunk::PPB_Context3D_API;
using ppapi::thunk::PPB_Graphics3D_API;
using ppapi::thunk::PPB_VideoDecoder_API; using ppapi::thunk::PPB_VideoDecoder_API;
namespace webkit { namespace webkit {
...@@ -51,41 +53,49 @@ PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { ...@@ -51,41 +53,49 @@ PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() {
// static // static
PP_Resource PPB_VideoDecoder_Impl::Create(PP_Instance instance, PP_Resource PPB_VideoDecoder_Impl::Create(PP_Instance instance,
PP_Resource context3d_id, PP_Resource graphics_context,
const PP_VideoConfigElement* config) { const PP_VideoConfigElement* config) {
if (!context3d_id) PluginDelegate::PlatformContext3D* platform_context = NULL;
return 0; gpu::gles2::GLES2Implementation* gles2_impl = NULL;
EnterResourceNoLock<PPB_Context3D_API> enter_context(graphics_context, false);
EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); if (enter_context.succeeded()) {
if (enter_context.failed()) PPB_Context3D_Impl* context3d_impl =
return 0; static_cast<PPB_Context3D_Impl*>(enter_context.object());
platform_context = context3d_impl->platform_context();
gles2_impl = context3d_impl->gles2_impl();
} else {
EnterResourceNoLock<PPB_Graphics3D_API> enter_context(graphics_context,
true);
if (enter_context.failed())
return 0;
PPB_Graphics3D_Impl* graphics3d_impl =
static_cast<PPB_Graphics3D_Impl*>(enter_context.object());
platform_context = graphics3d_impl->platform_context();
gles2_impl = graphics3d_impl->gles2_impl();
}
scoped_refptr<PPB_VideoDecoder_Impl> decoder( scoped_refptr<PPB_VideoDecoder_Impl> decoder(
new PPB_VideoDecoder_Impl(instance)); new PPB_VideoDecoder_Impl(instance));
if (decoder->Init(context3d_id, enter_context.object(), config)) if (decoder->Init(graphics_context, platform_context, gles2_impl, config))
return decoder->GetReference(); return decoder->GetReference();
return 0; return 0;
} }
bool PPB_VideoDecoder_Impl::Init(PP_Resource context3d_id, bool PPB_VideoDecoder_Impl::Init(
PPB_Context3D_API* context3d, PP_Resource graphics_context,
const PP_VideoConfigElement* config) { PluginDelegate::PlatformContext3D* context,
if (!::ppapi::VideoDecoderImpl::Init(context3d_id, context3d, config)) gpu::gles2::GLES2Implementation* gles2_impl,
const PP_VideoConfigElement* config) {
InitCommon(graphics_context, gles2_impl);
int command_buffer_route_id = context->GetCommandBufferRouteId();
if (command_buffer_route_id == 0)
return false; return false;
std::vector<int32> copied; std::vector<int32> copied;
if (!CopyConfigsToVector(config, &copied)) if (!CopyConfigsToVector(config, &copied))
return false; return false;
PPB_Context3D_Impl* context3d_impl =
static_cast<PPB_Context3D_Impl*>(context3d);
int command_buffer_route_id =
context3d_impl->platform_context()->GetCommandBufferRouteId();
if (command_buffer_route_id == 0)
return false;
PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
if (!plugin_delegate) if (!plugin_delegate)
return false; return false;
......
...@@ -48,7 +48,7 @@ class PPB_VideoDecoder_Impl : public ::ppapi::Resource, ...@@ -48,7 +48,7 @@ class PPB_VideoDecoder_Impl : public ::ppapi::Resource,
// See PPB_VideoDecoder_Dev::Create. Returns 0 on failure to create & // See PPB_VideoDecoder_Dev::Create. Returns 0 on failure to create &
// initialize. // initialize.
static PP_Resource Create(PP_Instance instance, static PP_Resource Create(PP_Instance instance,
PP_Resource context3d_id, PP_Resource graphics_context,
const PP_VideoConfigElement* config); const PP_VideoConfigElement* config);
// Resource overrides. // Resource overrides.
...@@ -77,14 +77,12 @@ class PPB_VideoDecoder_Impl : public ::ppapi::Resource, ...@@ -77,14 +77,12 @@ class PPB_VideoDecoder_Impl : public ::ppapi::Resource,
virtual void NotifyEndOfBitstreamBuffer(int32 buffer_id) OVERRIDE; virtual void NotifyEndOfBitstreamBuffer(int32 buffer_id) OVERRIDE;
virtual void NotifyResetDone() OVERRIDE; virtual void NotifyResetDone() OVERRIDE;
protected:
// VideoDecoderImpl implementation.
virtual bool Init(PP_Resource context3d_id,
::ppapi::thunk::PPB_Context3D_API* context,
const PP_VideoConfigElement* dec_config) OVERRIDE;
private: private:
explicit PPB_VideoDecoder_Impl(PP_Instance instance); explicit PPB_VideoDecoder_Impl(PP_Instance instance);
bool Init(PP_Resource graphics_context,
PluginDelegate::PlatformContext3D* context,
gpu::gles2::GLES2Implementation* gles2_impl,
const PP_VideoConfigElement* config);
// This is NULL before initialization, and if this PPB_VideoDecoder_Impl is // This is NULL before initialization, and if this PPB_VideoDecoder_Impl is
// swapped with another. // swapped with another.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment