Commit d9e23a08 authored by boliu's avatar boliu Committed by Commit bot

Move AW renderer compositor context to gpu thread

Use TexSubImage2D instead of TexImage2D to avoid orphaning
EGLImage
Create the renderer compositor context on the gpu thread.

BUG=448168, 259924

Committed: https://crrev.com/a4baed454be2bb165cb12eb7df432e9138e746e6
Cr-Commit-Position: refs/heads/master@{#313846}

Review URL: https://codereview.chromium.org/769703005

Cr-Commit-Position: refs/heads/master@{#314705}
parent 0c7c18bf
......@@ -4,6 +4,7 @@
#include "content/browser/android/in_process/synchronous_compositor_factory_impl.h"
#include "base/command_line.h"
#include "base/observer_list.h"
#include "content/browser/android/in_process/synchronous_compositor_external_begin_frame_source.h"
#include "content/browser/android/in_process/synchronous_compositor_impl.h"
......@@ -13,6 +14,7 @@
#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "ui/gl/android/surface_texture.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/gl_surface_stub.h"
......@@ -64,7 +66,8 @@ scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext(
scoped_ptr<gpu::GLInProcessContext> CreateContext(
scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
const gpu::GLInProcessContextSharedMemoryLimits& mem_limits) {
const gpu::GLInProcessContextSharedMemoryLimits& mem_limits,
bool is_offscreen) {
const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
gpu::gles2::ContextCreationAttribHelper in_process_attribs;
WebGraphicsContext3DImpl::ConvertAttributes(
......@@ -74,7 +77,7 @@ scoped_ptr<gpu::GLInProcessContext> CreateContext(
scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create(
service,
NULL /* surface */,
false /* is_offscreen */,
is_offscreen,
gfx::kNullAcceleratedWidget,
gfx::Size(1, 1),
NULL /* share_context */,
......@@ -219,7 +222,7 @@ scoped_refptr<cc::ContextProvider> SynchronousCompositorFactoryImpl::
// pipeline is only one frame deep.
mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024;
return webkit::gpu::ContextProviderInProcess::Create(
WrapContext(CreateContext(service_, mem_limits)),
WrapContext(CreateContext(nullptr, mem_limits, true)),
"Child-Compositor");
}
......@@ -288,9 +291,10 @@ SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() {
if (!video_context_provider_.get()) {
DCHECK(service_.get());
video_context_provider_ = new VideoContextProvider(
CreateContext(service_,
gpu::GLInProcessContextSharedMemoryLimits()));
// This needs to run in on-screen |service_| context due to SurfaceTexture
// limitations.
video_context_provider_ = new VideoContextProvider(CreateContext(
service_, gpu::GLInProcessContextSharedMemoryLimits(), false));
}
return video_context_provider_;
}
......
......@@ -77,13 +77,16 @@ bool AllowTransferThreadForGpu() {
AsyncPixelTransferManager* AsyncPixelTransferManager::Create(
gfx::GLContext* context) {
DCHECK(context->IsCurrent(NULL));
base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
// Threaded mailbox uses EGLImage which conflicts with EGL uploader.
// The spec only allows one EGL image per sibling group, but currently the
// image handle cannot be shared between the threaded mailbox code and
// AsyncPixelTransferManagerEGL.
bool uses_threaded_mailboxes =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableThreadedTextureMailboxes);
cl->HasSwitch(switches::kEnableThreadedTextureMailboxes);
// TexImage2D orphans the EGLImage used for threaded mailbox sharing.
bool use_teximage2d_over_texsubimage2d = !uses_threaded_mailboxes;
switch (gfx::GetGLImplementation()) {
case gfx::kGLImplementationEGLGLES2:
DCHECK(context);
......@@ -93,15 +96,16 @@ AsyncPixelTransferManager* AsyncPixelTransferManager::Create(
context->HasExtension("EGL_KHR_image_base") &&
context->HasExtension("EGL_KHR_gl_texture_2D_image") &&
context->HasExtension("GL_OES_EGL_image") &&
!uses_threaded_mailboxes &&
AllowTransferThreadForGpu()) {
!uses_threaded_mailboxes && AllowTransferThreadForGpu()) {
TRACE_EVENT0("gpu", "AsyncPixelTransferManager_CreateWithThread");
return new AsyncPixelTransferManagerEGL;
}
return new AsyncPixelTransferManagerIdle;
return new AsyncPixelTransferManagerIdle(
use_teximage2d_over_texsubimage2d);
case gfx::kGLImplementationOSMesaGL: {
TRACE_EVENT0("gpu", "AsyncPixelTransferManager_CreateIdle");
return new AsyncPixelTransferManagerIdle;
return new AsyncPixelTransferManagerIdle(
use_teximage2d_over_texsubimage2d);
}
case gfx::kGLImplementationMockGL:
return new AsyncPixelTransferManagerStub;
......
......@@ -183,9 +183,8 @@ void AsyncPixelTransferDelegateIdle::PerformAsyncTexSubImage2D(
base::TimeTicks begin_time(base::TimeTicks::Now());
gfx::ScopedTextureBinder texture_binder(tex_params.target, texture_id_);
// If it's a full texture update, use glTexImage2D as it's faster.
// TODO(epenner): Make this configurable (http://crbug.com/259924)
if (tex_params.xoffset == 0 &&
if (shared_state_->use_teximage2d_over_texsubimage2d &&
tex_params.xoffset == 0 &&
tex_params.yoffset == 0 &&
tex_params.target == define_params_.target &&
tex_params.level == define_params_.level &&
......@@ -234,8 +233,11 @@ AsyncPixelTransferManagerIdle::Task::Task(
AsyncPixelTransferManagerIdle::Task::~Task() {}
AsyncPixelTransferManagerIdle::SharedState::SharedState()
: texture_upload_count(0) {}
AsyncPixelTransferManagerIdle::SharedState::SharedState(
bool use_teximage2d_over_texsubimage2d)
: use_teximage2d_over_texsubimage2d(use_teximage2d_over_texsubimage2d),
texture_upload_count(0) {
}
AsyncPixelTransferManagerIdle::SharedState::~SharedState() {}
......@@ -250,8 +252,9 @@ void AsyncPixelTransferManagerIdle::SharedState::ProcessNotificationTasks() {
}
}
AsyncPixelTransferManagerIdle::AsyncPixelTransferManagerIdle()
: shared_state_() {
AsyncPixelTransferManagerIdle::AsyncPixelTransferManagerIdle(
bool use_teximage2d_over_texsubimage2d)
: shared_state_(use_teximage2d_over_texsubimage2d) {
}
AsyncPixelTransferManagerIdle::~AsyncPixelTransferManagerIdle() {}
......
......@@ -13,7 +13,8 @@ namespace gpu {
class AsyncPixelTransferManagerIdle : public AsyncPixelTransferManager {
public:
AsyncPixelTransferManagerIdle();
explicit AsyncPixelTransferManagerIdle(
bool use_teximage2d_over_texsubimage2d);
~AsyncPixelTransferManagerIdle() override;
// AsyncPixelTransferManager implementation:
......@@ -43,10 +44,11 @@ class AsyncPixelTransferManagerIdle : public AsyncPixelTransferManager {
// State shared between Managers and Delegates.
struct SharedState {
SharedState();
explicit SharedState(bool use_teximage2d_over_texsubimage2d);
~SharedState();
void ProcessNotificationTasks();
const bool use_teximage2d_over_texsubimage2d;
int texture_upload_count;
base::TimeDelta total_texture_upload_time;
std::list<Task> tasks;
......
......@@ -28,7 +28,7 @@ AsyncPixelTransferManager* AsyncPixelTransferManager::Create(
case gfx::kGLImplementationOSMesaGL:
case gfx::kGLImplementationDesktopGL:
case gfx::kGLImplementationEGLGLES2:
return new AsyncPixelTransferManagerIdle;
return new AsyncPixelTransferManagerIdle(true);
case gfx::kGLImplementationMockGL:
return new AsyncPixelTransferManagerStub;
default:
......
......@@ -18,7 +18,7 @@ AsyncPixelTransferManager* AsyncPixelTransferManager::Create(
case gfx::kGLImplementationOSMesaGL:
case gfx::kGLImplementationDesktopGL:
case gfx::kGLImplementationAppleGL:
return new AsyncPixelTransferManagerIdle;
return new AsyncPixelTransferManagerIdle(true);
case gfx::kGLImplementationMockGL:
return new AsyncPixelTransferManagerStub;
default:
......
......@@ -18,7 +18,7 @@ AsyncPixelTransferManager* AsyncPixelTransferManager::Create(
case gfx::kGLImplementationOSMesaGL:
case gfx::kGLImplementationDesktopGL:
case gfx::kGLImplementationEGLGLES2:
return new AsyncPixelTransferManagerIdle;
return new AsyncPixelTransferManagerIdle(true);
case gfx::kGLImplementationMockGL:
return new AsyncPixelTransferManagerStub;
default:
......
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