Skip to content

Commit

Permalink
Refactor references to GLInterface in shared main thread context
Browse files Browse the repository at this point in the history
This CL refactors Canvas2DLayerBridge::FinishRasterTimers() to use
RasterInterface in place of GLES2Interface. It also updates
RasterImplementationGLES::CreateAndConsumeForGpuRaster() so that it can
be called with shared image mailboxes and calls into RasterInterface
during CanvasResourceSharedImage initialization. Finally, it
checks for RasterInterface and GLInterface before making calls in code
shared with WebGL.

The references to GLES2Interface are being removed as part of the
OOPR-Canvas2D project with the goal of fully transitioning Canvas2D to
use RasterInterface. For more info about the project see the tracking
bug here: crbug.com/1018894

Bug: 1018898
Change-Id: If2bcb8dc5ba88fa4b41322cfefa83397671736d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891851
Commit-Queue: Nathan Zabriskie <nazabris@microsoft.com>
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716407}
  • Loading branch information
NathanZabriskie authored and Commit Bot committed Nov 19, 2019
1 parent 5922682 commit 0db1d9e
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 68 deletions.
2 changes: 1 addition & 1 deletion cc/raster/gpu_raster_buffer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void RasterizeSource(
// valid by the time the consume command executes.
ri->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
}
GLuint texture_id = ri->CreateAndConsumeForGpuRaster(mailbox->name);
GLuint texture_id = ri->CreateAndConsumeForGpuRaster(*mailbox);
{
ScopedGrContextAccess gr_context_access(context_provider);
base::Optional<viz::ClientResourceProvider::ScopedSkSurface> scoped_surface;
Expand Down
10 changes: 10 additions & 0 deletions content/renderer/webgraphicscontext3d_provider_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ bool WebGraphicsContext3DProviderImpl::BindToCurrentThread() {
return provider_->BindToCurrentThread() == gpu::ContextResult::kSuccess;
}

gpu::InterfaceBase* WebGraphicsContext3DProviderImpl::InterfaceBase() {
if (ContextGL())
return ContextGL();
if (RasterInterface())
return RasterInterface();
if (WebGPUInterface())
return WebGPUInterface();
return nullptr;
}

gpu::gles2::GLES2Interface* WebGraphicsContext3DProviderImpl::ContextGL() {
return provider_->ContextGL();
}
Expand Down
14 changes: 4 additions & 10 deletions content/renderer/webgraphicscontext3d_provider_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@
#include "base/memory/ref_counted.h"
#include "components/viz/common/gpu/context_provider.h"
#include "content/common/content_export.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/client/raster_interface.h"
#include "gpu/command_buffer/client/webgpu_interface.h"
#include "third_party/blink/public/platform/web_graphics_context_3d_provider.h"

namespace cc {
class ImageDecodeCache;
} // namespace cc

namespace gpu {
namespace gles2 {
class GLES2Interface;
} // namespace gles2

namespace raster {
class RasterInterface;
} // namespace raster
} // namespace gpu

namespace viz {
class ContextProviderCommandBuffer;
class GLHelper;
Expand All @@ -43,6 +36,7 @@ class CONTENT_EXPORT WebGraphicsContext3DProviderImpl

// WebGraphicsContext3DProvider implementation.
bool BindToCurrentThread() override;
gpu::InterfaceBase* InterfaceBase() override;
gpu::gles2::GLES2Interface* ContextGL() override;
gpu::raster::RasterInterface* RasterInterface() override;
gpu::webgpu::WebGPUInterface* WebGPUInterface() override;
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/raster_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ void RasterImplementation::IssueImageDecodeCacheEntryCreation(
}

GLuint RasterImplementation::CreateAndConsumeForGpuRaster(
const GLbyte* mailbox) {
const gpu::Mailbox& mailbox) {
NOTREACHED();
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/raster_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class RASTER_EXPORT RasterImplementation : public RasterInterface,
uint32_t transfer_cache_entry_id,
const gfx::ColorSpace& target_color_space,
bool needs_mips) override;
GLuint CreateAndConsumeForGpuRaster(const GLbyte* mailbox) override;
GLuint CreateAndConsumeForGpuRaster(const gpu::Mailbox& mailbox) override;
void DeleteGpuRasterTexture(GLuint texture) override;
void BeginGpuRaster() override;
void EndGpuRaster() override;
Expand Down
8 changes: 6 additions & 2 deletions gpu/command_buffer/client/raster_implementation_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ SyncToken RasterImplementationGLES::ScheduleImageDecode(
}

GLuint RasterImplementationGLES::CreateAndConsumeForGpuRaster(
const GLbyte* mailbox) {
return gl_->CreateAndConsumeTextureCHROMIUM(mailbox);
const gpu::Mailbox& mailbox) {
if (mailbox.IsSharedImage()) {
return gl_->CreateAndTexStorage2DSharedImageCHROMIUM(mailbox.name);
} else {
return gl_->CreateAndConsumeTextureCHROMIUM(mailbox.name);
}
}

void RasterImplementationGLES::DeleteGpuRasterTexture(GLuint texture) {
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/raster_implementation_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RASTER_EXPORT RasterImplementationGLES : public RasterInterface {
bool needs_mips) override;

// Raster via GrContext.
GLuint CreateAndConsumeForGpuRaster(const GLbyte* mailbox) override;
GLuint CreateAndConsumeForGpuRaster(const gpu::Mailbox& mailbox) override;
void DeleteGpuRasterTexture(GLuint texture) override;
void BeginGpuRaster() override;
void EndGpuRaster() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ TEST_F(RasterImplementationGLESTest, DeleteGpuRasterTexture) {
.WillOnce(Return(texture_id))
.RetiresOnSaturation();

EXPECT_EQ(texture_id, ri_->CreateAndConsumeForGpuRaster(mailbox.name));
EXPECT_EQ(texture_id, ri_->CreateAndConsumeForGpuRaster(mailbox));

EXPECT_CALL(*gl_, DeleteTextures(1, _)).Times(1);
ri_->DeleteGpuRasterTexture(texture_id);
Expand All @@ -424,7 +424,7 @@ TEST_F(RasterImplementationGLESTest, CreateAndConsumeForGpuRaster) {

EXPECT_CALL(*gl_, CreateAndConsumeTextureCHROMIUM(mailbox.name))
.WillOnce(Return(kTextureId));
texture_id = ri_->CreateAndConsumeForGpuRaster(mailbox.name);
texture_id = ri_->CreateAndConsumeForGpuRaster(mailbox);
EXPECT_EQ(kTextureId, texture_id);
}

Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/client/raster_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class RasterInterface : public InterfaceBase {
bool needs_mips) = 0;

// Raster via GrContext.
virtual GLuint CreateAndConsumeForGpuRaster(const GLbyte* mailbox) = 0;
virtual GLuint CreateAndConsumeForGpuRaster(const gpu::Mailbox& mailbox) = 0;
virtual void DeleteGpuRasterTexture(GLuint texture) = 0;
virtual void BeginGpuRaster() = 0;
virtual void EndGpuRaster() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ gpu::raster::RasterInterface* ContextProviderCommandBuffer::RasterInterface() {
return raster_interface_.get();

if (!attributes_.enable_raster_interface) {
DLOG(ERROR) << "Unexpected access to RasterInterface()";
return nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class VideoFrame;
namespace gpu {
struct Capabilities;
struct GpuFeatureInfo;
class InterfaceBase;
class SharedImageInterface;

namespace gles2 {
Expand Down Expand Up @@ -90,6 +91,7 @@ class WebGraphicsContext3DProvider {
public:
virtual ~WebGraphicsContext3DProvider() = default;

virtual gpu::InterfaceBase* InterfaceBase() = 0;
virtual gpu::gles2::GLES2Interface* ContextGL() = 0;
virtual gpu::raster::RasterInterface* RasterInterface() = 0;
virtual gpu::webgpu::WebGPUInterface* WebGPUInterface() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,26 +476,26 @@ void Canvas2DLayerBridge::SkipQueuedDrawCommands() {
}

void Canvas2DLayerBridge::ClearPendingRasterTimers() {
gpu::gles2::GLES2Interface* gl_interface = nullptr;
gpu::raster::RasterInterface* raster_interface = nullptr;
if (IsAccelerated() && SharedGpuContext::ContextProviderWrapper() &&
SharedGpuContext::ContextProviderWrapper()->ContextProvider()) {
gl_interface = SharedGpuContext::ContextProviderWrapper()
->ContextProvider()
->ContextGL();
raster_interface = SharedGpuContext::ContextProviderWrapper()
->ContextProvider()
->RasterInterface();
}

if (gl_interface) {
if (raster_interface) {
while (!pending_raster_timers_.IsEmpty()) {
RasterTimer rt = pending_raster_timers_.TakeFirst();
gl_interface->DeleteQueriesEXT(1, &rt.gl_query_id);
raster_interface->DeleteQueriesEXT(1, &rt.gl_query_id);
}
} else {
pending_raster_timers_.clear();
}
}

void Canvas2DLayerBridge::FinishRasterTimers(
gpu::gles2::GLES2Interface* gl_interface) {
gpu::raster::RasterInterface* raster_interface) {
// If the context was lost, then the old queries are not valid anymore
if (!CheckResourceProviderValid()) {
ClearPendingRasterTimers();
Expand All @@ -506,16 +506,16 @@ void Canvas2DLayerBridge::FinishRasterTimers(
while (!pending_raster_timers_.IsEmpty()) {
auto it = pending_raster_timers_.begin();
GLuint complete = 1;
gl_interface->GetQueryObjectuivEXT(
raster_interface->GetQueryObjectuivEXT(
it->gl_query_id, GL_QUERY_RESULT_AVAILABLE_NO_FLUSH_CHROMIUM_EXT,
&complete);
if (!complete) {
break;
}

GLuint raw_gpu_duration = 0u;
gl_interface->GetQueryObjectuivEXT(it->gl_query_id, GL_QUERY_RESULT_EXT,
&raw_gpu_duration);
raster_interface->GetQueryObjectuivEXT(it->gl_query_id, GL_QUERY_RESULT_EXT,
&raw_gpu_duration);
base::TimeDelta gpu_duration_microseconds =
base::TimeDelta::FromMicroseconds(raw_gpu_duration);
base::TimeDelta total_time =
Expand All @@ -534,7 +534,7 @@ void Canvas2DLayerBridge::FinishRasterTimers(
"Blink.Canvas.RasterDuration.Accelerated.Total", total_time, min, max,
num_buckets);

gl_interface->DeleteQueriesEXT(1, &it->gl_query_id);
raster_interface->DeleteQueriesEXT(1, &it->gl_query_id);

pending_raster_timers_.erase(it);
}
Expand All @@ -546,19 +546,19 @@ void Canvas2DLayerBridge::FlushRecording() {

TRACE_EVENT0("cc", "Canvas2DLayerBridge::flushRecording");

gpu::gles2::GLES2Interface* gl_interface = nullptr;
gpu::raster::RasterInterface* raster_interface = nullptr;
if (IsAccelerated() && SharedGpuContext::ContextProviderWrapper() &&
SharedGpuContext::ContextProviderWrapper()->ContextProvider()) {
gl_interface = SharedGpuContext::ContextProviderWrapper()
->ContextProvider()
->ContextGL();
FinishRasterTimers(gl_interface);
raster_interface = SharedGpuContext::ContextProviderWrapper()
->ContextProvider()
->RasterInterface();
FinishRasterTimers(raster_interface);
}

// Sample one out of every kRasterMetricProbability frames to time
// This measurement only makes sense if deferral is enabled
// If the canvas is accelerated, we also need access to the gl_interface
bool measure_raster_metric = (gl_interface || !IsAccelerated()) &&
bool measure_raster_metric = (raster_interface || !IsAccelerated()) &&
is_deferral_enabled_ &&
bernoulli_distribution_(random_generator_);
RasterTimer rasterTimer;
Expand All @@ -567,8 +567,8 @@ void Canvas2DLayerBridge::FlushRecording() {
if (measure_raster_metric) {
if (IsAccelerated()) {
GLuint gl_id = 0u;
gl_interface->GenQueriesEXT(1, &gl_id);
gl_interface->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, gl_id);
raster_interface->GenQueriesEXT(1, &gl_id);
raster_interface->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, gl_id);
rasterTimer.gl_query_id = gl_id;
}
timer.emplace();
Expand All @@ -590,7 +590,7 @@ void Canvas2DLayerBridge::FlushRecording() {
if (measure_raster_metric) {
if (IsAccelerated()) {
rasterTimer.cpu_raster_duration = timer->Elapsed();
gl_interface->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
raster_interface->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
pending_raster_timers_.push_back(rasterTimer);
} else {
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
Expand Down Expand Up @@ -641,14 +641,17 @@ bool Canvas2DLayerBridge::Restore() {
return false;
DCHECK(!ResourceProvider());

gpu::gles2::GLES2Interface* shared_gl = nullptr;
gpu::raster::RasterInterface* shared_raster_interface = nullptr;
layer_->ClearTexture();
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper =
SharedGpuContext::ContextProviderWrapper();
if (context_provider_wrapper)
shared_gl = context_provider_wrapper->ContextProvider()->ContextGL();
if (context_provider_wrapper) {
shared_raster_interface =
context_provider_wrapper->ContextProvider()->RasterInterface();
}

if (shared_gl && shared_gl->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
if (shared_raster_interface &&
shared_raster_interface->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
CanvasResourceProvider* resource_provider =
resource_host_->GetOrCreateCanvasResourceProviderImpl(
kPreferAcceleration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "cc/layers/texture_layer_client.h"
#include "components/viz/common/resources/transferable_resource.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/client/raster_interface.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/geometry/int_size.h"
#include "third_party/blink/renderer/platform/graphics/canvas_color_params.h"
Expand Down Expand Up @@ -217,7 +217,7 @@ class PLATFORM_EXPORT Canvas2DLayerBridge : public cc::TextureLayerClient {
mutable SnapshotState snapshot_state_;

void ClearPendingRasterTimers();
void FinishRasterTimers(gpu::gles2::GLES2Interface*);
void FinishRasterTimers(gpu::raster::RasterInterface*);
struct RasterTimer {
// The id for querying the duration of the gpu-side of the draw
GLuint gl_query_id = 0u;
Expand Down

0 comments on commit 0db1d9e

Please sign in to comment.