Skip to content

Commit

Permalink
[Android] Fix the render issue introduced by single process mode.
Browse files Browse the repository at this point in the history
* In Chromium, single process mode is only for Android WebView, ContentShell and
its derivatives only go to the multiple process mode.
* The context design is only for multiple process mode(ContentShell/XWalk), if we
force running it with single process mode, there are issues (black regions for
video/canvas/webgl layers, and black screen for stop/restart actions). The reason
is that Android port has browser-side compositor, and the shared context in
browser-side compositor has conflicts with renderer's contexts if running in single
process mode.
* To run ContentShell/XWalk in single process mode, we have to resolve the shared
context issue between renderer/browser.

BUG=crosswalk-project/crosswalk#516

Conflicts:
	content/browser/renderer_host/compositor_impl_android.cc
	content/browser/renderer_host/image_transport_factory_android.cc
	content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
	content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h

Rework with 32.0.1700.4 by Halton
  • Loading branch information
sqliu authored and Halton Huo committed Nov 6, 2013
1 parent d250663 commit c455818
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 19 deletions.
3 changes: 2 additions & 1 deletion content/browser/renderer_host/compositor_impl_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ CreateGpuProcessViewContext(
compositor_impl,
attributes,
false,
limits));
limits,
true));
}

scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ CmdBufferImageTransportFactory::CmdBufferImageTransportFactory() {
swap_client,
attrs,
false,
limits));
limits,
true));
context_->setContextLostCallback(context_lost_listener_.get());
if (context_->makeContextCurrent())
context_->pushGroupMarkerEXT(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ static base::LazyInstance<base::Lock>::Leaky
static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> >
g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER;

static base::LazyInstance<base::Lock>::Leaky
g_all_shared_contexts_browser_lock = LAZY_INSTANCE_INITIALIZER;
static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> >
g_all_shared_contexts_browser = LAZY_INSTANCE_INITIALIZER;

namespace {

void ClearSharedContextsIfInShareSet(
Expand All @@ -66,6 +71,26 @@ void ClearSharedContextsIfInShareSet(
}
}

void ClearSharedContextsIfInShareSetBrowser(
WebGraphicsContext3DCommandBufferImpl* context) {
// If the given context isn't in the share set, that means that it
// or another context it was previously sharing with already
// provoked a lost context. Other contexts might have since been
// successfully created and added to the share set, so do not clear
// out the share set unless we know that all the contexts in there
// are supposed to be lost simultaneously.
base::AutoLock lock(g_all_shared_contexts_browser_lock.Get());
std::set<WebGraphicsContext3DCommandBufferImpl*>* share_set =
g_all_shared_contexts_browser.Pointer();
for (std::set<WebGraphicsContext3DCommandBufferImpl*>::iterator iter =
share_set->begin(); iter != share_set->end(); ++iter) {
if (context == *iter) {
share_set->clear();
return;
}
}
}

size_t ClampUint64ToSizeT(uint64 value) {
value = std::min(value,
static_cast<uint64>(std::numeric_limits<size_t>::max()));
Expand Down Expand Up @@ -231,7 +256,8 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl(
const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client,
const Attributes& attributes,
bool bind_generates_resources,
const SharedMemoryLimits& limits)
const SharedMemoryLimits& limits,
bool context_for_browser_compositor)
: initialize_failed_(false),
visible_(false),
free_command_buffer_when_invisible_(false),
Expand All @@ -253,6 +279,7 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl(
bind_generates_resources_(bind_generates_resources),
use_echo_for_swap_ack_(true),
mem_limits_(limits),
context_for_browser_compositor_(context_for_browser_compositor),
flush_id_(0) {
#if (defined(OS_MACOSX) || defined(OS_WIN)) && !defined(USE_AURA)
// Get ViewMsg_SwapBuffers_ACK from browser for single-threaded path.
Expand All @@ -268,7 +295,10 @@ WebGraphicsContext3DCommandBufferImpl::
real_gl_->SetErrorMessageCallback(NULL);
}

{
if (context_for_browser_compositor_) {
base::AutoLock lock(g_all_shared_contexts_browser_lock.Get());
g_all_shared_contexts_browser.Pointer()->erase(this);
} else {
base::AutoLock lock(g_all_shared_contexts_lock.Get());
g_all_shared_contexts.Pointer()->erase(this);
}
Expand Down Expand Up @@ -343,14 +373,23 @@ bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer(
// We need to lock g_all_shared_contexts to ensure that the context we picked
// for our share group isn't deleted.
// (There's also a lock in our destructor.)
base::AutoLock lock(g_all_shared_contexts_lock.Get());
CommandBufferProxyImpl* share_group = NULL;
if (attributes_.shareResources) {
WebGraphicsContext3DCommandBufferImpl* share_group_context =
g_all_shared_contexts.Pointer()->empty() ?
NULL : *g_all_shared_contexts.Pointer()->begin();
share_group = share_group_context ?
share_group_context->command_buffer_.get() : NULL;
if (context_for_browser_compositor_) {
base::AutoLock lock(g_all_shared_contexts_browser_lock.Get());
WebGraphicsContext3DCommandBufferImpl* share_group_context =
g_all_shared_contexts_browser.Pointer()->empty() ?
NULL : *g_all_shared_contexts_browser.Pointer()->begin();
share_group = share_group_context ?
share_group_context->command_buffer_.get() : NULL;
} else {
base::AutoLock lock(g_all_shared_contexts_lock.Get());
WebGraphicsContext3DCommandBufferImpl* share_group_context =
g_all_shared_contexts.Pointer()->empty() ?
NULL : *g_all_shared_contexts.Pointer()->begin();
share_group = share_group_context ?
share_group_context->command_buffer_.get() : NULL;
}
}

std::vector<int32> attribs;
Expand Down Expand Up @@ -417,11 +456,20 @@ bool WebGraphicsContext3DCommandBufferImpl::CreateContext(
if (attributes_.shareResources) {
// Make sure two clients don't try to create a new ShareGroup
// simultaneously.
lock.reset(new base::AutoLock(g_all_shared_contexts_lock.Get()));
if (!g_all_shared_contexts.Pointer()->empty()) {
share_group = (*g_all_shared_contexts.Pointer()->begin())
->GetImplementation()->share_group();
DCHECK(share_group);
if (context_for_browser_compositor_) {
lock.reset(new base::AutoLock(g_all_shared_contexts_browser_lock.Get()));
if (!g_all_shared_contexts_browser.Pointer()->empty()) {
share_group = (*g_all_shared_contexts_browser.Pointer()->begin())
->GetImplementation()->share_group();
DCHECK(share_group);
}
} else {
lock.reset(new base::AutoLock(g_all_shared_contexts_lock.Get()));
if (!g_all_shared_contexts.Pointer()->empty()) {
share_group = (*g_all_shared_contexts.Pointer()->begin())
->GetImplementation()->share_group();
DCHECK(share_group);
}
}
}

Expand All @@ -436,7 +484,11 @@ bool WebGraphicsContext3DCommandBufferImpl::CreateContext(

if (attributes_.shareResources) {
// Don't add ourselves to the list before others can get to our ShareGroup.
g_all_shared_contexts.Pointer()->insert(this);
if (context_for_browser_compositor_) {
g_all_shared_contexts_browser.Pointer()->insert(this);
} else {
g_all_shared_contexts.Pointer()->insert(this);
}
lock.reset();
}

Expand Down Expand Up @@ -1456,8 +1508,13 @@ void WebGraphicsContext3DCommandBufferImpl::OnContextLost() {
if (context_lost_callback_) {
context_lost_callback_->onContextLost();
}
if (attributes_.shareResources)
ClearSharedContextsIfInShareSet(this);
if (attributes_.shareResources) {
if (context_for_browser_compositor_) {
ClearSharedContextsIfInShareSetBrowser(this);
} else {
ClearSharedContextsIfInShareSet(this);
}
}
if (ShouldUseSwapClient())
swap_client_->OnViewContextSwapBuffersAborted();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class WebGraphicsContext3DCommandBufferImpl
const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client,
const Attributes& attributes,
bool bind_generates_resources,
const SharedMemoryLimits& limits);
const SharedMemoryLimits& limits,
bool context_for_browser_compositor = false);

virtual ~WebGraphicsContext3DCommandBufferImpl();

Expand Down Expand Up @@ -753,6 +754,8 @@ class WebGraphicsContext3DCommandBufferImpl
bool use_echo_for_swap_ack_;
SharedMemoryLimits mem_limits_;

bool context_for_browser_compositor_;

uint32_t flush_id_;
};

Expand Down

0 comments on commit c455818

Please sign in to comment.