Flutter Engine
The Flutter Engine
size.cc
Go to the documentation of this file.
1// Copyright (c) 2012 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 "size.h"
6
7#if defined(OS_WIN)
8#include <windows.h>
9#elif defined(OS_IOS)
10#include <CoreGraphics/CoreGraphics.h>
11#elif defined(OS_APPLE)
12#include <ApplicationServices/ApplicationServices.h>
13#endif
14
18#include "base/string_utils.h"
19#include "size_conversions.h"
20
21namespace gfx {
22
23#if defined(OS_APPLE)
24Size::Size(const CGSize& s)
25 : width_(s.width < 0 ? 0 : s.width), height_(s.height < 0 ? 0 : s.height) {}
26
27Size& Size::operator=(const CGSize& s) {
28 set_width(s.width);
29 set_height(s.height);
30 return *this;
31}
32#endif
33
35 Enlarge(size.width(), size.height());
36}
37
39 Enlarge(-size.width(), -size.height());
40}
41
42#if defined(OS_WIN)
43SIZE Size::ToSIZE() const {
44 SIZE s;
45 s.cx = width();
46 s.cy = height();
47 return s;
48}
49#elif defined(OS_APPLE)
50CGSize Size::ToCGSize() const {
51 return CGSizeMake(width(), height());
52}
53#endif
54
55int Size::GetArea() const {
56 return GetCheckedArea().ValueOrDie();
57}
58
59base::CheckedNumeric<int> Size::GetCheckedArea() const {
60 base::CheckedNumeric<int> checked_area = width();
61 checked_area *= height();
62 return checked_area;
63}
64
65void Size::Enlarge(int grow_width, int grow_height) {
66 SetSize(base::ClampAdd(width(), grow_width),
67 base::ClampAdd(height(), grow_height));
68}
69
70void Size::SetToMin(const Size& other) {
71 width_ = width() <= other.width() ? width() : other.width();
72 height_ = height() <= other.height() ? height() : other.height();
73}
74
75void Size::SetToMax(const Size& other) {
76 width_ = width() >= other.width() ? width() : other.width();
77 height_ = height() >= other.height() ? height() : other.height();
78}
79
80std::string Size::ToString() const {
81 return base::StringPrintf("%dx%d", width(), height());
82}
83
84Size ScaleToCeiledSize(const Size& size, float x_scale, float y_scale) {
85 if (x_scale == 1.f && y_scale == 1.f)
86 return size;
87 return ToCeiledSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
88}
89
91 if (scale == 1.f)
92 return size;
94}
95
96Size ScaleToFlooredSize(const Size& size, float x_scale, float y_scale) {
97 if (x_scale == 1.f && y_scale == 1.f)
98 return size;
99 return ToFlooredSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
100}
101
103 if (scale == 1.f)
104 return size;
106}
107
108Size ScaleToRoundedSize(const Size& size, float x_scale, float y_scale) {
109 if (x_scale == 1.f && y_scale == 1.f)
110 return size;
111 return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
112}
113
115 if (scale == 1.f)
116 return size;
118}
119
120} // namespace gfx
Definition: size.h:26
constexpr Size()
Definition: size.h:28
constexpr int height() const
Definition: size.h:50
constexpr int width() const
Definition: size.h:49
struct MyStruct s
std::string StringPrintf(const std::string &format, Args... args)
Definition: string_utils.h:18
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: insets.cc:10
Size ToFlooredSize(const SizeF &size)
Size ScaleToCeiledSize(const Size &size, float scale)
Definition: size.cc:90
Size ScaleToRoundedSize(const Size &size, float scale)
Definition: size.cc:114
Size ScaleToFlooredSize(const Size &size, float scale)
Definition: size.cc:102
SizeF ScaleSize(const SizeF &s, float x_scale, float y_scale)
Definition: size_f.cc:33
Size ToCeiledSize(const SizeF &size)
Size ToRoundedSize(const SizeF &size)
static std::string ToString(CompilerBackend::Type type)
Definition: reflector.cc:559
TSize< Scalar > Size
Definition: size.h:137
SINT Vec< N, T > & operator-=(Vec< N, T > &x, const Vec< N, T > &y)
Definition: SkVx.h:451
SINT Vec< N, T > & operator+=(Vec< N, T > &x, const Vec< N, T > &y)
Definition: SkVx.h:450
#define SIZE
int32_t height
int32_t width
const Scalar scale