Commit 3f16bd2f authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Migrate references to viz::mojom::{CopyOutputResultSender,TextureReleaser}

Convert the remaining bits related to the viz::mojom::CopyOutputResultSender
and viz::mojom::TextureReleaser interfaces to the new mojo types.

Bug: 955171
Change-Id: Id1fd4e81e9c4708516ef03a9ec69d6b272a1fde9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872065
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarenne <enne@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709418}
parent 9785a8b9
......@@ -7,14 +7,16 @@
#include <utility>
#include "base/bind.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/viz/public/cpp/compositing/copy_output_result_mojom_traits.h"
namespace {
// When we're sending a CopyOutputRequest, we keep the result_callback_ in a
// CopyOutputResultSenderImpl and send a CopyOutputResultSenderPtr to the other
// process. When SendResult is called, we run the stored result_callback_.
// CopyOutputResultSenderImpl and send a PendingRemote<CopyOutputResultSender>
// to the other process. When SendResult is called, we run the stored
// result_callback_.
class CopyOutputResultSenderImpl : public viz::mojom::CopyOutputResultSender {
public:
CopyOutputResultSenderImpl(
......@@ -45,9 +47,12 @@ class CopyOutputResultSenderImpl : public viz::mojom::CopyOutputResultSender {
viz::CopyOutputRequest::CopyOutputRequestCallback result_callback_;
};
void SendResult(viz::mojom::CopyOutputResultSenderPtr ptr,
void SendResult(
mojo::PendingRemote<viz::mojom::CopyOutputResultSender> pending_remote,
std::unique_ptr<viz::CopyOutputResult> result) {
ptr->SendResult(std::move(result));
mojo::Remote<viz::mojom::CopyOutputResultSender> remote(
std::move(pending_remote));
remote->SendResult(std::move(result));
}
} // namespace
......@@ -55,14 +60,15 @@ void SendResult(viz::mojom::CopyOutputResultSenderPtr ptr,
namespace mojo {
// static
viz::mojom::CopyOutputResultSenderPtr
mojo::PendingRemote<viz::mojom::CopyOutputResultSender>
StructTraits<viz::mojom::CopyOutputRequestDataView,
std::unique_ptr<viz::CopyOutputRequest>>::
result_sender(const std::unique_ptr<viz::CopyOutputRequest>& request) {
viz::mojom::CopyOutputResultSenderPtr result_sender;
mojo::PendingRemote<viz::mojom::CopyOutputResultSender> result_sender;
auto impl = std::make_unique<CopyOutputResultSenderImpl>(
request->result_format(), std::move(request->result_callback_));
MakeStrongBinding(std::move(impl), MakeRequest(&result_sender));
MakeSelfOwnedReceiver(std::move(impl),
result_sender.InitWithNewPipeAndPassReceiver());
return result_sender;
}
......@@ -75,8 +81,9 @@ bool StructTraits<viz::mojom::CopyOutputRequestDataView,
if (!data.ReadResultFormat(&result_format))
return false;
auto result_sender =
data.TakeResultSender<viz::mojom::CopyOutputResultSenderPtr>();
auto result_sender = data.TakeResultSender<
mojo::PendingRemote<viz::mojom::CopyOutputResultSender>>();
auto request = std::make_unique<viz::CopyOutputRequest>(
result_format, base::BindOnce(SendResult, base::Passed(&result_sender)));
......
......@@ -7,6 +7,7 @@
#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "mojo/public/cpp/base/unguessable_token_mojom_traits.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/viz/public/cpp/compositing/copy_output_result_mojom_traits.h"
#include "services/viz/public/mojom/compositing/copy_output_request.mojom.h"
#include "ui/gfx/geometry/mojom/geometry_mojom_traits.h"
......@@ -46,7 +47,7 @@ struct StructTraits<viz::mojom::CopyOutputRequestDataView,
return request->result_selection_;
}
static viz::mojom::CopyOutputResultSenderPtr result_sender(
static mojo::PendingRemote<viz::mojom::CopyOutputResultSender> result_sender(
const std::unique_ptr<viz::CopyOutputRequest>& request);
static bool Read(viz::mojom::CopyOutputRequestDataView data,
......
......@@ -5,15 +5,16 @@
#include "services/viz/public/cpp/compositing/copy_output_result_mojom_traits.h"
#include "base/bind.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace {
// This class retains the SingleReleaseCallback of the CopyOutputResult that is
// being sent over mojo. A TextureReleaserPtr that talks to this impl
// object will be sent over mojo instead of the release_callback_ (which is not
// serializable). Once the client calls Release, the release_callback_ will be
// called. An object of this class will remain alive until the MessagePipe
// being sent over mojo. A PendingRemote<TextureReleaser> that talks to this
// impl object will be sent over mojo instead of the release_callback_ (which is
// not serializable). Once the client calls Release, the release_callback_ will
// be called. An object of this class will remain alive until the MessagePipe
// attached to it goes away (i.e. StrongBinding is used).
class TextureReleaserImpl : public viz::mojom::TextureReleaser {
public:
......@@ -30,10 +31,11 @@ class TextureReleaserImpl : public viz::mojom::TextureReleaser {
std::unique_ptr<viz::SingleReleaseCallback> release_callback_;
};
void Release(viz::mojom::TextureReleaserPtr ptr,
void Release(mojo::PendingRemote<viz::mojom::TextureReleaser> pending_remote,
const gpu::SyncToken& sync_token,
bool is_lost) {
ptr->Release(sync_token, is_lost);
mojo::Remote<viz::mojom::TextureReleaser> remote(std::move(pending_remote));
remote->Release(sync_token, is_lost);
}
} // namespace
......@@ -133,17 +135,17 @@ StructTraits<viz::mojom::CopyOutputResultDataView,
}
// static
viz::mojom::TextureReleaserPtr
mojo::PendingRemote<viz::mojom::TextureReleaser>
StructTraits<viz::mojom::CopyOutputResultDataView,
std::unique_ptr<viz::CopyOutputResult>>::
releaser(const std::unique_ptr<viz::CopyOutputResult>& result) {
if (result->format() != viz::CopyOutputResult::Format::RGBA_TEXTURE)
return nullptr;
return mojo::NullRemote();
viz::mojom::TextureReleaserPtr releaser;
MakeStrongBinding(
mojo::PendingRemote<viz::mojom::TextureReleaser> releaser;
MakeSelfOwnedReceiver(
std::make_unique<TextureReleaserImpl>(result->TakeTextureOwnership()),
MakeRequest(&releaser));
releaser.InitWithNewPipeAndPassReceiver());
return releaser;
}
......@@ -195,14 +197,14 @@ bool StructTraits<viz::mojom::CopyOutputResultDataView,
return true;
}
viz::mojom::TextureReleaserPtr releaser =
data.TakeReleaser<viz::mojom::TextureReleaserPtr>();
auto releaser =
data.TakeReleaser<mojo::PendingRemote<viz::mojom::TextureReleaser>>();
if (!releaser)
return false; // Illegal to provide texture without Releaser.
// Returns a result with a SingleReleaseCallback that will return
// here and proxy the callback over mojo to the CopyOutputResult's
// origin via the TextureReleaserPtr.
// origin via a mojo::Remote<viz::mojom::TextureReleaser> remote.
*out_p = std::make_unique<viz::CopyOutputTextureResult>(
rect, *mailbox, *sync_token, *color_space,
viz::SingleReleaseCallback::Create(
......
......@@ -8,6 +8,7 @@
#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "gpu/ipc/common/mailbox_mojom_traits.h"
#include "gpu/ipc/common/sync_token_mojom_traits.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/viz/public/mojom/compositing/copy_output_result.mojom-shared.h"
#include "services/viz/public/mojom/compositing/texture_releaser.mojom.h"
#include "skia/public/mojom/bitmap_skbitmap_mojom_traits.h"
......@@ -48,7 +49,7 @@ struct StructTraits<viz::mojom::CopyOutputResultDataView,
static base::Optional<gfx::ColorSpace> color_space(
const std::unique_ptr<viz::CopyOutputResult>& result);
static viz::mojom::TextureReleaserPtr releaser(
static mojo::PendingRemote<viz::mojom::TextureReleaser> releaser(
const std::unique_ptr<viz::CopyOutputResult>& result);
static bool Read(viz::mojom::CopyOutputResultDataView data,
......
......@@ -25,7 +25,7 @@
#include "gpu/ipc/common/sync_token_mojom_traits.h"
#include "ipc/ipc_message_utils.h"
#include "mojo/public/cpp/base/time_mojom_traits.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "services/viz/public/cpp/compositing/begin_frame_args_mojom_traits.h"
#include "services/viz/public/cpp/compositing/compositor_frame_metadata_mojom_traits.h"
......@@ -366,14 +366,17 @@ TEST_F(StructTraitsTest, CopyOutputRequest_CallbackRunsOnce) {
++*n_called;
},
base::Unretained(&n_called)));
auto result_sender = mojo::StructTraits<
auto result_sender_pending_remote = mojo::StructTraits<
mojom::CopyOutputRequestDataView,
std::unique_ptr<CopyOutputRequest>>::result_sender(request);
mojo::Remote<mojom::CopyOutputResultSender> result_sender_remote(
std::move(result_sender_pending_remote));
for (int i = 0; i < 10; i++)
result_sender->SendResult(std::make_unique<CopyOutputResult>(
result_sender_remote->SendResult(std::make_unique<CopyOutputResult>(
request->result_format(), gfx::Rect()));
EXPECT_EQ(0, n_called);
result_sender.FlushForTesting();
result_sender_remote.FlushForTesting();
EXPECT_EQ(1, n_called);
}
......
......@@ -22,7 +22,7 @@ struct CopyOutputRequest {
gfx.mojom.Rect? area;
gfx.mojom.Rect? result_selection;
CopyOutputResultSender result_sender;
pending_remote<CopyOutputResultSender> result_sender;
};
// When the display compositor is ready to respond to the CopyOutputRequest,
......
......@@ -33,5 +33,5 @@ struct CopyOutputResult {
gpu.mojom.SyncToken? sync_token;
gfx.mojom.ColorSpace? color_space;
// Present when the format is RGBA_TEXTURE and |mailbox| is non-empty.
TextureReleaser? releaser;
pending_remote<TextureReleaser>? releaser;
};
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