huangcm
2025-02-28 b45e871a67cd1272e3da9ba5bd383f832b0f1824
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Note: ported from Chromium commit head: a8e9f71
// Note: only necessary functions are ported from gfx::Size
 
#ifndef SIZE_H_
#define SIZE_H_
 
#include <string>
 
#include "base/strings/stringprintf.h"
 
namespace media {
 
// Helper struct for size to replace gfx::size usage from original code.
// Only partial functions of gfx::size is implemented here.
struct Size {
 public:
  Size() : width_(0), height_(0) {}
  Size(int width, int height)
      : width_(width < 0 ? 0 : width), height_(height < 0 ? 0 : height) {}
 
  constexpr int width() const { return width_; }
  constexpr int height() const { return height_; }
 
  void set_width(int width) { width_ = width < 0 ? 0 : width; }
  void set_height(int height) { height_ = height < 0 ? 0 : height; }
 
  void SetSize(int width, int height) {
    set_width(width);
    set_height(height);
  }
 
  bool IsEmpty() const { return !width() || !height(); }
 
  std::string ToString() const {
    return base::StringPrintf("%dx%d", width(), height());
  }
 
  Size& operator=(const Size& ps) {
    set_width(ps.width());
    set_height(ps.height());
    return *this;
  }
 
 private:
  int width_;
  int height_;
};
 
inline bool operator==(const Size& lhs, const Size& rhs) {
  return lhs.width() == rhs.width() && lhs.height() == rhs.height();
}
 
inline bool operator!=(const Size& lhs, const Size& rhs) {
  return !(lhs == rhs);
}
 
}  // namespace media
 
#endif  // SIZE_H_