Skip to content

Commit

Permalink
Modified old wait sync point functions to also accept new sync tokens.
Browse files Browse the repository at this point in the history
In order to help with refactoring old sync points into new sync points,
glWaitSyncPointCHROMIUM() has been changed to accept both the old and
new sync points.

This CL only refactors all the ways we pass around sync points so in
theory shouldn't change any behavior. Once this lands we can then
incrementally change the sync point insertions to the new sync points.

R=piman@chromium.org
BUG=514815
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

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

Cr-Commit-Position: refs/heads/master@{#357595}
  • Loading branch information
dyen authored and Commit bot committed Nov 3, 2015
1 parent 55df5b2 commit cc16ed4
Show file tree
Hide file tree
Showing 140 changed files with 1,326 additions and 1,031 deletions.
1 change: 1 addition & 0 deletions cc/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include_rules = [
"+gpu/command_buffer/common/gpu_memory_allocation.h",
"+gpu/command_buffer/common/mailbox.h",
"+gpu/command_buffer/common/mailbox_holder.h",
"+gpu/command_buffer/common/sync_token.h",
"+media",
"+skia/ext",
"+third_party/khronos/GLES2/gl2.h",
Expand Down
18 changes: 14 additions & 4 deletions cc/blink/web_external_texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ bool WebExternalTextureLayerImpl::PrepareTextureMailbox(
if (bitmap) {
*mailbox = cc::TextureMailbox(bitmap->shared_bitmap(), bitmap->size());
} else {
gpu::SyncToken sync_token;
static_assert(sizeof(sync_token) <= sizeof(client_mailbox.syncToken),
"Size of web external sync token too small.");
if (client_mailbox.validSyncToken)
memcpy(&sync_token, client_mailbox.syncToken, sizeof(sync_token));

// TODO(achaulk): pass a valid size here if allowOverlay is set.
*mailbox = cc::TextureMailbox(name, GL_TEXTURE_2D, client_mailbox.syncPoint,
gfx::Size(), client_mailbox.allowOverlay);
*mailbox = cc::TextureMailbox(name, sync_token, GL_TEXTURE_2D, gfx::Size(),
client_mailbox.allowOverlay);
}
mailbox->set_nearest_neighbor(client_mailbox.nearestNeighbor);

Expand Down Expand Up @@ -112,12 +118,16 @@ void WebExternalTextureLayerImpl::DidReleaseMailbox(
base::WeakPtr<WebExternalTextureLayerImpl> layer,
const blink::WebExternalTextureMailbox& mailbox,
WebExternalBitmapImpl* bitmap,
unsigned sync_point,
const gpu::SyncToken& sync_token,
bool lost_resource) {
DCHECK(layer);
blink::WebExternalTextureMailbox available_mailbox;
static_assert(sizeof(sync_token) <= sizeof(available_mailbox.syncToken),
"Size of web external sync token too small.");
memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name));
available_mailbox.syncPoint = sync_point;
memcpy(available_mailbox.syncToken, sync_token.GetConstData(),
sizeof(sync_token));
available_mailbox.validSyncToken = sync_token.HasData();
if (bitmap)
layer->free_bitmaps_.push_back(bitmap);
layer->client_->mailboxReleased(available_mailbox, lost_resource);
Expand Down
2 changes: 1 addition & 1 deletion cc/blink/web_external_texture_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class WebExternalTextureLayerImpl
base::WeakPtr<WebExternalTextureLayerImpl> layer,
const blink::WebExternalTextureMailbox& mailbox,
WebExternalBitmapImpl* bitmap,
unsigned sync_point,
const gpu::SyncToken& sync_token,
bool lost_resource);

WebExternalBitmapImpl* AllocateBitmap();
Expand Down
23 changes: 12 additions & 11 deletions cc/layers/texture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ void TextureLayer::SetTextureMailbox(
mailbox, release_callback.Pass(), requires_commit, allow_mailbox_reuse);
}

static void IgnoreReleaseCallback(uint32 sync_point, bool lost) {}
static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) {
}

