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