Skip to content

Commit

Permalink
Expose Signal(Query|SyncPoint) via gpu::ContextSupport* instead of WGC3D
Browse files Browse the repository at this point in the history
This exposes calls to register queries and sync points with callbacks by
a new gpu::ContextSupport interface intended to be used directly by clients
who need this functionality like the compositor instead of having to
go through WebKit::WebGraphicsContext3D.  These calls aren't 'proper' OpenGL
as OpenGL doesn't have any notion of callbacks, but are still useful with
our OpenGL implementation.

This also unifies the multiple implementations of these functions a bit.
In particular, now both the in-process and out-of-process contexts check if
the context is lost before dispatching SyncPoint/Query callbacks. Previously
only the in-process implementation did this.

R=piman,sievers
BUG=181120

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230043 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jamesr@chromium.org committed Oct 22, 2013
1 parent b255a8e commit 6ffaaf3
Show file tree
Hide file tree
Showing 40 changed files with 306 additions and 285 deletions.
1 change: 1 addition & 0 deletions cc/DEPS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include_rules = [
"+gpu/GLES2",
"+gpu/command_buffer/client/context_support.h",
"+gpu/command_buffer/common/mailbox.h",
"+media",
"+skia/ext",
Expand Down
4 changes: 2 additions & 2 deletions cc/cc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
'debug/ring_buffer.h',
'debug/test_context_provider.cc',
'debug/test_context_provider.h',
'debug/test_context_support.cc',
'debug/test_context_support.h',
'debug/test_texture.cc',
'debug/test_texture.h',
'debug/test_web_graphics_context_3d.cc',
Expand Down Expand Up @@ -362,8 +364,6 @@
'resources/single_release_callback.h',
'resources/skpicture_content_layer_updater.cc',
'resources/skpicture_content_layer_updater.h',
'resources/sync_point_helper.cc',
'resources/sync_point_helper.h',
'resources/texture_mailbox.cc',
'resources/texture_mailbox.h',
'resources/texture_mailbox_deleter.cc',
Expand Down
9 changes: 9 additions & 0 deletions cc/debug/test_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ TestContextProvider::TestContextProvider(
DCHECK(main_thread_checker_.CalledOnValidThread());
DCHECK(context3d_);
context_thread_checker_.DetachFromThread();
context3d_->set_test_support(&support_);
}

TestContextProvider::~TestContextProvider() {
Expand Down Expand Up @@ -121,6 +122,14 @@ WebKit::WebGraphicsContext3D* TestContextProvider::Context3d() {
return context3d_.get();
}

gpu::ContextSupport* TestContextProvider::ContextSupport() {
DCHECK(context3d_);
DCHECK(bound_);
DCHECK(context_thread_checker_.CalledOnValidThread());

return &support_;
}

class GrContext* TestContextProvider::GrContext() {
DCHECK(context3d_);
DCHECK(bound_);
Expand Down
4 changes: 4 additions & 0 deletions cc/debug/test_context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "cc/base/cc_export.h"
#include "cc/debug/test_context_support.h"
#include "cc/output/context_provider.h"

namespace WebKit { class WebGraphicsContext3D; }
Expand All @@ -30,6 +31,7 @@ class CC_EXPORT TestContextProvider
virtual bool BindToCurrentThread() OVERRIDE;
virtual Capabilities ContextCapabilities() OVERRIDE;
virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
virtual gpu::ContextSupport* ContextSupport() OVERRIDE;
virtual class GrContext* GrContext() OVERRIDE;
virtual void VerifyContexts() OVERRIDE;
virtual bool DestroyedOnMainThread() OVERRIDE;
Expand Down Expand Up @@ -59,6 +61,8 @@ class CC_EXPORT TestContextProvider
void OnLostContext();
void OnSwapBuffersComplete();

TestContextSupport support_;

scoped_ptr<TestWebGraphicsContext3D> context3d_;
bool bound_;

Expand Down
32 changes: 32 additions & 0 deletions cc/debug/test_context_support.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/debug/test_context_support.h"

#include "base/message_loop/message_loop.h"

namespace cc {

TestContextSupport::TestContextSupport() {}
TestContextSupport::~TestContextSupport() {}

void TestContextSupport::SignalSyncPoint(uint32 sync_point,
const base::Closure& callback) {
sync_point_callbacks_.push_back(callback);
}

void TestContextSupport::SignalQuery(uint32 query,
const base::Closure& callback) {
sync_point_callbacks_.push_back(callback);
}

void TestContextSupport::CallAllSyncPointCallbacks() {
for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
base::MessageLoop::current()->PostTask(
FROM_HERE, sync_point_callbacks_[i]);
}
sync_point_callbacks_.clear();
}

} // namespace cc
35 changes: 35 additions & 0 deletions cc/debug/test_context_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_DEBUG_TEST_CONTEXT_SUPPORT_H_
#define CC_DEBUG_TEST_CONTEXT_SUPPORT_H_

#include <vector>

#include "gpu/command_buffer/client/context_support.h"

namespace cc {

class TestContextSupport : public gpu::ContextSupport {
public:
TestContextSupport();
virtual ~TestContextSupport();

// gpu::ContextSupport implementation.
virtual void SignalSyncPoint(uint32 sync_point,
const base::Closure& callback) OVERRIDE;
virtual void SignalQuery(uint32 query,
const base::Closure& callback) OVERRIDE;

void CallAllSyncPointCallbacks();

private:
std::vector<base::Closure> sync_point_callbacks_;

DISALLOW_COPY_AND_ASSIGN(TestContextSupport);
};

} // namespace cc

#endif // CC_DEBUG_TEST_CONTEXT_SUPPORT_H_
64 changes: 11 additions & 53 deletions cc/debug/test_web_graphics_context_3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "cc/debug/test_context_support.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "third_party/khronos/GLES2/gl2ext.h"

Expand Down Expand Up @@ -73,33 +74,16 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D()
max_texture_size_(2048),
width_(0),
height_(0),
test_support_(NULL),
bound_buffer_(0),
weak_ptr_factory_(this) {
CreateNamespace();
test_capabilities_.swapbuffers_complete_callback = true;
}

TestWebGraphicsContext3D::TestWebGraphicsContext3D(
const WebGraphicsContext3D::Attributes& attributes)
: FakeWebGraphicsContext3D(),
context_id_(s_context_id++),
attributes_(attributes),
times_make_current_succeeds_(-1),
times_bind_texture_succeeds_(-1),
times_end_query_succeeds_(-1),
times_gen_mailbox_succeeds_(-1),
context_lost_(false),
times_map_image_chromium_succeeds_(-1),
times_map_buffer_chromium_succeeds_(-1),
context_lost_callback_(NULL),
swap_buffers_callback_(NULL),
max_texture_size_(2048),
width_(0),
height_(0),
bound_buffer_(0),
weak_ptr_factory_(this) {
CreateNamespace();
test_capabilities_.swapbuffers_complete_callback = true;
TestWebGraphicsContext3D::~TestWebGraphicsContext3D() {
base::AutoLock lock(g_shared_namespace_lock.Get());
namespace_ = NULL;
}

void TestWebGraphicsContext3D::CreateNamespace() {
Expand All @@ -116,15 +100,6 @@ void TestWebGraphicsContext3D::CreateNamespace() {
}
}

TestWebGraphicsContext3D::~TestWebGraphicsContext3D() {
for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
if (sync_point_callbacks_[i] != NULL)
delete sync_point_callbacks_[i];
}
base::AutoLock lock(g_shared_namespace_lock.Get());
namespace_ = NULL;
}

bool TestWebGraphicsContext3D::makeContextCurrent() {
if (times_make_current_succeeds_ >= 0) {
if (!times_make_current_succeeds_) {
Expand Down Expand Up @@ -398,13 +373,13 @@ void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current,
void TestWebGraphicsContext3D::signalSyncPoint(
unsigned sync_point,
WebGraphicsSyncPointCallback* callback) {
sync_point_callbacks_.push_back(callback);
NOTREACHED();
}

void TestWebGraphicsContext3D::signalQuery(
WebKit::WebGLId query,
WebGraphicsSyncPointCallback* callback) {
sync_point_callbacks_.push_back(callback);
NOTREACHED();
}

void TestWebGraphicsContext3D::setSwapBuffersCompleteCallbackCHROMIUM(
Expand All @@ -414,38 +389,21 @@ void TestWebGraphicsContext3D::setSwapBuffersCompleteCallbackCHROMIUM(
}

void TestWebGraphicsContext3D::prepareTexture() {
// TODO(jamesr): This should implemented as ContextSupport::SwapBuffers().
if (swap_buffers_callback_) {
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&TestWebGraphicsContext3D::SwapBuffersComplete,
weak_ptr_factory_.GetWeakPtr()));
}
CallAllSyncPointCallbacks();
test_support_->CallAllSyncPointCallbacks();
}

void TestWebGraphicsContext3D::finish() {
CallAllSyncPointCallbacks();
test_support_->CallAllSyncPointCallbacks();
}

void TestWebGraphicsContext3D::flush() {
CallAllSyncPointCallbacks();
}

static void CallAndDestroy(
WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback* callback) {
if (!callback)
return;
callback->onSyncPointReached();
delete callback;
}

void TestWebGraphicsContext3D::CallAllSyncPointCallbacks() {
for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&CallAndDestroy,
sync_point_callbacks_[i]));
}
sync_point_callbacks_.clear();
test_support_->CallAllSyncPointCallbacks();
}

void TestWebGraphicsContext3D::SwapBuffersComplete() {
Expand Down
9 changes: 6 additions & 3 deletions cc/debug/test_web_graphics_context_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "third_party/khronos/GLES2/gl2.h"

namespace cc {
class TestContextSupport;

class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
public:
Expand Down Expand Up @@ -106,7 +107,6 @@ class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
virtual void loseContextCHROMIUM(WebKit::WGC3Denum current,
WebKit::WGC3Denum other);

// Takes ownership of the |callback|.
virtual void signalSyncPoint(unsigned sync_point,
WebGraphicsSyncPointCallback* callback);
virtual void signalQuery(WebKit::WebGLId query,
Expand Down Expand Up @@ -212,6 +212,10 @@ class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
size_t GetTransferBufferMemoryUsedBytes() const;
void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes);

void set_test_support(TestContextSupport* test_support) {
test_support_ = test_support;
}

protected:
struct TextureTargets {
TextureTargets();
Expand Down Expand Up @@ -268,8 +272,6 @@ class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
};

TestWebGraphicsContext3D();
TestWebGraphicsContext3D(
const WebKit::WebGraphicsContext3D::Attributes& attributes);

void CallAllSyncPointCallbacks();
void SwapBuffersComplete();
Expand All @@ -294,6 +296,7 @@ class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
int max_texture_size_;
int width_;
int height_;
TestContextSupport* test_support_;

unsigned bound_buffer_;
TextureTargets texture_targets_;
Expand Down
2 changes: 2 additions & 0 deletions cc/output/context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class GrContext;
namespace WebKit { class WebGraphicsContext3D; }
namespace gpu { class ContextSupport; }

namespace cc {
struct ManagedMemoryPolicy;
Expand All @@ -24,6 +25,7 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
virtual bool BindToCurrentThread() = 0;

virtual WebKit::WebGraphicsContext3D* Context3d() = 0;
virtual gpu::ContextSupport* ContextSupport() = 0;
virtual class GrContext* GrContext() = 0;

struct Capabilities {
Expand Down
15 changes: 7 additions & 8 deletions cc/output/gl_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
#include "cc/quads/texture_draw_quad.h"
#include "cc/resources/layer_quad.h"
#include "cc/resources/scoped_resource.h"
#include "cc/resources/sync_point_helper.h"
#include "cc/resources/texture_mailbox_deleter.h"
#include "cc/trees/damage_tracker.h"
#include "cc/trees/proxy.h"
#include "cc/trees/single_thread_proxy.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/context_support.h"
#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
Expand Down Expand Up @@ -162,6 +162,7 @@ GLRenderer::GLRenderer(RendererClient* client,
offscreen_framebuffer_id_(0),
shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)),
context_(output_surface->context_provider()->Context3d()),
context_support_(output_surface->context_provider()->ContextSupport()),
texture_mailbox_deleter_(texture_mailbox_deleter),
is_backbuffer_discarded_(false),
discard_backbuffer_when_not_visible_(false),
Expand All @@ -174,6 +175,7 @@ GLRenderer::GLRenderer(RendererClient* client,
highp_threshold_cache_(0),
on_demand_tile_raster_resource_id_(0) {
DCHECK(context_);
DCHECK(context_support_);
}

bool GLRenderer::Initialize() {
Expand Down Expand Up @@ -1079,7 +1081,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
// Flush the compositor context before the filter bitmap goes out of
// scope, so the draw gets processed before the filter texture gets deleted.
if (filter_bitmap.getTexture())
context_->flush();
GLC(context_, context_->flush());
}

struct SolidColorProgramUniforms {
Expand Down Expand Up @@ -2056,8 +2058,8 @@ void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame,
}

void GLRenderer::Finish() {
TRACE_EVENT0("cc", "GLRenderer::finish");
context_->finish();
TRACE_EVENT0("cc", "GLRenderer::Finish");
GLC(context_, context_->finish());
}

void GLRenderer::SwapBuffers() {
Expand Down Expand Up @@ -2336,10 +2338,7 @@ void GLRenderer::DoGetFramebufferPixels(
if (is_async) {
GLC(context_, context_->endQueryEXT(
GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM));
SyncPointHelper::SignalQuery(
context_,
query,
finished_callback);
context_support_->SignalQuery(query, finished_callback);
} else {
resource_provider_->Finish();
finished_callback.Run();
Expand Down
1 change: 1 addition & 0 deletions cc/output/gl_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ class CC_EXPORT GLRenderer : public DirectRenderer {
scoped_ptr<SolidColorProgramAA> solid_color_program_aa_;

WebKit::WebGraphicsContext3D* context_;
gpu::ContextSupport* context_support_;

skia::RefPtr<GrContext> gr_context_;
skia::RefPtr<SkCanvas> sk_canvas_;
Expand Down
Loading

0 comments on commit 6ffaaf3

Please sign in to comment.