OLD | NEW |
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/quads_struct_traits.h" | 5 #include "cc/ipc/quads_struct_traits.h" |
6 #include "ui/gfx/mojo/transform_struct_traits.h" | 6 #include "ui/gfx/mojo/transform_struct_traits.h" |
7 | 7 |
8 namespace mojo { | 8 namespace mojo { |
9 | 9 |
| 10 cc::DrawQuad* AllocateAndConstruct(cc::mojom::Material material, |
| 11 cc::QuadList* list) { |
| 12 cc::DrawQuad* quad = nullptr; |
| 13 switch (material) { |
| 14 case cc::mojom::Material::INVALID: |
| 15 return nullptr; |
| 16 case cc::mojom::Material::DEBUG_BORDER: |
| 17 quad = list->AllocateAndConstruct<cc::DebugBorderDrawQuad>(); |
| 18 quad->material = cc::DrawQuad::DEBUG_BORDER; |
| 19 return quad; |
| 20 case cc::mojom::Material::PICTURE_CONTENT: |
| 21 quad = list->AllocateAndConstruct<cc::PictureDrawQuad>(); |
| 22 quad->material = cc::DrawQuad::PICTURE_CONTENT; |
| 23 return quad; |
| 24 case cc::mojom::Material::RENDER_PASS: |
| 25 quad = list->AllocateAndConstruct<cc::RenderPassDrawQuad>(); |
| 26 quad->material = cc::DrawQuad::RENDER_PASS; |
| 27 return quad; |
| 28 case cc::mojom::Material::SOLID_COLOR: |
| 29 quad = list->AllocateAndConstruct<cc::SolidColorDrawQuad>(); |
| 30 quad->material = cc::DrawQuad::SOLID_COLOR; |
| 31 return quad; |
| 32 case cc::mojom::Material::STREAM_VIDEO_CONTENT: |
| 33 quad = list->AllocateAndConstruct<cc::StreamVideoDrawQuad>(); |
| 34 quad->material = cc::DrawQuad::STREAM_VIDEO_CONTENT; |
| 35 return quad; |
| 36 case cc::mojom::Material::SURFACE_CONTENT: |
| 37 quad = list->AllocateAndConstruct<cc::SurfaceDrawQuad>(); |
| 38 quad->material = cc::DrawQuad::SURFACE_CONTENT; |
| 39 return quad; |
| 40 case cc::mojom::Material::TEXTURE_CONTENT: |
| 41 quad = list->AllocateAndConstruct<cc::TextureDrawQuad>(); |
| 42 quad->material = cc::DrawQuad::TEXTURE_CONTENT; |
| 43 return quad; |
| 44 case cc::mojom::Material::TILED_CONTENT: |
| 45 quad = list->AllocateAndConstruct<cc::TileDrawQuad>(); |
| 46 quad->material = cc::DrawQuad::TILED_CONTENT; |
| 47 return quad; |
| 48 case cc::mojom::Material::YUV_VIDEO_CONTENT: |
| 49 quad = list->AllocateAndConstruct<cc::YUVVideoDrawQuad>(); |
| 50 quad->material = cc::DrawQuad::YUV_VIDEO_CONTENT; |
| 51 return quad; |
| 52 } |
| 53 NOTREACHED(); |
| 54 return nullptr; |
| 55 } |
10 namespace { | 56 namespace { |
11 | 57 |
12 bool ReadDrawQuad(cc::mojom::DrawQuadDataView data, cc::DrawQuad* quad) { | 58 bool ReadDrawQuad(cc::mojom::DrawQuadDataView data, cc::DrawQuad* quad) { |
13 cc::DrawQuad::Material material; | 59 cc::DrawQuad::Material material; |
14 if (!data.ReadMaterial(&material) || material != quad->material) { | 60 if (!data.ReadMaterial(&material) || material != quad->material) { |
15 return false; | 61 return false; |
16 } | 62 } |
17 if (!data.ReadRect(&quad->rect) || !data.ReadOpaqueRect(&quad->opaque_rect) || | 63 if (!data.ReadRect(&quad->rect) || !data.ReadOpaqueRect(&quad->opaque_rect) || |
18 !data.ReadVisibleRect(&quad->visible_rect)) { | 64 !data.ReadVisibleRect(&quad->visible_rect)) { |
19 return false; | 65 return false; |
20 } | 66 } |
21 quad->needs_blending = data.needs_blending(); | 67 quad->needs_blending = data.needs_blending(); |
22 return true; | 68 return true; |
23 } | 69 } |
24 | 70 |
25 bool AllocateAndConstruct(cc::DrawQuad::Material material, cc::QuadList* list) { | |
26 cc::DrawQuad* quad = nullptr; | |
27 switch (material) { | |
28 case cc::DrawQuad::INVALID: | |
29 break; | |
30 case cc::DrawQuad::DEBUG_BORDER: | |
31 quad = list->AllocateAndConstruct<cc::DebugBorderDrawQuad>(); | |
32 break; | |
33 case cc::DrawQuad::PICTURE_CONTENT: | |
34 quad = list->AllocateAndConstruct<cc::PictureDrawQuad>(); | |
35 break; | |
36 case cc::DrawQuad::RENDER_PASS: | |
37 quad = list->AllocateAndConstruct<cc::RenderPassDrawQuad>(); | |
38 break; | |
39 case cc::DrawQuad::SOLID_COLOR: | |
40 quad = list->AllocateAndConstruct<cc::SolidColorDrawQuad>(); | |
41 break; | |
42 case cc::DrawQuad::STREAM_VIDEO_CONTENT: | |
43 quad = list->AllocateAndConstruct<cc::StreamVideoDrawQuad>(); | |
44 break; | |
45 case cc::DrawQuad::SURFACE_CONTENT: | |
46 quad = list->AllocateAndConstruct<cc::SurfaceDrawQuad>(); | |
47 break; | |
48 case cc::DrawQuad::TEXTURE_CONTENT: | |
49 quad = list->AllocateAndConstruct<cc::TextureDrawQuad>(); | |
50 break; | |
51 case cc::DrawQuad::TILED_CONTENT: | |
52 quad = list->AllocateAndConstruct<cc::TileDrawQuad>(); | |
53 break; | |
54 case cc::DrawQuad::YUV_VIDEO_CONTENT: | |
55 quad = list->AllocateAndConstruct<cc::YUVVideoDrawQuad>(); | |
56 break; | |
57 } | |
58 if (quad) | |
59 quad->material = material; | |
60 return quad != nullptr; | |
61 } | |
62 | |
63 } // namespace | 71 } // namespace |
64 | 72 |
65 // static | 73 // static |
66 cc::mojom::Material | 74 cc::mojom::Material |
67 EnumTraits<cc::mojom::Material, cc::DrawQuad::Material>::ToMojom( | 75 EnumTraits<cc::mojom::Material, cc::DrawQuad::Material>::ToMojom( |
68 cc::DrawQuad::Material material) { | 76 cc::DrawQuad::Material material) { |
69 switch (material) { | 77 switch (material) { |
70 case cc::DrawQuad::INVALID: | 78 case cc::DrawQuad::INVALID: |
71 return cc::mojom::Material::INVALID; | 79 return cc::mojom::Material::INVALID; |
72 case cc::DrawQuad::DEBUG_BORDER: | 80 case cc::DrawQuad::DEBUG_BORDER: |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 return data.ReadTextureQuadState(out); | 328 return data.ReadTextureQuadState(out); |
321 case cc::mojom::Material::TILED_CONTENT: | 329 case cc::mojom::Material::TILED_CONTENT: |
322 return data.ReadTileQuadState(out); | 330 return data.ReadTileQuadState(out); |
323 case cc::mojom::Material::YUV_VIDEO_CONTENT: | 331 case cc::mojom::Material::YUV_VIDEO_CONTENT: |
324 return data.ReadYuvVideoQuadState(out); | 332 return data.ReadYuvVideoQuadState(out); |
325 } | 333 } |
326 NOTREACHED(); | 334 NOTREACHED(); |
327 return false; | 335 return false; |
328 } | 336 } |
329 | 337 |
330 // static | |
331 void* StructTraits<cc::mojom::QuadList, cc::QuadList>::SetUpContext( | |
332 const cc::QuadList& quad_list) { | |
333 mojo::Array<cc::DrawQuad::Material>* materials = | |
334 new mojo::Array<cc::DrawQuad::Material>(quad_list.size()); | |
335 for (auto it = quad_list.begin(); it != quad_list.end(); ++it) | |
336 (*materials)[it.index()] = it->material; | |
337 return materials; | |
338 } | |
339 | |
340 // static | |
341 void StructTraits<cc::mojom::QuadList, cc::QuadList>::TearDownContext( | |
342 const cc::QuadList& quad_list, | |
343 void* context) { | |
344 // static_cast to ensure the destructor is called. | |
345 delete static_cast<mojo::Array<cc::DrawQuad::Material>*>(context); | |
346 } | |
347 | |
348 // static | |
349 const mojo::Array<cc::DrawQuad::Material>& | |
350 StructTraits<cc::mojom::QuadList, cc::QuadList>::quad_types( | |
351 const cc::QuadList& quad_list, | |
352 void* context) { | |
353 return *static_cast<mojo::Array<cc::DrawQuad::Material>*>(context); | |
354 } | |
355 | |
356 // static | |
357 bool StructTraits<cc::mojom::QuadList, cc::QuadList>::Read( | |
358 cc::mojom::QuadListDataView data, | |
359 cc::QuadList* out) { | |
360 // TODO(fsamuel): Once we have ArrayTraits DataViews we can delete | |
361 // this field. This field exists so we can pre-allocate DrawQuads | |
362 // in the QuadList according to their material. | |
363 mojo::Array<cc::DrawQuad::Material> materials; | |
364 if (!data.ReadQuadTypes(&materials)) | |
365 return false; | |
366 for (size_t i = 0; i < materials.size(); ++i) { | |
367 if (!AllocateAndConstruct(materials[i], out)) | |
368 return false; | |
369 } | |
370 // The materials array and the quads array are expected to be the same size. | |
371 // If they are not, then deserialization will fail. | |
372 QuadListArray quad_list_array = {materials.size(), out}; | |
373 return data.ReadQuads(&quad_list_array); | |
374 } | |
375 | |
376 } // namespace mojo | 338 } // namespace mojo |
OLD | NEW |