1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "cc/test/resource_provider_test_utils.h"
6 
7 #include "base/callback_helpers.h"
8 
9 namespace cc {
10 
11 const std::unordered_map<viz::ResourceId, viz::ResourceId>&
SendResourceAndGetChildToParentMap(const std::vector<viz::ResourceId> & resource_ids,viz::DisplayResourceProvider * resource_provider,viz::ClientResourceProvider * child_resource_provider,viz::ContextProvider * child_context_provider)12 SendResourceAndGetChildToParentMap(
13     const std::vector<viz::ResourceId>& resource_ids,
14     viz::DisplayResourceProvider* resource_provider,
15     viz::ClientResourceProvider* child_resource_provider,
16     viz::ContextProvider* child_context_provider) {
17   DCHECK(resource_provider);
18   DCHECK(child_resource_provider);
19   // Transfer resources to the parent.
20   std::vector<viz::TransferableResource> send_to_parent;
21   int child_id = resource_provider->CreateChild(base::DoNothing());
22   child_resource_provider->PrepareSendToParent(resource_ids, &send_to_parent,
23                                                child_context_provider);
24   resource_provider->ReceiveFromChild(child_id, send_to_parent);
25 
26   // Delete them in the child so they won't be leaked, and will be released once
27   // returned from the parent. This assumes they won't need to be sent to the
28   // parent again.
29   for (viz::ResourceId id : resource_ids)
30     child_resource_provider->RemoveImportedResource(id);
31 
32   // Return the child to parent map.
33   return resource_provider->GetChildToParentMap(child_id);
34 }
35 
36 }  // namespace cc
37