forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaint_image_builder.cc
80 lines (70 loc) · 2.79 KB
/
paint_image_builder.cc
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// 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.
#include "cc/paint/paint_image_builder.h"
namespace cc {
// static
PaintImageBuilder PaintImageBuilder::WithDefault() {
return PaintImageBuilder();
}
// static
PaintImageBuilder PaintImageBuilder::WithCopy(PaintImage paint_image) {
return PaintImageBuilder(std::move(paint_image), false);
}
// static
PaintImageBuilder PaintImageBuilder::WithProperties(PaintImage paint_image) {
return PaintImageBuilder(std::move(paint_image), true);
}
PaintImageBuilder::PaintImageBuilder() = default;
PaintImageBuilder::PaintImageBuilder(PaintImage image, bool clear_contents)
: paint_image_(std::move(image)) {
#if DCHECK_IS_ON()
id_set_ = true;
#endif
if (clear_contents) {
paint_image_.sk_image_ = nullptr;
paint_image_.paint_record_ = nullptr;
paint_image_.paint_record_rect_ = gfx::Rect();
paint_image_.paint_image_generator_ = nullptr;
paint_image_.cached_sk_image_ = nullptr;
}
}
PaintImageBuilder::PaintImageBuilder(PaintImageBuilder&& other) = default;
PaintImageBuilder::~PaintImageBuilder() = default;
PaintImage PaintImageBuilder::TakePaintImage() {
#if DCHECK_IS_ON()
DCHECK(id_set_);
if (paint_image_.sk_image_) {
DCHECK(!paint_image_.paint_record_);
DCHECK(!paint_image_.paint_image_generator_);
DCHECK(!paint_image_.sk_image_->isLazyGenerated());
// TODO(khushalsagar): Assert that we don't have an animated image type
// here. The only case where this is possible is DragImage. There are 2 use
// cases going through that path, re-orienting the image and for use by the
// DragController. The first should never be triggered for an animated
// image (orientation changes can only be specified by JPEGs, none of the
// animation image types use it). For the latter the image is required to be
// decoded and used in blink, and should only need the default frame.
} else if (paint_image_.paint_record_) {
DCHECK(!paint_image_.sk_image_);
DCHECK(!paint_image_.paint_image_generator_);
// TODO(khushalsagar): Assert that we don't have an animated image type
// here.
} else if (paint_image_.paint_image_generator_) {
DCHECK(!paint_image_.sk_image_);
DCHECK(!paint_image_.paint_record_);
}
if (paint_image_.ShouldAnimate()) {
DCHECK(paint_image_.paint_image_generator_)
<< "Animated images must provide a generator";
for (const auto& frame : paint_image_.GetFrameMetadata())
DCHECK_GT(frame.duration, base::TimeDelta());
}
#endif
// We may already have a cached_sk_image_ if this builder was created with a
// copy.
if (!paint_image_.cached_sk_image_)
paint_image_.CreateSkImage();
return std::move(paint_image_);
}
} // namespace cc