1 // Copyright 2021 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 <v4l2_codec2/common/Common.h>
6 
7 #include <base/numerics/safe_math.h>
8 
9 namespace android {
10 
contains(const Rect & rect1,const Rect & rect2)11 bool contains(const Rect& rect1, const Rect& rect2) {
12     return (rect2.left >= rect1.left && rect2.right <= rect1.right && rect2.top >= rect1.top &&
13             rect2.bottom <= rect1.bottom);
14 }
15 
toString(const Rect & rect)16 std::string toString(const Rect& rect) {
17     return std::string("(") + std::to_string(rect.left) + "," + std::to_string(rect.top) + ") " +
18            std::to_string(rect.width()) + "x" + std::to_string(rect.height());
19 }
20 
getArea(const ui::Size & size)21 std::optional<int> getArea(const ui::Size& size) {
22     base::CheckedNumeric<int> checked_area = size.width;
23     checked_area *= size.height;
24     return checked_area.IsValid() ? std::optional<int>(checked_area.ValueOrDie()) : std::nullopt;
25 }
26 
isEmpty(const ui::Size & size)27 bool isEmpty(const ui::Size& size) {
28     return !size.width || !size.height;
29 }
30 
toString(const ui::Size & size)31 std::string toString(const ui::Size& size) {
32     return std::to_string(size.width) + "x" + std::to_string(size.height);
33 }
34 
35 }  // namespace android
36