| 466 | |
| 467 | template <typename ObjectSizeT> |
| 468 | Status ApplyTexturesAssignment( |
| 469 | const ObjectsAssignment<ObjectSizeT>& assignment, |
| 470 | const std::vector<size_t>& global_ref_to_usage_rec, |
| 471 | const std::vector<Object*>& global_ref_to_object_ptr, |
| 472 | std::vector<ObjectRef>* global_ref_to_shared_ref, |
| 473 | std::vector<Object>* shared_objects) { |
| 474 | std::vector<ObjectRef> assigned_id_to_shared_ref( |
| 475 | assignment.object_sizes.size(), kInvalidObjectRef); |
| 476 | for (size_t global_ref = 0; global_ref < global_ref_to_usage_rec.size(); |
| 477 | ++global_ref) { |
| 478 | const auto& usage_rec_id = global_ref_to_usage_rec[global_ref]; |
| 479 | Object* object = global_ref_to_object_ptr[global_ref]; |
| 480 | if (usage_rec_id == kNotAssigned || object == nullptr || |
| 481 | object->object_type != ObjectType::TEXTURE || |
| 482 | !absl::get_if<ObjectSizeT>(&object->size)) { |
| 483 | // Skip objects with other data type, non-textures and textures with wrong |
| 484 | // number of dimensions. |
| 485 | continue; |
| 486 | } |
| 487 | |
| 488 | // id of shared object, returned by memory allocation algorithm. |
| 489 | size_t assigned_id = assignment.object_ids[usage_rec_id]; |
| 490 | |
| 491 | // id of corresponding shared object in vector share_objects. |
| 492 | ObjectRef shared_ref = assigned_id_to_shared_ref[assigned_id]; |
| 493 | |
| 494 | if (shared_ref == kInvalidObjectRef) { |
| 495 | // We need to create new shared object for current texture. |
| 496 | shared_ref = shared_objects->size(); |
| 497 | Object shared_object = *object; |
| 498 | shared_object.access = AccessType::READ_WRITE; |
| 499 | shared_object.object = shared_ref; |
| 500 | shared_object.size = assignment.object_sizes[assigned_id]; |
| 501 | shared_objects->push_back(std::move(shared_object)); |
| 502 | assigned_id_to_shared_ref[assigned_id] = shared_ref; |
| 503 | } |
| 504 | (*global_ref_to_shared_ref)[global_ref] = shared_ref; |
| 505 | } |
| 506 | return OkStatus(); |
| 507 | } |
| 508 | |
| 509 | } // namespace |
| 510 |
no test coverage detected