Skip to content

Commit

Permalink
Revert "Automate calls to GrContext::resetContext"
Browse files Browse the repository at this point in the history
This reverts commit c8f117c.
This reverts commit c18cd56.

Reason for revert: causes rendering corruption in Android WebView

BUG=823232
TBR=piman@chromium.org

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I56df8c34b7bbf2e80eb818f8ca4595f220dbffd0
Reviewed-on: https://chromium-review.googlesource.com/974064
Commit-Queue: Justin Novosad <junov@chromium.org>
Reviewed-by: Justin Novosad <junov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544862}
  • Loading branch information
junov authored and Commit Bot committed Mar 21, 2018
1 parent 50afc83 commit 60f840e
Show file tree
Hide file tree
Showing 60 changed files with 422 additions and 1,069 deletions.
11 changes: 9 additions & 2 deletions android_webview/browser/aw_render_thread_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class GrContext* AwRenderThreadContextProvider::GrContext() {
if (gr_context_)
return gr_context_.get();

sk_sp<GrGLInterface> interface(skia_bindings::CreateGLES2InterfaceBindings(
ContextGL(), ContextSupport()));
sk_sp<GrGLInterface> interface(
skia_bindings::CreateGLES2InterfaceBindings(ContextGL()));
gr_context_ = GrContext::MakeGL(std::move(interface));
cache_controller_->SetGrContext(gr_context_.get());
return gr_context_.get();
Expand All @@ -152,6 +152,13 @@ viz::ContextCacheController* AwRenderThreadContextProvider::CacheController() {
return cache_controller_.get();
}

void AwRenderThreadContextProvider::InvalidateGrContext(uint32_t state) {
DCHECK(main_thread_checker_.CalledOnValidThread());

if (gr_context_)
gr_context_->resetContext(state);
}

base::Lock* AwRenderThreadContextProvider::GetLock() {
// This context provider is not used on multiple threads.
NOTREACHED();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class AwRenderThreadContextProvider
gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override;
viz::ContextCacheController* CacheController() override;
void InvalidateGrContext(uint32_t state) override;
base::Lock* GetLock() override;
void AddObserver(viz::ContextLostObserver* obs) override;
void RemoveObserver(viz::ContextLostObserver* obs) override;
Expand Down
22 changes: 22 additions & 0 deletions cc/raster/gpu_raster_buffer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,27 @@ static void RasterizeSourceOOP(
ri->DeleteTextures(1, &texture_id);
}

// The following class is needed to correctly reset GL state when rendering to
// SkCanvases with a GrContext on a RasterInterface enabled context.
class ScopedGrContextAccess {
public:
explicit ScopedGrContextAccess(viz::RasterContextProvider* context_provider)
: context_provider_(context_provider) {
gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
ri->BeginGpuRaster();

class GrContext* gr_context = context_provider_->GrContext();
gr_context->resetContext();
}
~ScopedGrContextAccess() {
gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
ri->EndGpuRaster();
}

private:
viz::RasterContextProvider* context_provider_;
};

static void RasterizeSource(
const RasterSource* raster_source,
bool resource_has_previous_content,
Expand Down Expand Up @@ -193,6 +214,7 @@ static void RasterizeSource(
}

{
ScopedGrContextAccess gr_context_access(context_provider);
base::Optional<LayerTreeResourceProvider::ScopedSkSurface> scoped_surface;
base::Optional<ScopedSkSurfaceForUnpremultiplyAndDither>
scoped_dither_surface;
Expand Down
3 changes: 3 additions & 0 deletions cc/raster/raster_buffer_provider_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class PerfContextProvider
viz::ContextCacheController* CacheController() override {
return &cache_controller_;
}
void InvalidateGrContext(uint32_t state) override {
test_context_provider_->GrContext()->resetContext(state);
}
base::Lock* GetLock() override { return &context_lock_; }
void AddObserver(viz::ContextLostObserver* obs) override {}
void RemoveObserver(viz::ContextLostObserver* obs) override {}
Expand Down
3 changes: 3 additions & 0 deletions cc/raster/scoped_gpu_raster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ void ScopedGpuRaster::BeginGpuRaster() {
// Using push/pop functions directly incurs cost to evaluate function
// arguments even when tracing is disabled.
gl->TraceBeginCHROMIUM("ScopedGpuRaster", "GpuRasterization");

class GrContext* gr_context = context_provider_->GrContext();
gr_context->resetContext();
}

void ScopedGpuRaster::EndGpuRaster() {
Expand Down
9 changes: 7 additions & 2 deletions cc/test/test_in_process_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class GrContext* TestInProcessContextProvider::GrContext() {
skia_bindings::GrContextForGLES2Interface::DefaultCacheLimitsForTests(
&max_resource_cache_bytes, &max_glyph_cache_texture_bytes);
gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(
ContextGL(), ContextSupport(), ContextCapabilities(),
max_resource_cache_bytes, max_glyph_cache_texture_bytes));
ContextGL(), ContextCapabilities(), max_resource_cache_bytes,
max_glyph_cache_texture_bytes));
cache_controller_->SetGrContext(gr_context_->get());
return gr_context_->get();
}
Expand All @@ -123,6 +123,11 @@ viz::ContextCacheController* TestInProcessContextProvider::CacheController() {
return cache_controller_.get();
}

void TestInProcessContextProvider::InvalidateGrContext(uint32_t state) {
if (gr_context_)
gr_context_->ResetContext(state);
}

base::Lock* TestInProcessContextProvider::GetLock() {
return &context_lock_;
}
Expand Down
1 change: 1 addition & 0 deletions cc/test/test_in_process_context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class TestInProcessContextProvider
gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override;
viz::ContextCacheController* CacheController() override;
void InvalidateGrContext(uint32_t state) override;
base::Lock* GetLock() override;
const gpu::Capabilities& ContextCapabilities() const override;
const gpu::GpuFeatureInfo& GetGpuFeatureInfo() const override;
Expand Down
5 changes: 5 additions & 0 deletions cc/tiles/gpu_image_decode_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,11 @@ void GpuImageDecodeCache::RunPendingContextThreadOperations() {
context_->ContextGL()->UnlockDiscardableTextureCHROMIUM(
GlIdFromSkImage(image));
}
if (images_pending_unlock_.size() > 0) {
// When we unlock images, we remove any outstanding texture bindings. We
// need to inform Skia so it will re-generate these bindings if needed.
context_->GrContext()->resetContext(kTextureBinding_GrGLBackendState);
}
images_pending_unlock_.clear();

for (auto id : ids_pending_unlock_) {
Expand Down
3 changes: 0 additions & 3 deletions cc/trees/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2080,9 +2080,6 @@ void LayerTreeHostImpl::GetGpuRasterizationCapabilities(
if (!*gpu_rasterization_enabled && !settings_.gpu_rasterization_forced)
return;

if (!context_provider->ContextSupport()->HasGrContextSupport())
return;

// Do not check GrContext above. It is lazy-created, and we only want to
// create it if it might be used.
GrContext* gr_context = context_provider->GrContext();
Expand Down
7 changes: 7 additions & 0 deletions components/viz/common/gl_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,13 @@ gfx::Size I420Converter::GetChromaPlaneTextureSize(
(output_size.height() + 1) / 2);
}

// static
uint32_t ReadbackYUVInterface::GetGrGLBackendStateChanges() {
return kTextureBinding_GrGLBackendState | kView_GrGLBackendState |
kVertex_GrGLBackendState | kProgram_GrGLBackendState |
kRenderTarget_GrGLBackendState;
}

namespace {

I420ConverterImpl::I420ConverterImpl(GLES2Interface* gl,
Expand Down
4 changes: 4 additions & 0 deletions components/viz/common/gl_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ class VIZ_COMMON_EXPORT ReadbackYUVInterface {
unsigned char* v_plane_data,
const gfx::Point& paste_location,
const base::Callback<void(bool)>& callback) = 0;

// Returns the bitwise ORed set of GL backend state change that can be used to
// restore the GL state after ReadbackYUV() calls.
static uint32_t GetGrGLBackendStateChanges();
};

} // namespace viz
Expand Down
5 changes: 5 additions & 0 deletions components/viz/common/gpu/context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class VIZ_COMMON_EXPORT ContextProvider {
// nullptr if a GrContext fails to initialize on this context.
virtual class GrContext* GrContext() = 0;

// Invalidates the cached OpenGL state in GrContext. The context provider
// must have been successfully bound to a thread before calling this.
// See skia GrContext::resetContext for details.
virtual void InvalidateGrContext(uint32_t state) = 0;

// Returns the capabilities of the currently bound 3d context. The context
// provider must have been successfully bound to a thread before calling this.
virtual const gpu::Capabilities& ContextCapabilities() const = 0;
Expand Down
9 changes: 7 additions & 2 deletions components/viz/common/gpu/in_process_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,20 @@ class GrContext* InProcessContextProvider::GrContext() {
&max_glyph_cache_texture_bytes);

gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(
ContextGL(), ContextSupport(), ContextCapabilities(),
max_resource_cache_bytes, max_glyph_cache_texture_bytes));
ContextGL(), ContextCapabilities(), max_resource_cache_bytes,
max_glyph_cache_texture_bytes));
return gr_context_->get();
}

