Commit 61a9f19a authored by danakj's avatar danakj Committed by Commit Bot

layout tests: Use SharedBitmapIdRegistrar for TestPlugin.

This uses the new TextureLayer APIs to register SharedBitmapIds instead
of using ClientSharedBitmapManager, in order to get the registration in
the same IPC channel that the compositor uses for submitting frames
that include the TestPlugin's shared memory bitmaps.

The formula used for this change is:
- Change std::unique_ptr<viz::SharedBitmap> to scoped_refptr<cc::CrossThreadSharedBitmap>
- Allocate shm with viz::bitmap_allocation instead of with viz::SharedBitmapManager
- Generate a SharedBitmapId when allocating and register it with SharedBitmapIdRegistrar
- Store ownership of cc::SharedBitmapIdRegistration alongside each cc::CrossThreadSharedBitmap
- Remove forward decls/includes for SharedBitmap and SharedBitmapManager (still need for SharedBitmapId)

However, for TestPlugin a SharedMemory, and thus, a SharedBitmapId, is
only given to the compositor a single time ever, and deleted in the
ReleaseCallback. As well the SharedMemory is allocated earlier than
when it is given to the compositor. So the SharedBitmapId registration
is delated from the allocation step to where the SharedMemory is handed
to the compositor. But since we only use a SharedMemory once, we can
always do the registration there without any conditions.

R=piman@chromium.org

Bug: 730660
Change-Id: Idaf69b854062482f55d359f7542f576be7df1dd4
Reviewed-on: https://chromium-review.googlesource.com/987096
Commit-Queue: Antoine Labour <piman@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547501}
parent c58d701e
......@@ -16,7 +16,8 @@
#include "base/strings/stringprintf.h"
#include "cc/blink/web_layer_impl.h"
#include "cc/layers/texture_layer.h"
#include "components/viz/common/resources/shared_bitmap_manager.h"
#include "cc/resources/cross_thread_shared_bitmap.h"
#include "components/viz/common/resources/bitmap_allocation.h"
#include "content/shell/test_runner/web_test_delegate.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "third_party/WebKit/public/platform/Platform.h"
......@@ -267,9 +268,17 @@ void TestPlugin::UpdateGeometry(
} else {
mailbox_ = gpu::Mailbox();
sync_token_ = gpu::SyncToken();
shared_bitmap_ = delegate_->GetSharedBitmapManager()->AllocateSharedBitmap(
gfx::Rect(rect_).size(), viz::RGBA_8888);
DrawSceneSoftware(shared_bitmap_->pixels());
viz::SharedBitmapId id = viz::SharedBitmap::GenerateId();
std::unique_ptr<base::SharedMemory> shm =
viz::bitmap_allocation::AllocateMappedBitmap(gfx::Rect(rect_).size(),
viz::RGBA_8888);
shared_bitmap_ = base::MakeRefCounted<cc::CrossThreadSharedBitmap>(
id, std::move(shm), gfx::Rect(rect_).size(), viz::RGBA_8888);
// The |shared_bitmap_|'s id will be registered when being given to the
// compositor.
DrawSceneSoftware(shared_bitmap_->shared_memory()->memory());
}
content_changed_ = true;
......@@ -283,9 +292,12 @@ bool TestPlugin::IsPlaceholder() {
static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) {
}
static void ReleaseSharedMemory(std::unique_ptr<viz::SharedBitmap> bitmap,
const gpu::SyncToken& sync_token,
bool lost) {}
// static
void TestPlugin::ReleaseSharedMemory(
scoped_refptr<cc::CrossThreadSharedBitmap> shared_bitmap,
cc::SharedBitmapIdRegistration registration,
const gpu::SyncToken& sync_token,
bool lost) {}
bool TestPlugin::PrepareTransferableResource(
cc::SharedBitmapIdRegistrar* bitmap_registrar,
......@@ -299,11 +311,18 @@ bool TestPlugin::PrepareTransferableResource(
*release_callback = viz::SingleReleaseCallback::Create(
base::BindOnce(&IgnoreReleaseCallback));
} else if (shared_bitmap_) {
// The |bitmap_data_| is only used for a single compositor frame, so we know
// the SharedBitmapId in it was not registered yet.
cc::SharedBitmapIdRegistration registration =
bitmap_registrar->RegisterSharedBitmapId(shared_bitmap_->id(),
shared_bitmap_);
*resource = viz::TransferableResource::MakeSoftware(
shared_bitmap_->id(), shared_bitmap_->sequence_number(),
gfx::Size(rect_.width, rect_.height), viz::RGBA_8888);
shared_bitmap_->id(), /*sequence_number=*/0, shared_bitmap_->size(),
viz::RGBA_8888);
*release_callback = viz::SingleReleaseCallback::Create(
base::BindOnce(&ReleaseSharedMemory, base::Passed(&shared_bitmap_)));
base::BindOnce(&ReleaseSharedMemory, base::Passed(&shared_bitmap_),
base::Passed(&registration)));
}
content_changed_ = false;
return true;
......
......@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "cc/layers/texture_layer.h"
#include "cc/layers/texture_layer_client.h"
#include "cc/resources/shared_bitmap_id_registrar.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "third_party/WebKit/public/platform/WebLayer.h"
......@@ -28,7 +29,7 @@ struct WebPluginParams;
}
namespace cc {
class SharedBitmap;
class CrossThreadSharedBitmap;
}
namespace gpu {
......@@ -154,6 +155,11 @@ class TestPlugin : public blink::WebPlugin, public cc::TextureLayerClient {
// Functions for drawing scene in Software.
void DrawSceneSoftware(void* memory);
static void ReleaseSharedMemory(
scoped_refptr<cc::CrossThreadSharedBitmap> shared_bitmap,
cc::SharedBitmapIdRegistration registration,
const gpu::SyncToken& sync_token,
bool lost);
WebTestDelegate* delegate_;
blink::WebPluginContainer* container_;
......@@ -165,7 +171,7 @@ class TestPlugin : public blink::WebPlugin, public cc::TextureLayerClient {
GLuint color_texture_;
gpu::Mailbox mailbox_;
gpu::SyncToken sync_token_;
std::unique_ptr<viz::SharedBitmap> shared_bitmap_;
scoped_refptr<cc::CrossThreadSharedBitmap> shared_bitmap_;
bool content_changed_;
GLuint framebuffer_;
Scene scene_;
......
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