Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: cc/ipc/render_pass_struct_traits.cc

Issue 2174843003: cc mojo: Use ArrayDataViews in RenderPasses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: A little bit of cleanup Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/ipc/render_pass_struct_traits.h" 5 #include "cc/ipc/render_pass_struct_traits.h"
6 6
7 #include "base/numerics/safe_conversions.h" 7 #include "base/numerics/safe_conversions.h"
8 #include "cc/ipc/shared_quad_state_struct_traits.h" 8 #include "cc/ipc/shared_quad_state_struct_traits.h"
9 9
10 namespace mojo { 10 namespace mojo {
11 11
12 // static 12 // static
13 void* StructTraits<cc::mojom::RenderPass, std::unique_ptr<cc::RenderPass>>::
14 SetUpContext(const std::unique_ptr<cc::RenderPass>& input) {
15 std::unique_ptr<mojo::Array<uint32_t>> sqs_references(
16 new mojo::Array<uint32_t>(input->quad_list.size()));
17 cc::SharedQuadStateList::ConstIterator sqs_iter =
18 input->shared_quad_state_list.begin();
19 for (auto it = input->quad_list.begin(); it != input->quad_list.end(); ++it) {
20 if ((*it)->shared_quad_state != *sqs_iter)
21 ++sqs_iter;
22 (*sqs_references)[it.index()] =
23 base::checked_cast<uint32_t>(sqs_iter.index());
24 DCHECK_NE(nullptr, (*it)->shared_quad_state);
25 DCHECK_EQ(*sqs_iter, (*it)->shared_quad_state);
26 }
27 DCHECK(input->shared_quad_state_list.empty() ||
28 input->shared_quad_state_list.size() - 1 == sqs_iter.index());
29 return sqs_references.release();
30 }
31
32 // static
33 void StructTraits<cc::mojom::RenderPass, std::unique_ptr<cc::RenderPass>>::
34 TearDownContext(const std::unique_ptr<cc::RenderPass>& input,
35 void* context) {
36 // static_cast to ensure the destructor is called.
37 delete static_cast<mojo::Array<uint32_t>*>(context);
38 }
39
40 // static 13 // static
41 bool StructTraits<cc::mojom::RenderPass, std::unique_ptr<cc::RenderPass>>::Read( 14 bool StructTraits<cc::mojom::RenderPass, std::unique_ptr<cc::RenderPass>>::Read(
42 cc::mojom::RenderPassDataView data, 15 cc::mojom::RenderPassDataView data,
43 std::unique_ptr<cc::RenderPass>* out) { 16 std::unique_ptr<cc::RenderPass>* out) {
44 *out = cc::RenderPass::Create(); 17 *out = cc::RenderPass::Create();
45 if (!data.ReadId(&(*out)->id) || !data.ReadOutputRect(&(*out)->output_rect) || 18 if (!data.ReadId(&(*out)->id) || !data.ReadOutputRect(&(*out)->output_rect) ||
46 !data.ReadDamageRect(&(*out)->damage_rect) || 19 !data.ReadDamageRect(&(*out)->damage_rect) ||
47 !data.ReadTransformToRootTarget(&(*out)->transform_to_root_target)) { 20 !data.ReadTransformToRootTarget(&(*out)->transform_to_root_target)) {
48 return false; 21 return false;
49 } 22 }
50 (*out)->has_transparent_background = data.has_transparent_background(); 23 (*out)->has_transparent_background = data.has_transparent_background();
51 if (!data.ReadQuadList(&(*out)->quad_list) ||
52 !data.ReadSharedQuadStateList(&(*out)->shared_quad_state_list))
53 return false;
54 24
55 mojo::Array<uint32_t> shared_quad_state_references; 25 cc::mojom::QuadListDataView quad_list_view;
56 if (!data.ReadSharedQuadStateReferences(&shared_quad_state_references)) 26 data.GetQuadListDataView(&quad_list_view);
57 return false; 27 mojo::ArrayDataView<cc::mojom::DrawQuadDataView> quads;
28 quad_list_view.GetQuadsDataView(&quads);
29 cc::SharedQuadState* last_sqs = nullptr;
30 for (size_t i = 0; i < quads.size(); ++i) {
31 cc::mojom::DrawQuadDataView quad_data_view;
32 quads.GetDataView(i, &quad_data_view);
33 cc::DrawQuad* quad =
34 AllocateAndConstruct(quad_data_view.material(), &(*out)->quad_list);
35 if (!quad)
36 return false;
37 if (!quads.Read(i, quad))
38 return false;
58 39
59 if ((*out)->quad_list.size() != shared_quad_state_references.size()) 40 // Read the SharedQuadState.
60 return false; 41 cc::mojom::SharedQuadStateDataView sqs_data_view;
61 42 quad_data_view.GetSqsDataView(&sqs_data_view);
62 cc::SharedQuadStateList::ConstIterator sqs_iter = 43 // If there is no seralized SharedQuadState then used the last deseriaized
63 (*out)->shared_quad_state_list.begin(); 44 // one.
64 for (auto it = (*out)->quad_list.begin(); it != (*out)->quad_list.end(); 45 if (!sqs_data_view.is_null()) {
65 ++it) { 46 last_sqs = (*out)->CreateAndAppendSharedQuadState();
66 if (sqs_iter.index() != shared_quad_state_references[it.index()]) 47 if (!quad_data_view.ReadSqs(last_sqs))
67 ++sqs_iter; 48 return false;
68 if (shared_quad_state_references[it.index()] != sqs_iter.index()) 49 }
69 return false; 50 quad->shared_quad_state = last_sqs;
70 (*it)->shared_quad_state = *sqs_iter;
71 if (!(*it)->shared_quad_state)
72 return false;
73 } 51 }
74 return (*out)->shared_quad_state_list.empty() || 52 return true;
75 sqs_iter.index() == (*out)->shared_quad_state_list.size() - 1;
76 } 53 }
77 54
78 } // namespace mojo 55 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698