ContextCacheController* InProcessContextProvider::CacheController() {
return cache_controller_.get();
}

void InProcessContextProvider::InvalidateGrContext(uint32_t state) {
if (gr_context_)
gr_context_->ResetContext(state);
}

base::Lock* InProcessContextProvider::GetLock() {
return &context_lock_;
}
Expand Down
1 change: 1 addition & 0 deletions components/viz/common/gpu/in_process_context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class VIZ_COMMON_EXPORT InProcessContextProvider
gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override;
ContextCacheController* CacheController() override;
void InvalidateGrContext(uint32_t state) override;
base::Lock* GetLock() override;
const gpu::Capabilities& ContextCapabilities() const override;
const gpu::GpuFeatureInfo& GetGpuFeatureInfo() const override;
Expand Down
5 changes: 5 additions & 0 deletions components/viz/common/gpu/raster_context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class VIZ_COMMON_EXPORT RasterContextProvider {
// nullptr if a GrContext fails to initialize on this context.
virtual class GrContext* GrContext() = 0;

// Invalidates the cached OpenGL state in GrContext. The context provider
// must have been successfully bound to a thread before calling this.
// See skia GrContext::resetContext for details.
virtual void InvalidateGrContext(uint32_t state) = 0;

// Returns the capabilities of the currently bound 3d context. The context
// provider must have been successfully bound to a thread before calling this.
virtual const gpu::Capabilities& ContextCapabilities() const = 0;
Expand Down
10 changes: 9 additions & 1 deletion components/viz/test/test_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class GrContext* TestContextProvider::GrContext() {
skia_bindings::GrContextForGLES2Interface::DefaultCacheLimitsForTests(
&max_resource_cache_bytes, &max_glyph_cache_texture_bytes);
gr_context_ = std::make_unique<skia_bindings::GrContextForGLES2Interface>(
context_gl_.get(), support_.get(), context3d_->test_capabilities(),
context_gl_.get(), context3d_->test_capabilities(),
max_resource_cache_bytes, max_glyph_cache_texture_bytes);
cache_controller_->SetGrContext(gr_context_->get());

Expand All @@ -285,6 +285,14 @@ ContextCacheController* TestContextProvider::CacheController() {
return cache_controller_.get();
}

void TestContextProvider::InvalidateGrContext(uint32_t state) {
DCHECK(bound_);
CheckValidThreadOrLockAcquired();

if (gr_context_)
gr_context_->get()->resetContext(state);
}

base::Lock* TestContextProvider::GetLock() {
if (!support_locking_)
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions components/viz/test/test_context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class TestContextProvider
gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override;
ContextCacheController* CacheController() override;
void InvalidateGrContext(uint32_t state) override;
base::Lock* GetLock() override;
void AddObserver(ContextLostObserver* obs) override;
void RemoveObserver(ContextLostObserver* obs) override;
Expand Down
10 changes: 0 additions & 10 deletions components/viz/test/test_context_support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,4 @@ unsigned int TestContextSupport::GetTransferBufferFreeSize() const {
return 0;
}

bool TestContextSupport::HasGrContextSupport() const {
return true;
}

void TestContextSupport::SetGrContext(GrContext* gr) {}

void TestContextSupport::WillCallGLFromSkia() {}

void TestContextSupport::DidCallGLFromSkia() {}

} // namespace viz
4 changes: 0 additions & 4 deletions components/viz/test/test_context_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ class TestContextSupport : public gpu::ContextSupport {
void DeleteTransferCacheEntry(uint32_t entry_type,
uint32_t entry_id) override;
unsigned int GetTransferBufferFreeSize() const override;
bool HasGrContextSupport() const override;
void SetGrContext(GrContext* gr) override;
void WillCallGLFromSkia() override;
void DidCallGLFromSkia() override;

void CallAllSyncPointCallbacks();

Expand Down
12 changes: 3 additions & 9 deletions content/browser/compositor/gpu_process_transport_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,10 @@ void GpuProcessTransportFactory::EstablishedGpuChannel(
bool support_locking = true;
bool support_gles2_interface = false;
bool support_raster_interface = true;
bool support_grcontext = false;
shared_worker_context_provider_ = CreateContextCommon(
gpu_channel_host, gpu::kNullSurfaceHandle, need_alpha_channel,
false /* support_stencil */, support_locking, support_gles2_interface,
support_raster_interface, support_grcontext,
support_raster_interface,
ui::command_buffer_metrics::BROWSER_WORKER_CONTEXT);
auto result = shared_worker_context_provider_->BindToCurrentThread();
if (result != gpu::ContextResult::kSuccess) {
Expand All @@ -421,11 +420,10 @@ void GpuProcessTransportFactory::EstablishedGpuChannel(
bool support_locking = false;
bool support_gles2_interface = true;
bool support_raster_interface = false;
bool support_grcontext = true;
context_provider = CreateContextCommon(
std::move(gpu_channel_host), surface_handle, need_alpha_channel,
support_stencil, support_locking, support_gles2_interface,
support_raster_interface, support_grcontext,
support_raster_interface,
ui::command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT);
// On Mac, GpuCommandBufferMsg_SwapBuffersCompleted must be handled in
// a nested run loop during resize.
Expand Down Expand Up @@ -970,11 +968,9 @@ GpuProcessTransportFactory::SharedMainThreadContextProvider() {
bool support_locking = false;
bool support_gles2_interface = true;
bool support_raster_interface = false;
bool support_grcontext = true;
shared_main_thread_contexts_ = CreateContextCommon(
std::move(gpu_channel_host), gpu::kNullSurfaceHandle, need_alpha_channel,
false, support_locking, support_gles2_interface, support_raster_interface,
support_grcontext,
ui::command_buffer_metrics::BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT);
shared_main_thread_contexts_->AddObserver(this);
auto result = shared_main_thread_contexts_->BindToCurrentThread();
Expand Down Expand Up @@ -1063,7 +1059,6 @@ GpuProcessTransportFactory::CreateContextCommon(
bool support_locking,
bool support_gles2_interface,
bool support_raster_interface,
bool support_grcontext,
ui::command_buffer_metrics::ContextType type) {
DCHECK(gpu_channel_host);
DCHECK(!is_gpu_compositing_disabled_);
Expand Down Expand Up @@ -1104,8 +1099,7 @@ GpuProcessTransportFactory::CreateContextCommon(
return base::MakeRefCounted<ui::ContextProviderCommandBuffer>(
std::move(gpu_channel_host), GetGpuMemoryBufferManager(), stream_id,
stream_priority, surface_handle, url, automatic_flushes, support_locking,
support_grcontext, gpu::SharedMemoryLimits(), attributes,
nullptr /* share_context */, type);
gpu::SharedMemoryLimits(), attributes, nullptr /* share_context */, type);
}

} // namespace content
1 change: 0 additions & 1 deletion content/browser/compositor/gpu_process_transport_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class GpuProcessTransportFactory : public ui::ContextFactory,
bool support_locking,
bool support_gles2_interface,
bool support_raster_interface,
bool support_grcontext,
ui::command_buffer_metrics::ContextType type);

viz::FrameSinkIdAllocator frame_sink_id_allocator_;
Expand Down
8 changes: 2 additions & 6 deletions content/browser/compositor/viz_process_transport_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ scoped_refptr<ui::ContextProviderCommandBuffer> CreateContextProviderImpl(
bool support_locking,
bool support_gles2_interface,
bool support_raster_interface,
bool support_grcontext,
ui::command_buffer_metrics::ContextType type) {
constexpr bool kAutomaticFlushes = false;

Expand All @@ -69,7 +68,7 @@ scoped_refptr<ui::ContextProviderCommandBuffer> CreateContextProviderImpl(
return base::MakeRefCounted<ui::ContextProviderCommandBuffer>(
std::move(gpu_channel_host), gpu_memory_buffer_manager,
kGpuStreamIdDefault, kGpuStreamPriorityUI, gpu::kNullSurfaceHandle,
std::move(url), kAutomaticFlushes, support_locking, support_grcontext,
std::move(url), kAutomaticFlushes, support_locking,
gpu::SharedMemoryLimits(), attributes, nullptr /* share_context */, type);
}

Expand Down Expand Up @@ -520,11 +519,9 @@ bool VizProcessTransportFactory::CreateContextProviders(
constexpr bool kSharedWorkerContextSupportsLocking = true;
constexpr bool kSharedWorkerContextSupportsGLES2 = false;
constexpr bool kSharedWorkerContextSupportsRaster = true;
constexpr bool kSharedWorkerContextSupportsGrContext = false;
constexpr bool kCompositorContextSupportsLocking = false;
constexpr bool kCompositorContextSupportsGLES2 = true;
constexpr bool kCompositorContextSupportsRaster = false;
constexpr bool kCompositorContextSupportsGrContext = true;

if (main_context_provider_ && IsContextLost(main_context_provider_.get())) {
main_context_provider_->RemoveObserver(this);
Expand All @@ -540,7 +537,6 @@ bool VizProcessTransportFactory::CreateContextProviders(
gpu_channel_host, GetGpuMemoryBufferManager(),
kSharedWorkerContextSupportsLocking, kSharedWorkerContextSupportsGLES2,
kSharedWorkerContextSupportsRaster,
kSharedWorkerContextSupportsGrContext,
ui::command_buffer_metrics::BROWSER_WORKER_CONTEXT);

// Don't observer context loss on |worker_context_provider_| here, that is
Expand All @@ -557,7 +553,7 @@ bool VizProcessTransportFactory::CreateContextProviders(
main_context_provider_ = CreateContextProviderImpl(
std::move(gpu_channel_host), GetGpuMemoryBufferManager(),
kCompositorContextSupportsLocking, kCompositorContextSupportsGLES2,
kCompositorContextSupportsRaster, kCompositorContextSupportsGrContext,
kCompositorContextSupportsRaster,
ui::command_buffer_metrics::UI_COMPOSITOR_CONTEXT);
main_context_provider_->SetDefaultTaskRunner(resize_task_runner_);
main_context_provider_->AddObserver(this);
Expand Down
Loading

0 comments on commit 60f840e

Please sign in to comment.