Add SII method to upload data at creation and use for LTHI

Adds a method to SharedImage interface (SII) which allows us to create
a shared image and upload initial data in a single command. This method
is then used in LTHI to convert the UI Resource uploader code to SII.

As SII can't rely on the command buffer, it uses the following pattern
for uploads:
 - Allocate a 1MB (or required size) block of shared memory.
 - Sub allocate from it for each upload, duplicating the SHM and
   transferring ownership to the GPU service for each upload.
 - When the current shared memory buffer is used up, drop it on the
   client side. It will be kept alive by the duplicated handles passed
   to the service, until these are no longer needed.
 - Repeat.

This may be a bit inefficient, so we may need a more complex allocation
scheme in the future.

Bug: 906794
Change-Id: Ie91ab352b06097da6e00f80582b0cc92d690a6f9
Reviewed-on: https://chromium-review.googlesource.com/c/1343346
Commit-Queue: Eric Karl <[email protected]>
Reviewed-by: Chris Palmer <[email protected]>
Reviewed-by: Antoine Labour <[email protected]>
Cr-Commit-Position: refs/heads/master@{#615451}
diff --git a/cc/trees/layer_tree_host_unittest_context.cc b/cc/trees/layer_tree_host_unittest_context.cc
index a871ac9..bc8bbcf 100644
--- a/cc/trees/layer_tree_host_unittest_context.cc
+++ b/cc/trees/layer_tree_host_unittest_context.cc
@@ -107,6 +107,8 @@
                                GL_INNOCENT_CONTEXT_RESET_ARB);
     }
 
+    sii_ = provider->SharedImageInterface();
+
     return LayerTreeTest::CreateLayerTreeFrameSink(
         renderer_settings, refresh_rate, std::move(provider),
         std::move(worker_context_provider));
@@ -162,6 +164,7 @@
   // CreateDisplayLayerTreeFrameSink can both use it on different threads.
   base::Lock gl_lock_;
   viz::TestGLES2Interface* gl_ = nullptr;
+  viz::TestSharedImageInterface* sii_ = nullptr;
 
   int times_to_fail_create_;
   int times_to_lose_during_commit_;
@@ -1494,7 +1497,7 @@
   void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, bool visible) override {
     if (!visible) {
       // All resources should have been evicted.
-      ASSERT_EQ(0u, gl_->NumTextures());
+      ASSERT_EQ(0u, sii_->shared_image_count());
       EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
       EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource2_->id()));
       EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource3_->id()));
@@ -1514,7 +1517,7 @@
       case 1:
         // The first two resources should have been created on LTHI after the
         // commit.
-        ASSERT_EQ(2u, gl_->NumTextures());
+        ASSERT_EQ(2u, sii_->shared_image_count());
         EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
         EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource2_->id()));
         EXPECT_EQ(1, ui_resource_->resource_create_count);
@@ -1522,7 +1525,7 @@
         EXPECT_TRUE(impl->CanDraw());
         // Evict all UI resources. This will trigger a commit.
         impl->EvictAllUIResources();
-        ASSERT_EQ(0u, gl_->NumTextures());
+        ASSERT_EQ(0u, sii_->shared_image_count());
         EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
         EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource2_->id()));
         EXPECT_EQ(1, ui_resource_->resource_create_count);
@@ -1531,7 +1534,7 @@
         break;
       case 2:
         // The first two resources should have been recreated.
-        ASSERT_EQ(2u, gl_->NumTextures());
+        ASSERT_EQ(2u, sii_->shared_image_count());
         EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
         EXPECT_EQ(2, ui_resource_->resource_create_count);
         EXPECT_EQ(1, ui_resource_->lost_resource_count);
@@ -1543,7 +1546,7 @@
       case 3:
         // The first resource should have been recreated after visibility was
         // restored.
-        ASSERT_EQ(2u, gl_->NumTextures());
+        ASSERT_EQ(2u, sii_->shared_image_count());
         EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
         EXPECT_EQ(3, ui_resource_->resource_create_count);
         EXPECT_EQ(2, ui_resource_->lost_resource_count);
@@ -1585,7 +1588,7 @@
       case 0:
         // The UIResource has been created and a gpu resource made for it.
         EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
-        EXPECT_EQ(1u, gl_->NumTextures());
+        EXPECT_EQ(1u, sii_->shared_image_count());
         // Lose the LayerTreeFrameSink connection. The UI resource should
         // be replaced and the old texture should be destroyed.
         impl->DidLoseLayerTreeFrameSink();
@@ -1594,7 +1597,7 @@
         // The UIResource has been recreated, the old texture is not kept
         // around.
         EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
-        EXPECT_EQ(1u, gl_->NumTextures());
+        EXPECT_EQ(1u, sii_->shared_image_count());
         MainThreadTaskRunner()->PostTask(
             FROM_HERE,
             base::BindOnce(