Skip to content

Commit

Permalink
pepper: Use the RenderThread's shared context as the parent context.
Browse files Browse the repository at this point in the history
Remove the PepperParentContextProvider interface entirely. Have the
pepper PlatformContext3DImpl go directly to RenderThreadImpl and get
the offscreen shared context, and create its texture with that context
and make it the parent of the PlatformContext3DImpl context3d.

Remove the SetParentContext() method from the PlatformContext3DImpl and
the plugin delegate, and the fullscreen widget. Instead, when the plugin
delegate or fullscreen widget become active, in ReparentContext() they
have the PlatformContext3DImpl require access to the offscreen shared
context and create the parent texture id with it, if needed.

The fullscreen widget context management needs to be adjusted. Previously
PlatformContext3DImpl would call back into the fullscreen widget which
would create the fullscreen widget's context. But we have removed that
circular trip. Now in RenderWidgetFullscreenPepper::CheckCompositing() if
compositing mode is being used, we create the fullscreen context3d.
We also recreate it if the old context was lost. When leaving compositing
mode, the fullscreen widget's context is destroyed.

The fullscreen widget's context is now made to share resources so that it
can access the texture created by the RenderThread's context.

This fixes the known issue where fullscreen remains black after a context
loss.

R=piman
BUG=181052


Review URL: https://chromiumcodereview.appspot.com/12673002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187109 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
danakj@chromium.org committed Mar 9, 2013
1 parent bb4f11b commit a44c1b2
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 164 deletions.
2 changes: 0 additions & 2 deletions content/content_renderer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@
'renderer/pepper/pepper_in_process_resource_creation.h',
'renderer/pepper/pepper_in_process_router.cc',
'renderer/pepper/pepper_in_process_router.h',
'renderer/pepper/pepper_parent_context_provider.cc',
'renderer/pepper/pepper_parent_context_provider.h',
'renderer/pepper/pepper_platform_audio_input_impl.cc',
'renderer/pepper/pepper_platform_audio_input_impl.h',
'renderer/pepper/pepper_platform_audio_output_impl.cc',
Expand Down
15 changes: 0 additions & 15 deletions content/renderer/pepper/pepper_parent_context_provider.cc

This file was deleted.

30 changes: 0 additions & 30 deletions content/renderer/pepper/pepper_parent_context_provider.h

This file was deleted.

88 changes: 35 additions & 53 deletions content/renderer/pepper/pepper_platform_context_3d_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "content/renderer/pepper/pepper_platform_context_3d_impl.h"

#include "base/bind.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "content/common/gpu/client/gpu_channel_host.h"
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
#include "content/renderer/pepper/pepper_parent_context_provider.h"
#include "content/renderer/render_thread_impl.h"
#include "googleurl/src/gurl.h"
#include "gpu/command_buffer/client/gles2_cmd_helper.h"
Expand All @@ -20,24 +20,15 @@

namespace content {

PlatformContext3DImpl::PlatformContext3DImpl(
PepperParentContextProvider* parent_context_provider)
: parent_context_provider_(parent_context_provider),
parent_texture_id_(0),
has_alpha_(false),
command_buffer_(NULL),
weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
PlatformContext3DImpl::PlatformContext3DImpl()
: parent_texture_id_(0),
has_alpha_(false),
command_buffer_(NULL),
weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}

