Commit 406891a4 authored by Victor Miura's avatar Victor Miura Committed by Commit Bot

oop: Add more APIs to RasterInterface.

BeginGpuRaster / EndGpuRaster should be used to scope use of GPU raster via a
GrContext, so that GrContext and RasterImplementationGLES state can be correctly
invalidated.

crrev.com/c/828079 depends on this change.

BUG=757607

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I3c0b8267bc42a051673fc5ef0f91d89dc8f3686e
Reviewed-on: https://chromium-review.googlesource.com/830888
Commit-Queue: Victor Miura <vmiura@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524582}
parent c13329c6
......@@ -64,6 +64,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::ContextProvider* context_provider)
: context_provider_(context_provider) {
gpu::raster::RasterInterface* ri = context_provider_->RasterContext();
ri->BeginGpuRaster();
class GrContext* gr_context = context_provider_->GrContext();
gr_context->resetContext();
}
~ScopedGrContextAccess() {
gpu::raster::RasterInterface* ri = context_provider_->RasterContext();
ri->EndGpuRaster();
}
private:
viz::ContextProvider* context_provider_;
};
static void RasterizeSource(
const RasterSource* raster_source,
bool resource_has_previous_content,
......@@ -76,7 +97,7 @@ static void RasterizeSource(
ResourceProvider::ScopedWriteLockRaster* resource_lock,
bool use_distance_field_text,
int msaa_sample_count) {
ScopedGpuRaster gpu_raster(context_provider);
ScopedGrContextAccess gr_context_access(context_provider);
gpu::raster::RasterInterface* ri = context_provider->RasterContext();
GLuint texture_id = resource_lock->ConsumeTexture(ri);
......
......@@ -25,6 +25,10 @@ void RasterImplementationGLES::Finish() {
gl_->Finish();
}
void RasterImplementationGLES::Flush() {
gl_->Flush();
}
void RasterImplementationGLES::ShallowFlushCHROMIUM() {
gl_->ShallowFlushCHROMIUM();
}
......@@ -290,5 +294,22 @@ void RasterImplementationGLES::EndRasterCHROMIUM() {
gl_->EndRasterCHROMIUM();
}
void RasterImplementationGLES::BeginGpuRaster() {
// TODO(alokp): Use a trace macro to push/pop markers.
// Using push/pop functions directly incurs cost to evaluate function
// arguments even when tracing is disabled.
gl_->TraceBeginCHROMIUM("BeginGpuRaster", "GpuRasterization");
}
void RasterImplementationGLES::EndGpuRaster() {
// Restore default GL unpack alignment. TextureUploader expects this.
gl_->PixelStorei(GL_UNPACK_ALIGNMENT, 4);
// TODO(alokp): Use a trace macro to push/pop markers.
// Using push/pop functions directly incurs cost to evaluate function
// arguments even when tracing is disabled.
gl_->TraceEndCHROMIUM();
}
} // namespace raster
} // namespace gpu
......@@ -25,6 +25,7 @@ class GLES2_IMPL_EXPORT RasterImplementationGLES : public RasterInterface {
// Command buffer Flush / Finish.
void Finish() override;
void Flush() override;
void ShallowFlushCHROMIUM() override;
void OrderingBarrierCHROMIUM() override;
......@@ -145,6 +146,10 @@ class GLES2_IMPL_EXPORT RasterImplementationGLES : public RasterInterface {
GLfloat post_scale) override;
void EndRasterCHROMIUM() override;
// Raster via GrContext.
void BeginGpuRaster() override;
void EndGpuRaster() override;
private:
gles2::GLES2Interface* gl_;
bool use_texture_storage_;
......
......@@ -23,6 +23,7 @@
using testing::_;
using testing::Return;
using testing::SetArgPointee;
using testing::StrEq;
namespace gpu {
namespace raster {
......@@ -31,6 +32,7 @@ class RasterMockGLES2Interface : public gles2::GLES2InterfaceStub {
public:
// Command buffer Flush / Finish.
MOCK_METHOD0(Finish, void());
MOCK_METHOD0(Flush, void());
MOCK_METHOD0(ShallowFlushCHROMIUM, void());
MOCK_METHOD0(OrderingBarrierCHROMIUM, void());
......@@ -151,6 +153,11 @@ class RasterMockGLES2Interface : public gles2::GLES2InterfaceStub {
GLfloat post_translate_y,
GLfloat post_scale));
MOCK_METHOD0(EndRasterCHROMIUM, void());
MOCK_METHOD2(PixelStorei, void(GLenum pname, GLint param));
MOCK_METHOD2(TraceBeginCHROMIUM,
void(const char* category_name, const char* trace_name));
MOCK_METHOD0(TraceEndCHROMIUM, void());
};
class RasterImplementationGLESTest : public testing::Test {
......@@ -178,6 +185,11 @@ TEST_F(RasterImplementationGLESTest, Finish) {
ri_->Finish();
}
TEST_F(RasterImplementationGLESTest, Flush) {
EXPECT_CALL(*gl_, Flush()).Times(1);
ri_->Flush();
}
TEST_F(RasterImplementationGLESTest, ShallowFlushCHROMIUM) {
EXPECT_CALL(*gl_, ShallowFlushCHROMIUM()).Times(1);
ri_->ShallowFlushCHROMIUM();
......@@ -632,5 +644,18 @@ TEST_F(RasterImplementationGLESTest, EndRasterCHROMIUM) {
ri_->EndRasterCHROMIUM();
}
TEST_F(RasterImplementationGLESTest, BeginGpuRaster) {
EXPECT_CALL(*gl_, TraceBeginCHROMIUM(StrEq("BeginGpuRaster"),
StrEq("GpuRasterization")))
.Times(1);
ri_->BeginGpuRaster();
}
TEST_F(RasterImplementationGLESTest, EndGpuRaster) {
EXPECT_CALL(*gl_, PixelStorei(GL_UNPACK_ALIGNMENT, 4)).Times(1);
EXPECT_CALL(*gl_, TraceEndCHROMIUM()).Times(1);
ri_->EndGpuRaster();
}
} // namespace raster
} // namespace gpu
......@@ -28,6 +28,7 @@ class RasterInterface {
// Command buffer Flush / Finish.
virtual void Finish() = 0;
virtual void Flush() = 0;
virtual void ShallowFlushCHROMIUM() = 0;
virtual void OrderingBarrierCHROMIUM() = 0;
......@@ -150,6 +151,10 @@ class RasterInterface {
GLfloat post_translate_y,
GLfloat post_scale) = 0;
virtual void EndRasterCHROMIUM() = 0;
// Raster via GrContext.
virtual void BeginGpuRaster() = 0;
virtual void EndGpuRaster() = 0;
};
} // namespace raster
......
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