Skip to content

Commit

Permalink
Moved exo::SurfaceFactoryOwner to its own file and renamed it to exo:…
Browse files Browse the repository at this point in the history
…:CompositorFrameSink.

CompositorFrameSink implements cc::mojom::MojoCompositorFrameSink.

CompositorFrameSink is no longer a friend class of exo::Surface.

Added exo::CompositorFrameSinkHolder class that implements cc::mojom::MojoCompositorFrameSinkClient.

BUG=659601
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2493223002
Review-Url: https://codereview.chromium.org/2493223002
Cr-Commit-Position: refs/heads/master@{#437780}
  • Loading branch information
staraz authored and Commit bot committed Dec 10, 2016
1 parent 39fe426 commit d8f4f64
Show file tree
Hide file tree
Showing 12 changed files with 491 additions and 194 deletions.
4 changes: 4 additions & 0 deletions ash/test/ash_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ void AshTestHelper::SetUp(bool start_session,
void AshTestHelper::TearDown() {
// Tear down the shell.
Shell::DeleteInstance();

// Suspend the tear down until all resources are returned via
// MojoCompositorFrameSinkClient::ReclaimResources()
RunAllPendingInMessageLoop();
material_design_state_.reset();
test::MaterialDesignControllerTestAPI::Uninitialize();
ash_test_environment_->TearDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class DesktopMediaListAshTest : public ash::test::AshTestBase {
DesktopMediaListAshTest() {}
~DesktopMediaListAshTest() override {}

void TearDown() override {
// Reset the unique_ptr so the list stops refreshing.
list_.reset();
ash::test::AshTestBase::TearDown();
}

void CreateList(int source_types) {
list_.reset(new DesktopMediaListAsh(source_types));
list_->SetThumbnailSize(gfx::Size(kThumbnailSize, kThumbnailSize));
Expand Down
5 changes: 5 additions & 0 deletions components/exo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ source_set("exo") {
sources = [
"buffer.cc",
"buffer.h",
"compositor_frame_sink.cc",
"compositor_frame_sink.h",
"compositor_frame_sink_holder.cc",
"compositor_frame_sink_holder.h",
"display.cc",
"display.h",
"gamepad.cc",
Expand Down Expand Up @@ -156,6 +160,7 @@ test("exo_unittests") {
"//base",
"//base/test:test_support",
"//device/gamepad:test_helpers",
"//mojo/edk/embedder:headers",
]

data_deps = [
Expand Down
7 changes: 7 additions & 0 deletions components/exo/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ include_rules = [
"+chromeos/audio/chromeos_sounds.h",
"+device/gamepad",
"+gpu",
"+mojo/public/cpp",
"+services/ui/public/cpp",
"+third_party/khronos",
"+third_party/skia",
"+ui",
]

specific_include_rules = {
"run_all_unittests\.cc": [
"+mojo/edk/embedder/embedder.h",
],
}
101 changes: 101 additions & 0 deletions components/exo/compositor_frame_sink.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2016 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 "components/exo/compositor_frame_sink.h"

#include "cc/surfaces/surface.h"
#include "cc/surfaces/surface_manager.h"
#include "mojo/public/cpp/bindings/strong_binding.h"

namespace exo {

////////////////////////////////////////////////////////////////////////////////
// ExoComopositorFrameSink, public:

// static
void CompositorFrameSink::Create(
const cc::FrameSinkId& frame_sink_id,
cc::SurfaceManager* surface_manager,
cc::mojom::MojoCompositorFrameSinkClientPtr client,
cc::mojom::MojoCompositorFrameSinkRequest request) {
std::unique_ptr<CompositorFrameSink> impl =
base::MakeUnique<CompositorFrameSink>(frame_sink_id, surface_manager,
std::move(client));
CompositorFrameSink* compositor_frame_sink = impl.get();
compositor_frame_sink->binding_ =
mojo::MakeStrongBinding(std::move(impl), std::move(request));
}

CompositorFrameSink::CompositorFrameSink(
const cc::FrameSinkId& frame_sink_id,
cc::SurfaceManager* surface_manager,
cc::mojom::MojoCompositorFrameSinkClientPtr client)
: support_(this, surface_manager, frame_sink_id, nullptr),
client_(std::move(client)) {}

CompositorFrameSink::~CompositorFrameSink() {}

////////////////////////////////////////////////////////////////////////////////
// cc::mojom::MojoCompositorFrameSink overrides:

void CompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) {
support_.SetNeedsBeginFrame(needs_begin_frame);
}

void CompositorFrameSink::SubmitCompositorFrame(
const cc::LocalFrameId& local_frame_id,
cc::CompositorFrame frame) {
support_.SubmitCompositorFrame(local_frame_id, std::move(frame));
}

void CompositorFrameSink::AddSurfaceReferences(
const std::vector<cc::SurfaceReference>& references) {
// TODO(fsamuel, staraz): Implement this.
NOTIMPLEMENTED();
}

void CompositorFrameSink::RemoveSurfaceReferences(
const std::vector<cc::SurfaceReference>& references) {
// TODO(fsamuel, staraz): Implement this.
NOTIMPLEMENTED();
}

void CompositorFrameSink::EvictFrame() {
support_.EvictFrame();
}

void CompositorFrameSink::Require(const cc::LocalFrameId& local_frame_id,
const cc::SurfaceSequence& sequence) {
support_.Require(local_frame_id, sequence);
}

void CompositorFrameSink::Satisfy(const cc::SurfaceSequence& sequence) {
support_.Satisfy(sequence);
}

////////////////////////////////////////////////////////////////////////////////
// cc::CompositorFrameSinkSupportClient overrides:

void CompositorFrameSink::DidReceiveCompositorFrameAck() {
if (client_)
client_->DidReceiveCompositorFrameAck();
}

void CompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) {
if (client_)
client_->OnBeginFrame(args);
}

void CompositorFrameSink::ReclaimResources(
const cc::ReturnedResourceArray& resources) {
if (client_)
client_->ReclaimResources(resources);
}

void CompositorFrameSink::WillDrawSurface() {
if (client_)
client_->WillDrawSurface();
}

} // namespace exo
61 changes: 61 additions & 0 deletions components/exo/compositor_frame_sink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2016 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 COMPONENTS_EXO_EXO_COMPOSITOR_FRAME_SINK_H_
#define COMPONENTS_EXO_EXO_COMPOSITOR_FRAME_SINK_H_

#include "cc/ipc/compositor_frame.mojom.h"
#include "cc/ipc/mojo_compositor_frame_sink.mojom.h"
#include "cc/resources/transferable_resource.h"
#include "cc/surfaces/compositor_frame_sink_support.h"
#include "cc/surfaces/compositor_frame_sink_support_client.h"
#include "mojo/public/cpp/bindings/strong_binding.h"

namespace exo {

class CompositorFrameSink : public cc::CompositorFrameSinkSupportClient,
public cc::mojom::MojoCompositorFrameSink {
public:
static void Create(const cc::FrameSinkId& frame_sink_id,
cc::SurfaceManager* surface_manager,
cc::mojom::MojoCompositorFrameSinkClientPtr client,
cc::mojom::MojoCompositorFrameSinkRequest request);

CompositorFrameSink(const cc::FrameSinkId& frame_sink_id,
cc::SurfaceManager* surface_manager,
cc::mojom::MojoCompositorFrameSinkClientPtr client);

~CompositorFrameSink() override;

// Overridden from cc::mojom::MojoCompositorFrameSink:
void SetNeedsBeginFrame(bool needs_begin_frame) override;
void SubmitCompositorFrame(const cc::LocalFrameId& local_frame_id,
cc::CompositorFrame frame) override;
void AddSurfaceReferences(
const std::vector<cc::SurfaceReference>& references) override;
void RemoveSurfaceReferences(
const std::vector<cc::SurfaceReference>& references) override;
void EvictFrame() override;
void Require(const cc::LocalFrameId& local_frame_id,
const cc::SurfaceSequence& sequence) override;
void Satisfy(const cc::SurfaceSequence& sequence) override;

// Overridden from cc::CompositorFrameSinkSupportClient:
void DidReceiveCompositorFrameAck() override;
void OnBeginFrame(const cc::BeginFrameArgs& args) override;
void ReclaimResources(const cc::ReturnedResourceArray& resources) override;
void WillDrawSurface() override;

private:
cc::CompositorFrameSinkSupport support_;
cc::mojom::MojoCompositorFrameSinkClientPtr client_;
cc::ReturnedResourceArray surface_returned_resources_;
mojo::StrongBindingPtr<cc::mojom::MojoCompositorFrameSink> binding_;

DISALLOW_COPY_AND_ASSIGN(CompositorFrameSink);
};

} // namespace exo

#endif // COMPONENTS_EXO_EXO_COMPOSITOR_FRAME_SINK_H_
142 changes: 142 additions & 0 deletions components/exo/compositor_frame_sink_holder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright 2016 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 "components/exo/compositor_frame_sink_holder.h"

#include "cc/resources/returned_resource.h"
#include "components/exo/surface.h"

namespace exo {

////////////////////////////////////////////////////////////////////////////////
// CompositorFrameSinkHolder, public:

CompositorFrameSinkHolder::CompositorFrameSinkHolder(
Surface* surface,
std::unique_ptr<CompositorFrameSink> frame_sink,
cc::mojom::MojoCompositorFrameSinkClientRequest request)
: surface_(surface),
frame_sink_(std::move(frame_sink)),
begin_frame_source_(base::MakeUnique<cc::ExternalBeginFrameSource>(this)),
binding_(this, std::move(request)),
weak_factory_(this) {
surface_->AddSurfaceObserver(this);
}

bool CompositorFrameSinkHolder::HasReleaseCallbackForResource(
cc::ResourceId id) {
return release_callbacks_.find(id) != release_callbacks_.end();
}

void CompositorFrameSinkHolder::AddResourceReleaseCallback(
cc::ResourceId id,
std::unique_ptr<cc::SingleReleaseCallback> callback) {
release_callbacks_[id] = std::make_pair(this, std::move(callback));
}

void CompositorFrameSinkHolder::ActivateFrameCallbacks(
std::list<FrameCallback>* frame_callbacks) {
active_frame_callbacks_.splice(active_frame_callbacks_.end(),
*frame_callbacks);
UpdateNeedsBeginFrame();
}

void CompositorFrameSinkHolder::CancelFrameCallbacks() {
// Call pending frame callbacks with a null frame time to indicate that they
// have been cancelled.
for (const auto& frame_callback : active_frame_callbacks_)
frame_callback.Run(base::TimeTicks());
}

void CompositorFrameSinkHolder::SetNeedsBeginFrame(bool needs_begin_frame) {
needs_begin_frame_ = needs_begin_frame;
OnNeedsBeginFrames(needs_begin_frame);
}

void CompositorFrameSinkHolder::Satisfy(const cc::SurfaceSequence& sequence) {
frame_sink_->Satisfy(sequence);
}

void CompositorFrameSinkHolder::Require(const cc::SurfaceId& id,
const cc::SurfaceSequence& sequence) {
frame_sink_->Require(id.local_frame_id(), sequence);
}

////////////////////////////////////////////////////////////////////////////////
// cc::mojom::MojoCompositorFrameSinkClient overrides:

void CompositorFrameSinkHolder::DidReceiveCompositorFrameAck() {
// TODO(staraz): Implement this
}

void CompositorFrameSinkHolder::OnBeginFrame(const cc::BeginFrameArgs& args) {
while (!active_frame_callbacks_.empty()) {
active_frame_callbacks_.front().Run(args.frame_time);
active_frame_callbacks_.pop_front();
}
begin_frame_source_->OnBeginFrame(args);
}

void CompositorFrameSinkHolder::ReclaimResources(
const cc::ReturnedResourceArray& resources) {
for (auto& resource : resources) {
auto it = release_callbacks_.find(resource.id);
DCHECK(it != release_callbacks_.end());
std::unique_ptr<cc::SingleReleaseCallback> callback =
std::move(it->second.second);
release_callbacks_.erase(it);
callback->Run(resource.sync_token, resource.lost);
}
}

void CompositorFrameSinkHolder::WillDrawSurface() {
if (surface_)
surface_->WillDraw();

UpdateNeedsBeginFrame();
}

////////////////////////////////////////////////////////////////////////////////
// cc::BeginFrameObserver overrides:

const cc::BeginFrameArgs& CompositorFrameSinkHolder::LastUsedBeginFrameArgs()
const {
return last_begin_frame_args_;
}

void CompositorFrameSinkHolder::OnBeginFrameSourcePausedChanged(bool paused) {}

////////////////////////////////////////////////////////////////////////////////
// cc::ExternalBeginFrameSouceClient overrides:

void CompositorFrameSinkHolder::OnNeedsBeginFrames(bool needs_begin_frames) {
frame_sink_->SetNeedsBeginFrame(needs_begin_frames);
}

////////////////////////////////////////////////////////////////////////////////
// SurfaceObserver overrides:

void CompositorFrameSinkHolder::OnSurfaceDestroying(Surface* surface) {
surface_->RemoveSurfaceObserver(this);
surface_ = nullptr;
}

////////////////////////////////////////////////////////////////////////////////
// ExoComopositorFrameSink, private:

CompositorFrameSinkHolder::~CompositorFrameSinkHolder() {}

void CompositorFrameSinkHolder::UpdateNeedsBeginFrame() {
if (!begin_frame_source_)
return;

bool needs_begin_frame = !active_frame_callbacks_.empty();
if (needs_begin_frame == needs_begin_frame_)
return;

needs_begin_frame_ = needs_begin_frame;
OnNeedsBeginFrames(needs_begin_frame_);
}

} // namespace exo
Loading

0 comments on commit d8f4f64

Please sign in to comment.