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

Side by Side Diff: ui/display/display_layout.cc

Issue 2814843007: Fix expected PlacementList sort order. (Closed)
Patch Set: Don't register invalid layouts Created 3 years, 8 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 "ui/display/display_layout.h" 5 #include "ui/display/display_layout.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <sstream> 10 #include <sstream>
(...skipping 21 matching lines...) Expand all
32 const int kMaxValidOffset = 10000; 32 const int kMaxValidOffset = 10000;
33 33
34 bool IsIdInList(int64_t id, const DisplayIdList& list) { 34 bool IsIdInList(int64_t id, const DisplayIdList& list) {
35 const auto iter = 35 const auto iter =
36 std::find_if(list.begin(), list.end(), 36 std::find_if(list.begin(), list.end(),
37 [id](int64_t display_id) { return display_id == id; }); 37 [id](int64_t display_id) { return display_id == id; });
38 return iter != list.end(); 38 return iter != list.end();
39 } 39 }
40 40
41 bool ComparePlacements(const DisplayPlacement& d1, const DisplayPlacement& d2) { 41 bool ComparePlacements(const DisplayPlacement& d1, const DisplayPlacement& d2) {
42 return d1.display_id < d2.display_id; 42 return CompareDisplayIds(d1.display_id, d2.display_id);
43 } 43 }
44 44
45 // Extracts the displays IDs list from the displays list. 45 // Extracts the displays IDs list from the displays list.
46 DisplayIdList DisplayListToDisplayIdList(const Displays& displays) { 46 DisplayIdList DisplayListToDisplayIdList(const Displays& displays) {
47 DisplayIdList list; 47 DisplayIdList list;
48 for (const auto& display : displays) 48 for (const auto& display : displays)
49 list.emplace_back(display.id()); 49 list.emplace_back(display.id());
50 50
51 return list; 51 return list;
52 } 52 }
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 << " is not in the id list."; 528 << " is not in the id list.";
529 return false; 529 return false;
530 } 530 }
531 531
532 // Unified mode, or mirror mode switched from unified mode, 532 // Unified mode, or mirror mode switched from unified mode,
533 // may not have the placement yet. 533 // may not have the placement yet.
534 if (layout.placement_list.size() == 0u) 534 if (layout.placement_list.size() == 0u)
535 return true; 535 return true;
536 536
537 bool has_primary_as_parent = false; 537 bool has_primary_as_parent = false;
538 int64_t prev_id = std::numeric_limits<int64_t>::min(); 538 // The placement list must be sorted by the first 8 bits of the display IDs.
539 int64_t prev_id = std::numeric_limits<int8_t>::min();
539 for (const auto& placement : layout.placement_list) { 540 for (const auto& placement : layout.placement_list) {
540 // Placements are sorted by display_id. 541 // Placements are sorted by display_id.
541 if (prev_id >= placement.display_id) { 542 if (prev_id >= (placement.display_id & 0xFF)) {
542 LOG(ERROR) << "PlacementList must be sorted by display_id"; 543 LOG(ERROR) << "PlacementList must be sorted by first 8 bits of"
544 << " display_id ";
543 return false; 545 return false;
544 } 546 }
545 prev_id = placement.display_id; 547 prev_id = (placement.display_id & 0xFF);
546 if (placement.display_id == kInvalidDisplayId) { 548 if (placement.display_id == kInvalidDisplayId) {
547 LOG(ERROR) << "display_id is not initialized"; 549 LOG(ERROR) << "display_id is not initialized";
548 return false; 550 return false;
549 } 551 }
550 if (placement.parent_display_id == kInvalidDisplayId) { 552 if (placement.parent_display_id == kInvalidDisplayId) {
551 LOG(ERROR) << "display_parent_id is not initialized"; 553 LOG(ERROR) << "display_parent_id is not initialized";
552 return false; 554 return false;
553 } 555 }
554 if (placement.display_id == placement.parent_display_id) { 556 if (placement.display_id == placement.parent_display_id) {
555 LOG(ERROR) << "display_id must not be same as parent_display_id"; 557 LOG(ERROR) << "display_id must not be same as parent_display_id";
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 688
687 gfx::Insets insets = target_display->GetWorkAreaInsets(); 689 gfx::Insets insets = target_display->GetWorkAreaInsets();
688 target_display->set_bounds( 690 target_display->set_bounds(
689 gfx::Rect(new_target_origin, target_bounds.size())); 691 gfx::Rect(new_target_origin, target_bounds.size()));
690 target_display->UpdateWorkAreaFromInsets(insets); 692 target_display->UpdateWorkAreaFromInsets(insets);
691 693
692 return old_bounds != target_display->bounds(); 694 return old_bounds != target_display->bounds();
693 } 695 }
694 696
695 } // namespace display 697 } // namespace display
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698