Skip to content

Commit

Permalink
Use TestGLES2Interface in paint op buffer fuzzer
Browse files Browse the repository at this point in the history
Currently this uses Skia's null GL interface which the Skia team would
like to delete.

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: Id69939464f5677bdd18aad6ae5e377dd98294648
Reviewed-on: https://chromium-review.googlesource.com/806716
Commit-Queue: Brian Salomon <bsalomon@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523485}
  • Loading branch information
bsalomon authored and Commit Bot committed Dec 12, 2017
1 parent 54794b5 commit 2c30e2d
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 34 deletions.
1 change: 1 addition & 0 deletions cc/paint/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fuzzer_test("paint_op_buffer_fuzzer") {
libfuzzer_options = [ "max_len=4096" ]

deps = [
"//cc:test_support",
"//cc/paint",
]
}
Expand Down
9 changes: 7 additions & 2 deletions cc/paint/oop_pixeltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,13 @@ class OopPixelTest : public testing::Test {
}
gpu::Capabilities capabilities;
gpu::gles2::GLES2Interface* gl = context_->GetImplementation();
skia_bindings::GrContextForGLES2Interface scoped_grcontext(gl,
capabilities);
size_t max_resource_cache_bytes;
size_t max_glyph_cache_texture_bytes;
skia_bindings::GrContextForGLES2Interface::DefaultCacheLimitsForTests(
&max_resource_cache_bytes, &max_glyph_cache_texture_bytes);
skia_bindings::GrContextForGLES2Interface scoped_grcontext(
gl, capabilities, max_resource_cache_bytes,
max_glyph_cache_texture_bytes);
SkImageInfo image_info = SkImageInfo::MakeN32Premul(
options.bitmap_rect.width(), options.bitmap_rect.height());
auto surface = SkSurface::MakeRenderTarget(scoped_grcontext.get(),
Expand Down
10 changes: 4 additions & 6 deletions cc/paint/paint_op_buffer_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <stdint.h>

#include "cc/paint/paint_op_buffer.h"
#include "cc/test/test_context_provider.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"

// Deserialize an arbitrary number of cc::PaintOps and raster them
// using gpu raster into an SkCanvas.
Expand All @@ -18,12 +18,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {

SkImageInfo image_info = SkImageInfo::MakeN32(
kRasterDimension, kRasterDimension, kOpaque_SkAlphaType);
sk_sp<const GrGLInterface> gl_interface(GrGLCreateNullInterface());
sk_sp<GrContext> gr_context(GrContext::Create(
kOpenGL_GrBackend,
reinterpret_cast<GrBackendContext>(gl_interface.get())));
scoped_refptr<cc::TestContextProvider> context_provider =
cc::TestContextProvider::Create();
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(
gr_context.get(), SkBudgeted::kYes, image_info);
context_provider->GrContext(), SkBudgeted::kYes, image_info);
SkCanvas* canvas = surface->getCanvas();

cc::PlaybackParams params(nullptr, canvas->getTotalMatrix());
Expand Down
13 changes: 12 additions & 1 deletion cc/test/test_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class TestGLES2InterfaceForContextProvider : public TestGLES2Interface {
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
*params = 8;
return;
case GL_MAX_TEXTURE_SIZE:
*params = 2048;
break;
case GL_MAX_RENDERBUFFER_SIZE:
*params = 2048;
break;
default:
break;
}
Expand Down Expand Up @@ -241,8 +247,13 @@ class GrContext* TestContextProvider::GrContext() {
if (gr_context_)
return gr_context_->get();

size_t max_resource_cache_bytes;
size_t max_glyph_cache_texture_bytes;
skia_bindings::GrContextForGLES2Interface::DefaultCacheLimitsForTests(
&max_resource_cache_bytes, &max_glyph_cache_texture_bytes);
gr_context_ = std::make_unique<skia_bindings::GrContextForGLES2Interface>(
context_gl_.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());

// If GlContext is already lost, also abandon the new GrContext.
Expand Down
7 changes: 6 additions & 1 deletion cc/test/test_in_process_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ class GrContext* TestInProcessContextProvider::GrContext() {
if (gr_context_)
return gr_context_->get();

size_t max_resource_cache_bytes;
size_t max_glyph_cache_texture_bytes;
skia_bindings::GrContextForGLES2Interface::DefaultCacheLimitsForTests(
&max_resource_cache_bytes, &max_glyph_cache_texture_bytes);
gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(
ContextGL(), ContextCapabilities()));
ContextGL(), ContextCapabilities(), max_resource_cache_bytes,
max_glyph_cache_texture_bytes));
cache_controller_->SetGrContext(gr_context_->get());
return gr_context_->get();
}
Expand Down
9 changes: 8 additions & 1 deletion components/viz/common/gpu/in_process_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@ class GrContext* InProcessContextProvider::GrContext() {
if (gr_context_)
return gr_context_->get();

size_t max_resource_cache_bytes;
size_t max_glyph_cache_texture_bytes;
skia_bindings::GrContextForGLES2Interface::
DetermineCacheLimitsFromAvailableMemory(&max_resource_cache_bytes,
&max_glyph_cache_texture_bytes);

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

Expand Down
53 changes: 33 additions & 20 deletions gpu/skia_bindings/grcontext_for_gles2_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@

namespace skia_bindings {

GrContextForGLES2Interface::GrContextForGLES2Interface(
gpu::gles2::GLES2Interface* gl,
const gpu::Capabilities& capabilities) {
// Calculate limits to pass during initialization:
// The limit of the number of GPU resources we hold in the GrContext's
// GPU cache.
static const int kMaxGaneshResourceCacheCount = 16384;
void GrContextForGLES2Interface::DetermineCacheLimitsFromAvailableMemory(
size_t* max_resource_cache_bytes,
size_t* max_glyph_cache_texture_bytes) {
// The limit of the bytes allocated toward GPU resources in the GrContext's
// GPU cache.
static const size_t kMaxLowEndGaneshResourceCacheBytes = 48 * 1024 * 1024;
Expand All @@ -40,29 +36,46 @@ GrContextForGLES2Interface::GrContextForGLES2Interface(
static const int64_t kHighEndMemoryThreshold = (int64_t)4096 * 1024 * 1024;
static const int64_t kLowEndMemoryThreshold = (int64_t)512 * 1024 * 1024;

size_t max_ganesh_resource_cache_bytes = kMaxGaneshResourceCacheBytes;
int max_glyph_cache_texture_bytes = kMaxDefaultGlyphCacheTextureBytes;
if (base::SysInfo::AmountOfPhysicalMemory() <= kLowEndMemoryThreshold) {
max_ganesh_resource_cache_bytes = kMaxLowEndGaneshResourceCacheBytes;
max_glyph_cache_texture_bytes = kMaxLowEndGlyphCacheTextureBytes;
} else if (base::SysInfo::AmountOfPhysicalMemory() >=
kHighEndMemoryThreshold) {
max_ganesh_resource_cache_bytes = kMaxHighEndGaneshResourceCacheBytes;
int64_t amount_of_physical_memory = base::SysInfo::AmountOfPhysicalMemory();

*max_resource_cache_bytes = kMaxGaneshResourceCacheBytes;
*max_glyph_cache_texture_bytes = kMaxDefaultGlyphCacheTextureBytes;
if (amount_of_physical_memory <= kLowEndMemoryThreshold) {
*max_resource_cache_bytes = kMaxLowEndGaneshResourceCacheBytes;
*max_glyph_cache_texture_bytes = kMaxLowEndGlyphCacheTextureBytes;
} else if (amount_of_physical_memory >= kHighEndMemoryThreshold) {
*max_resource_cache_bytes = kMaxHighEndGaneshResourceCacheBytes;
}
}

void GrContextForGLES2Interface::DefaultCacheLimitsForTests(
size_t* max_resource_cache_bytes,
size_t* max_glyph_cache_texture_bytes) {
static const size_t kDefaultGlyphCacheTextureBytes = 2048 * 1024 * 4;
static const size_t kDefaultGaneshResourceCacheBytes = 96 * 1024 * 1024;
*max_resource_cache_bytes = kDefaultGaneshResourceCacheBytes;
*max_glyph_cache_texture_bytes = kDefaultGlyphCacheTextureBytes;
}

GrContextForGLES2Interface::GrContextForGLES2Interface(
gpu::gles2::GLES2Interface* gl,
const gpu::Capabilities& capabilities,
size_t max_resource_cache_bytes,
size_t max_glyph_cache_texture_bytes) {
// The limit of the number of GPU resources we hold in the GrContext's
// GPU cache.
static const int kMaxGaneshResourceCacheCount = 16384;

GrContextOptions options;
options.fGlyphCacheTextureMaximumBytes = max_glyph_cache_texture_bytes;
options.fAvoidStencilBuffers = capabilities.avoid_stencil_buffers;
options.fAllowPathMaskCaching = false;
sk_sp<GrGLInterface> interface(
skia_bindings::CreateGLES2InterfaceBindings(gl));
gr_context_ = sk_sp<GrContext>(GrContext::Create(
kOpenGL_GrBackend,
// GrContext takes ownership of |interface|.
reinterpret_cast<GrBackendContext>(interface.get()), options));
gr_context_ = GrContext::MakeGL(std::move(interface), options);
if (gr_context_) {
gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
max_ganesh_resource_cache_bytes);
max_resource_cache_bytes);
}
}

Expand Down
12 changes: 11 additions & 1 deletion gpu/skia_bindings/grcontext_for_gles2_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ namespace skia_bindings {
// is alive.
class GrContextForGLES2Interface {
public:
static void DetermineCacheLimitsFromAvailableMemory(
size_t* max_resource_cache_bytes,
size_t* max_glyph_cache_texture_bytes);

static void DefaultCacheLimitsForTests(size_t* max_resource_cache_bytes,
size_t* max_glyph_cache_texture_bytes);

explicit GrContextForGLES2Interface(gpu::gles2::GLES2Interface* gl,
const gpu::Capabilities& capabilities);
const gpu::Capabilities& capabilities,
size_t max_resource_cache_bytes,
size_t max_glyph_cache_texture_bytes);

virtual ~GrContextForGLES2Interface();

GrContext* get() { return gr_context_.get(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,14 @@ class GrContext* ContextProviderCommandBuffer::GrContext() {
if (gr_context_)
return gr_context_->get();

size_t max_resource_cache_bytes;
size_t max_glyph_cache_texture_bytes;
skia_bindings::GrContextForGLES2Interface::
DetermineCacheLimitsFromAvailableMemory(&max_resource_cache_bytes,
&max_glyph_cache_texture_bytes);
gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(
ContextGL(), ContextCapabilities()));
ContextGL(), ContextCapabilities(), max_resource_cache_bytes,
max_glyph_cache_texture_bytes));
cache_controller_->SetGrContext(gr_context_->get());

// If GlContext is already lost, also abandon the new GrContext.
Expand Down
7 changes: 6 additions & 1 deletion ui/compositor/test/in_process_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ class GrContext* InProcessContextProvider::GrContext() {
if (gr_context_)
return gr_context_->get();

size_t max_resource_cache_bytes;
size_t max_glyph_cache_texture_bytes;
skia_bindings::GrContextForGLES2Interface::DefaultCacheLimitsForTests(
&max_resource_cache_bytes, &max_glyph_cache_texture_bytes);
gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(
ContextGL(), ContextCapabilities()));
ContextGL(), ContextCapabilities(), max_resource_cache_bytes,
max_glyph_cache_texture_bytes));
cache_controller_->SetGrContext(gr_context_->get());

return gr_context_->get();
Expand Down

0 comments on commit 2c30e2d

Please sign in to comment.