void TextureLayer::SetTextureMailboxWithoutReleaseCallback(
const TextureMailbox& mailbox) {
Expand All @@ -163,7 +164,7 @@ void TextureLayer::SetTextureMailboxWithoutReleaseCallback(
// multiple times for the same mailbox.
DCHECK(!mailbox.IsValid() || !holder_ref_ ||
!mailbox.Equals(holder_ref_->holder()->mailbox()) ||
mailbox.sync_point() != holder_ref_->holder()->mailbox().sync_point());
mailbox.sync_token() != holder_ref_->holder()->mailbox().sync_token());
scoped_ptr<SingleReleaseCallback> release;
bool requires_commit = true;
bool allow_mailbox_reuse = true;
Expand Down Expand Up @@ -267,9 +268,8 @@ TextureLayer::TextureMailboxHolder::TextureMailboxHolder(
: internal_references_(0),
mailbox_(mailbox),
release_callback_(release_callback.Pass()),
sync_point_(mailbox.sync_point()),
is_lost_(false) {
}
sync_token_(mailbox.sync_token()),
is_lost_(false) {}

TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() {
DCHECK_EQ(0u, internal_references_);
Expand All @@ -283,10 +283,11 @@ TextureLayer::TextureMailboxHolder::Create(
new TextureMailboxHolder(mailbox, release_callback.Pass())));
}

void TextureLayer::TextureMailboxHolder::Return(uint32 sync_point,
bool is_lost) {
void TextureLayer::TextureMailboxHolder::Return(
const gpu::SyncToken& sync_token,
bool is_lost) {
base::AutoLock lock(arguments_lock_);
sync_point_ = sync_point;
sync_token_ = sync_token;
is_lost_ = is_lost;
}

Expand All @@ -307,17 +308,17 @@ void TextureLayer::TextureMailboxHolder::InternalAddRef() {
void TextureLayer::TextureMailboxHolder::InternalRelease() {
DCHECK(main_thread_checker_.CalledOnValidThread());
if (!--internal_references_) {
release_callback_->Run(sync_point_, is_lost_);
release_callback_->Run(sync_token_, is_lost_);
mailbox_ = TextureMailbox();
release_callback_ = nullptr;
}
}

void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread(
uint32 sync_point,
const gpu::SyncToken& sync_token,
bool is_lost,
BlockingTaskRunner* main_thread_task_runner) {
Return(sync_point, is_lost);
Return(sync_token, is_lost);
main_thread_task_runner->PostTask(
FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this));
}
Expand Down
12 changes: 8 additions & 4 deletions cc/layers/texture_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "cc/layers/layer.h"
#include "cc/resources/texture_mailbox.h"

namespace gpu {
struct SyncToken;
}

namespace cc {
class BlockingTaskRunner;
class SingleReleaseCallback;
Expand All @@ -38,7 +42,7 @@ class CC_EXPORT TextureLayer : public Layer {
};

const TextureMailbox& mailbox() const { return mailbox_; }
void Return(uint32 sync_point, bool is_lost);
void Return(const gpu::SyncToken& sync_token, bool is_lost);

// Gets a ReleaseCallback that can be called from another thread. Note: the
// caller must ensure the callback is called.
Expand All @@ -63,7 +67,7 @@ class CC_EXPORT TextureLayer : public Layer {
void InternalAddRef();
void InternalRelease();
void ReturnAndReleaseOnImplThread(
uint32 sync_point,
const gpu::SyncToken& sync_token,
bool is_lost,
BlockingTaskRunner* main_thread_task_runner);

Expand All @@ -73,12 +77,12 @@ class CC_EXPORT TextureLayer : public Layer {
TextureMailbox mailbox_;
scoped_ptr<SingleReleaseCallback> release_callback_;

// This lock guards the sync_point_ and is_lost_ fields because they can be
// This lock guards the sync_token_ and is_lost_ fields because they can be
// accessed on both the impl and main thread. We do this to ensure that the
// values of these fields are well-ordered such that the last call to
// ReturnAndReleaseOnImplThread() defines their values.
base::Lock arguments_lock_;
uint32 sync_point_;
gpu::SyncToken sync_token_;
bool is_lost_;
base::ThreadChecker main_thread_checker_;
DISALLOW_COPY_AND_ASSIGN(TextureMailboxHolder);
Expand Down
2 changes: 1 addition & 1 deletion cc/layers/texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void TextureLayerImpl::FreeTextureMailbox() {
if (own_mailbox_) {
DCHECK(!external_texture_resource_);
if (release_callback_) {
release_callback_->Run(texture_mailbox_.sync_point(), false,
release_callback_->Run(texture_mailbox_.sync_token(), false,
layer_tree_impl()
->task_runner_provider()
->blocking_main_thread_task_runner());
Expand Down
7 changes: 3 additions & 4 deletions cc/layers/texture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
namespace cc {
namespace {

void IgnoreCallback(uint32 sync_point,
void IgnoreCallback(const gpu::SyncToken& sync_token,
bool lost,
BlockingTaskRunner* main_thread_task_runner) {
}
BlockingTaskRunner* main_thread_task_runner) {}

TEST(TextureLayerImplTest, VisibleOpaqueRegion) {
const gfx::Size layer_bounds(100, 100);
Expand Down Expand Up @@ -52,7 +51,7 @@ TEST(TextureLayerImplTest, Occlusion) {
gpu::Mailbox mailbox;
impl.output_surface()->context_provider()->ContextGL()->GenMailboxCHROMIUM(
mailbox.name);
TextureMailbox texture_mailbox(mailbox, GL_TEXTURE_2D, 0);
TextureMailbox texture_mailbox(mailbox, gpu::SyncToken(), GL_TEXTURE_2D);

TextureLayerImpl* texture_layer_impl =
impl.AddChildToRoot<TextureLayerImpl>();
Expand Down
Loading

0 comments on commit cc16ed4

Please sign in to comment.