• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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 // Note: ported from Chromium commit head: a8e9f71
5 // Note: only necessary functions are ported from gfx::Size
6 
7 #ifndef SIZE_H_
8 #define SIZE_H_
9 
10 #include <string>
11 
12 #include "base/strings/stringprintf.h"
13 
14 namespace media {
15 
16 // Helper struct for size to replace gfx::size usage from original code.
17 // Only partial functions of gfx::size is implemented here.
18 struct Size {
19  public:
SizeSize20   Size() : width_(0), height_(0) {}
SizeSize21   Size(int width, int height)
22       : width_(width < 0 ? 0 : width), height_(height < 0 ? 0 : height) {}
23 
widthSize24   constexpr int width() const { return width_; }
heightSize25   constexpr int height() const { return height_; }
26 
set_widthSize27   void set_width(int width) { width_ = width < 0 ? 0 : width; }
set_heightSize28   void set_height(int height) { height_ = height < 0 ? 0 : height; }
29 
SetSizeSize30   void SetSize(int width, int height) {
31     set_width(width);
32     set_height(height);
33   }
34 
IsEmptySize35   bool IsEmpty() const { return !width() || !height(); }
36 
ToStringSize37   std::string ToString() const {
38     return base::StringPrintf("%dx%d", width(), height());
39   }
40 
41   Size& operator=(const Size& ps) {
42     set_width(ps.width());
43     set_height(ps.height());
44     return *this;
45   }
46 
47  private:
48   int width_;
49   int height_;
50 };
51 
52 inline bool operator==(const Size& lhs, const Size& rhs) {
53   return lhs.width() == rhs.width() && lhs.height() == rhs.height();
54 }
55 
56 inline bool operator!=(const Size& lhs, const Size& rhs) {
57   return !(lhs == rhs);
58 }
59 
60 }  // namespace media
61 
62 #endif  // SIZE_H_
63