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 @@
#include "ppapi/c/dev/ppp_video_decoder_dev.h"
#include "ppapi/c/pp_errors.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/module.h"
#include "ppapi/cpp/module_impl.h"
......@@ -31,6 +32,15 @@ VideoDecoder_Dev::VideoDecoder_Dev(const Instance& instance,
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) {
}
......
......@@ -15,6 +15,7 @@
namespace pp {
class Context3D_Dev;
class Graphics3D_Dev;
class Instance;
// C++ wrapper for the Pepper Video Decoder interface. For more detailed
......@@ -24,9 +25,12 @@ class Instance;
class VideoDecoder_Dev : public Resource {
public:
// See PPB_VideoDecoder_Dev::Create.
explicit VideoDecoder_Dev(const Instance& instance,
const Context3D_Dev& context,
const PP_VideoConfigElement* config);
VideoDecoder_Dev(const Instance& instance,
const Context3D_Dev& context,
const PP_VideoConfigElement* config);
VideoDecoder_Dev(const Instance& instance,
const Graphics3D_Dev& context,
const PP_VideoConfigElement* config);
explicit VideoDecoder_Dev(PP_Resource resource);
virtual ~VideoDecoder_Dev();
......
......@@ -11,6 +11,7 @@
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppb_buffer_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/resource_creation_api.h"
#include "ppapi/thunk/thunk.h"
......@@ -18,6 +19,7 @@
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Buffer_API;
using ppapi::thunk::PPB_Context3D_API;
using ppapi::thunk::PPB_Graphics3D_API;
using ppapi::thunk::PPB_VideoDecoder_API;
namespace ppapi {
......@@ -30,7 +32,7 @@ class VideoDecoder : public Resource, public VideoDecoderImpl {
virtual ~VideoDecoder();
static VideoDecoder* Create(const HostResource& resource,
PP_Resource context3d_id,
PP_Resource graphics_context,
const PP_VideoConfigElement* config);
// Resource overrides.
......@@ -206,7 +208,8 @@ bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) {
}
PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource(
PP_Instance instance, PP_Resource context3d_id,
PP_Instance instance,
PP_Resource graphics_context,
const PP_VideoConfigElement* config) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
// 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(
if (!VideoDecoderImpl::CopyConfigsToVector(config, &copied))
return 0;
EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true);
if (enter_context.failed())
return 0;
Context3D* ppb_context =
static_cast<Context3D*>(enter_context.object());
HostResource host_context = ppb_context->host_resource();
HostResource host_context;
gpu::gles2::GLES2Implementation* gles2_impl = NULL;
EnterResourceNoLock<PPB_Context3D_API> enter_context(graphics_context, false);
if (enter_context.succeeded()) {
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;
dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create(
......@@ -234,13 +248,12 @@ PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource(
// Need a scoped_refptr to keep the object alive during the Init call.
scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result));
if (!decoder->Init(context3d_id, enter_context.object(), config))
return 0;
decoder->InitCommon(graphics_context, gles2_impl);
return decoder->GetReference();
}
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,
HostResource* result) {
thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation(instance,
......@@ -254,7 +267,7 @@ void PPB_VideoDecoder_Proxy::OnMsgCreate(
// Make the resource and get the API pointer to its interface.
result->SetHostResource(
instance, resource_creation.functions()->CreateVideoDecoder(
instance, context3d_id.host_resource(), &copied.front()));
instance, graphics_context.host_resource(), &copied.front()));
}
void PPB_VideoDecoder_Proxy::OnMsgDecode(
......@@ -275,7 +288,7 @@ void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers(
const PP_PictureBuffer_Dev* buffer_array = &buffers.front();
ppb_video_decoder_target()->AssignPictureBuffers(
decoder.host_resource(), buffers.size(), buffer_array);
decoder.host_resource(), buffers.size(), buffer_array);
}
void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer(
......
......@@ -24,7 +24,8 @@ class PPB_VideoDecoder_Proxy : public InterfaceProxy {
// Creates a VideoDecoder object in the plugin process.
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.
virtual bool OnMessageReceived(const IPC::Message& msg);
......@@ -37,7 +38,7 @@ class PPB_VideoDecoder_Proxy : public InterfaceProxy {
// Message handlers in the renderer process to receive messages from the
// plugin process.
void OnMsgCreate(PP_Instance instance,
const ppapi::HostResource& context3d_id,
const ppapi::HostResource& graphics_context,
const std::vector<PP_VideoConfigElement>& config,
ppapi::HostResource* result);
void OnMsgDecode(
......
......@@ -19,30 +19,27 @@ namespace ppapi {
VideoDecoderImpl::VideoDecoderImpl()
: flush_callback_(PP_MakeCompletionCallback(NULL, NULL)),
reset_callback_(PP_MakeCompletionCallback(NULL, NULL)),
context3d_id_(0),
graphics_context_(0),
gles2_impl_(NULL) {
}
VideoDecoderImpl::~VideoDecoderImpl() {
}
bool VideoDecoderImpl::Init(PP_Resource context3d_id,
PPB_Context3D_API* context3d,
const PP_VideoConfigElement* decoder_config) {
if (!context3d || !decoder_config || !context3d_id)
return false;
DCHECK(!gles2_impl_ && !context3d_id_);
gles2_impl_ = context3d->GetGLES2Impl();
TrackerBase::Get()->GetResourceTracker()->AddRefResource(context3d_id);
context3d_id_ = context3d_id;
return true;
void VideoDecoderImpl::InitCommon(
PP_Resource graphics_context,
gpu::gles2::GLES2Implementation* gles2_impl) {
DCHECK(graphics_context);
DCHECK(!gles2_impl_ && !graphics_context_);
gles2_impl_ = gles2_impl;
TrackerBase::Get()->GetResourceTracker()->AddRefResource(graphics_context);
graphics_context_ = graphics_context;
}
void VideoDecoderImpl::Destroy() {
context3d_id_ = 0;
graphics_context_ = 0;
gles2_impl_ = NULL;
TrackerBase::Get()->GetResourceTracker()->ReleaseResource(context3d_id_);
TrackerBase::Get()->GetResourceTracker()->ReleaseResource(graphics_context_);
}
bool VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) {
......
......@@ -57,10 +57,9 @@ class PPAPI_SHARED_EXPORT VideoDecoderImpl
// Tell command buffer to process all commands it has received so far.
void FlushCommandBuffer();
// Initialize the underlying decoder and return success status.
virtual bool Init(PP_Resource context3d_id,
thunk::PPB_Context3D_API* context,
const PP_VideoConfigElement* dec_config);
// Initialize the underlying decoder.
void InitCommon(PP_Resource graphics_context,
gpu::gles2::GLES2Implementation* gles2_impl);
private:
// Key: bitstream_buffer_id, value: callback to run when bitstream decode is
......@@ -73,7 +72,7 @@ class PPAPI_SHARED_EXPORT VideoDecoderImpl
// The resource ID of the underlying Context3d object being used. Used only
// 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_|.
// Context3D is guaranteed to be alive for the lifetime of this class.
......
......@@ -57,6 +57,10 @@ class PPB_Graphics3D_Impl : public ::ppapi::Resource,
void ViewInitiatedPaint();
void ViewFlushedPaint();
PluginDelegate::PlatformContext3D* platform_context() {
return platform_context_.get();
}
protected:
// ppapi::Graphics3DImpl overrides.
virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE;
......
......@@ -22,11 +22,13 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_buffer_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"
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Buffer_API;
using ppapi::thunk::PPB_Context3D_API;
using ppapi::thunk::PPB_Graphics3D_API;
using ppapi::thunk::PPB_VideoDecoder_API;
namespace webkit {
......@@ -51,41 +53,49 @@ PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() {
// static
PP_Resource PPB_VideoDecoder_Impl::Create(PP_Instance instance,
PP_Resource context3d_id,
PP_Resource graphics_context,
const PP_VideoConfigElement* config) {
if (!context3d_id)
return 0;
EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true);
if (enter_context.failed())
return 0;
PluginDelegate::PlatformContext3D* platform_context = NULL;
gpu::gles2::GLES2Implementation* gles2_impl = NULL;
EnterResourceNoLock<PPB_Context3D_API> enter_context(graphics_context, false);
if (enter_context.succeeded()) {
PPB_Context3D_Impl* context3d_impl =
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(
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 0;
}
bool PPB_VideoDecoder_Impl::Init(PP_Resource context3d_id,
PPB_Context3D_API* context3d,
const PP_VideoConfigElement* config) {
if (!::ppapi::VideoDecoderImpl::Init(context3d_id, context3d, config))
bool PPB_VideoDecoder_Impl::Init(
PP_Resource graphics_context,
PluginDelegate::PlatformContext3D* context,
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;
std::vector<int32> copied;
if (!CopyConfigsToVector(config, &copied))
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);
if (!plugin_delegate)
return false;
......
......@@ -48,7 +48,7 @@ class PPB_VideoDecoder_Impl : public ::ppapi::Resource,
// See PPB_VideoDecoder_Dev::Create. Returns 0 on failure to create &
// initialize.
static PP_Resource Create(PP_Instance instance,
PP_Resource context3d_id,
PP_Resource graphics_context,
const PP_VideoConfigElement* config);
// Resource overrides.
......@@ -77,14 +77,12 @@ class PPB_VideoDecoder_Impl : public ::ppapi::Resource,
virtual void NotifyEndOfBitstreamBuffer(int32 buffer_id) 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:
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
// 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