• 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 
5 #ifndef SIZE_H_
6 #define SIZE_H_
7 
8 #include <string>
9 
10 #include "base/strings/stringprintf.h"
11 
12 namespace media {
13 
14 // Helper struct for size to replace gfx::size usage from original code.
15 // Only partial functions of gfx::size is implemented here.
16 struct Size {
17  public:
SizeSize18   Size() : width_(0), height_(0) {}
SizeSize19   Size(int width, int height)
20       : width_(width < 0 ? 0 : width), height_(height < 0 ? 0 : height) {}
21 
widthSize22   constexpr int width() const { return width_; }
heightSize23   constexpr int height() const { return height_; }
24 
set_widthSize25   void set_width(int width) { width_ = width < 0 ? 0 : width; }
set_heightSize26   void set_height(int height) { height_ = height < 0 ? 0 : height; }
27 
SetSizeSize28   void SetSize(int width, int height) {
29     set_width(width);
30     set_height(height);
31   }
32 
IsEmptySize33   bool IsEmpty() const { return !width() || !height(); }
34 
ToStringSize35   std::string ToString() const {
36     return base::StringPrintf("%dx%d", width(), height());
37   }
38 
39   Size& operator=(const Size& ps) {
40     set_width(ps.width());
41     set_height(ps.height());
42     return *this;
43   }
44 
45  private:
46   int width_;
47   int height_;
48 };
49 
50 inline bool operator==(const Size& lhs, const Size& rhs) {
51   return lhs.width() == rhs.width() && lhs.height() == rhs.height();
52 }
53 
54 inline bool operator!=(const Size& lhs, const Size& rhs) {
55   return !(lhs == rhs);
56 }
57 
58 }  // namespace media
59 
60 #endif  // SIZE_H_
61