PlatformContext3DImpl::~PlatformContext3DImpl() {
if (parent_context_.get() && parent_texture_id_ != 0) {
// Flush any remaining commands in the parent context to make sure the
// texture id accounting stays consistent.
gpu::gles2::GLES2Implementation* parent_gles2 =
parent_context_->GetImplementation();
parent_gles2->helper()->CommandBufferHelper::Finish();
parent_gles2->FreeTextureId(parent_texture_id_);
}
DestroyParentContextProviderAndBackingTexture();

if (command_buffer_) {
DCHECK(channel_.get());
Expand All @@ -54,9 +45,6 @@ bool PlatformContext3DImpl::Init(const int32* attrib_list,
if (command_buffer_)
return true;

if (!parent_context_provider_)
return false;

RenderThreadImpl* render_thread = RenderThreadImpl::current();
if (!render_thread)
return false;
Expand Down Expand Up @@ -126,61 +114,53 @@ bool PlatformContext3DImpl::Init(const int32* attrib_list,
base::Bind(&PlatformContext3DImpl::OnConsoleMessage,
weak_ptr_factory_.GetWeakPtr()));

// Fetch the parent context now, after any potential shutdown of the
// channel due to GPU switching, and creation of the Pepper 3D
// context with the discrete GPU preference.
WebGraphicsContext3DCommandBufferImpl* parent_context =
parent_context_provider_->GetParentContextForPlatformContext3D();
if (!parent_context)
return false;
return SetParentAndCreateBackingTextureIfNeeded();
}

parent_context_provider_ = NULL;
parent_context_ = parent_context->AsWeakPtr();
bool PlatformContext3DImpl::SetParentAndCreateBackingTextureIfNeeded() {
if (parent_context_provider_ &&
!parent_context_provider_->DestroyedOnMainThread() &&
parent_texture_id_)
return true;

parent_context_provider_ =
RenderThreadImpl::current()->OffscreenContextProviderForMainThread();
if (!parent_context_provider_->InitializeOnMainThread() ||
!parent_context_provider_->BindToCurrentThread()) {
DestroyParentContextProviderAndBackingTexture();
return false;
}

// Flush any remaining commands in the parent context to make sure the
// texture id accounting stays consistent.
gpu::gles2::GLES2Implementation* parent_gles2 =
parent_context_->GetImplementation();
parent_context_provider_->Context3d()->GetImplementation();
parent_gles2->helper()->CommandBufferHelper::Finish();
parent_texture_id_ = parent_gles2->MakeTextureId();

CommandBufferProxyImpl* parent_command_buffer =
parent_context_->GetCommandBufferProxy();
parent_context_provider_->Context3d()->GetCommandBufferProxy();
if (!command_buffer_->SetParent(parent_command_buffer, parent_texture_id_))
return false;

return true;
}

void PlatformContext3DImpl::SetParentContext(
PepperParentContextProvider* parent_context_provider) {
if (parent_context_.get() && parent_texture_id_ != 0) {
void PlatformContext3DImpl::DestroyParentContextProviderAndBackingTexture() {
if (!parent_context_provider_)
return;

if (parent_texture_id_) {
// Flush any remaining commands in the parent context to make sure the
// texture id accounting stays consistent.
gpu::gles2::GLES2Implementation* parent_gles2 =
parent_context_->GetImplementation();
parent_gles2->helper()->CommandBufferHelper::Flush();
parent_context_provider_->Context3d()->GetImplementation();
parent_gles2->helper()->CommandBufferHelper::Finish();
parent_gles2->FreeTextureId(parent_texture_id_);
parent_context_.reset();
parent_texture_id_ = 0;
}

WebGraphicsContext3DCommandBufferImpl* parent_context =
parent_context_provider->GetParentContextForPlatformContext3D();
if (!parent_context)
return;

parent_context_ = parent_context->AsWeakPtr();
// Flush any remaining commands in the parent context to make sure the
// texture id accounting stays consistent.
gpu::gles2::GLES2Implementation* parent_gles2 =
parent_context_->GetImplementation();
parent_gles2->helper()->CommandBufferHelper::Flush();
parent_texture_id_ = parent_gles2->MakeTextureId();

CommandBufferProxyImpl* parent_command_buffer =
parent_context_->GetCommandBufferProxy();
command_buffer_->SetParent(parent_command_buffer, parent_texture_id_);
parent_context_provider_ = NULL;
}

unsigned PlatformContext3DImpl::GetBackingTextureId() {
Expand All @@ -189,7 +169,9 @@ unsigned PlatformContext3DImpl::GetBackingTextureId() {
}

WebKit::WebGraphicsContext3D* PlatformContext3DImpl::GetParentContext() {
return parent_context_.get();
if (!parent_context_provider_)
return NULL;
return parent_context_provider_->Context3d();
}

bool PlatformContext3DImpl::IsOpaque() {
Expand Down
14 changes: 5 additions & 9 deletions content/renderer/pepper/pepper_platform_context_3d_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ class CommandBuffer;
} // namespace gpu

namespace content {
class ContextProviderCommandBuffer;
class GpuChannelHost;

class PepperParentContextProvider;

class PlatformContext3DImpl
: public webkit::ppapi::PluginDelegate::PlatformContext3D {
public:
explicit PlatformContext3DImpl(
PepperParentContextProvider* parent_context_provider);
explicit PlatformContext3DImpl();
virtual ~PlatformContext3DImpl();

virtual bool Init(const int32* attrib_list,
Expand All @@ -43,17 +41,15 @@ class PlatformContext3DImpl
const ConsoleMessageCallback& callback) OVERRIDE;
virtual bool Echo(const base::Closure& task) OVERRIDE;

virtual void SetParentContext(
PepperParentContextProvider* parent_context_provider);
bool SetParentAndCreateBackingTextureIfNeeded();
void DestroyParentContextProviderAndBackingTexture();

private:
bool InitRaw();
void OnContextLost();
void OnConsoleMessage(const std::string& msg, int id);

// Implicitly weak pointer; must outlive this instance.
PepperParentContextProvider* parent_context_provider_;
base::WeakPtr<WebGraphicsContext3DCommandBufferImpl> parent_context_;
scoped_refptr<ContextProviderCommandBuffer> parent_context_provider_;
scoped_refptr<GpuChannelHost> channel_;
unsigned int parent_texture_id_;
bool has_alpha_;
Expand Down
20 changes: 3 additions & 17 deletions content/renderer/pepper/pepper_plugin_delegate_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,16 @@ webkit::ppapi::PluginDelegate::PlatformContext3D*
const webkit_glue::WebPreferences& prefs = render_view_->webkit_preferences();
if (!prefs.accelerated_compositing_for_plugins_enabled)
return NULL;
return new PlatformContext3DImpl(this);
return new PlatformContext3DImpl;
#else
return NULL;
#endif
}

void PepperPluginDelegateImpl::ReparentContext(
webkit::ppapi::PluginDelegate::PlatformContext3D* context) {
static_cast<PlatformContext3DImpl*>(context)->SetParentContext(this);
static_cast<PlatformContext3DImpl*>(context)->
SetParentAndCreateBackingTextureIfNeeded();
}

webkit::ppapi::PluginDelegate::PlatformVideoCapture*
Expand Down Expand Up @@ -1573,21 +1574,6 @@ int PepperPluginDelegateImpl::GetSessionID(PP_DeviceType_Dev type,
#endif
}

WebGraphicsContext3DCommandBufferImpl*
PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() {
if (!offscreen_context3d_ || offscreen_context3d_->DestroyedOnMainThread()) {
offscreen_context3d_ =
RenderThreadImpl::current()->OffscreenContextProviderForMainThread();

if (!offscreen_context3d_->InitializeOnMainThread() ||
!offscreen_context3d_->BindToCurrentThread()) {
offscreen_context3d_ = NULL;
return NULL;
}
}
return offscreen_context3d_->Context3d();
}

MouseLockDispatcher::LockTarget*
PepperPluginDelegateImpl::GetOrCreateLockTargetAdapter(
webkit::ppapi::PluginInstance* instance) {
Expand Down
6 changes: 0 additions & 6 deletions content/renderer/pepper/pepper_plugin_delegate_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "base/observer_list.h"
#include "content/public/renderer/render_view_observer.h"
#include "content/renderer/mouse_lock_dispatcher.h"
#include "content/renderer/pepper/pepper_parent_context_provider.h"
#include "content/renderer/render_view_pepper_helper.h"
#include "ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h"
#include "ppapi/shared_impl/private/tcp_socket_private_impl.h"
Expand Down Expand Up @@ -63,7 +62,6 @@ class PepperPluginDelegateImpl
: public webkit::ppapi::PluginDelegate,
public RenderViewPepperHelper,
public base::SupportsWeakPtr<PepperPluginDelegateImpl>,
public PepperParentContextProvider,
public RenderViewObserver {
public:
explicit PepperPluginDelegateImpl(RenderViewImpl* render_view);
Expand Down Expand Up @@ -382,10 +380,6 @@ class PepperPluginDelegateImpl
int plugin_child_id,
bool is_external);

// Implementation of PepperParentContextProvider.
virtual WebGraphicsContext3DCommandBufferImpl*
GetParentContextForPlatformContext3D() OVERRIDE;

MouseLockDispatcher::LockTarget* GetOrCreateLockTargetAdapter(
webkit::ppapi::PluginInstance* instance);
void UnSetAndDeleteLockTargetAdapter(webkit::ppapi::PluginInstance* instance);
Expand Down
Loading

0 comments on commit a44c1b2

Please sign in to comment.