summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h')
-rw-r--r--chromium/third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h89
1 files changed, 52 insertions, 37 deletions
diff --git a/chromium/third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h b/chromium/third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h
index 23e015402ff..b698402e038 100644
--- a/chromium/third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h
+++ b/chromium/third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h
@@ -5,68 +5,83 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_ADJUST_PAINT_OFFSET_SCOPE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_ADJUST_PAINT_OFFSET_SCOPE_H_
-#include "third_party/blink/renderer/core/layout/layout_box.h"
+#include "third_party/blink/renderer/core/layout/layout_box_model_object.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/platform/graphics/paint/scoped_paint_chunk_properties.h"
namespace blink {
+// Adjusts cull rect of the input PaintInfo and finds the paint offset for a
+// LayoutObject or an NGPaintFragment before painting. Normally a
+// Paint(const PaintInfo&) method creates an AdjustPaintOffsetScope and holds it
+// in the stack, and passes it to other PaintXXX() methods that paint different
+// parts of the object.
class AdjustPaintOffsetScope {
STACK_ALLOCATED();
public:
- AdjustPaintOffsetScope(const LayoutBox& box,
- const PaintInfo& paint_info,
- const LayoutPoint& paint_offset)
- : old_paint_info_(paint_info) {
- if (!RuntimeEnabledFeatures::SlimmingPaintV175Enabled() ||
- !AdjustPaintOffset(box))
- adjusted_paint_offset_ = paint_offset + box.Location();
+ AdjustPaintOffsetScope(const LayoutObject& object,
+ const PaintInfo& paint_info)
+ : fragment_to_paint_(paint_info.FragmentToPaint(object)),
+ input_paint_info_(paint_info) {
+ if (!fragment_to_paint_) {
+ // The object has nothing to paint in the current fragment.
+ return;
+ }
+ if (&object == paint_info.PaintContainer()) {
+ // PaintLayerPainter already adjusted for PaintOffsetTranslation for
+ // PaintContainer. TODO(wangxianzhu): Can we combine the code?
+ return;
+ }
+ const auto* properties = fragment_to_paint_->PaintProperties();
+ if (properties && properties->PaintOffsetTranslation()) {
+ AdjustForPaintOffsetTranslation(object,
+ properties->PaintOffsetTranslation());
+ }
}
AdjustPaintOffsetScope(const NGPaintFragment& fragment,
- const PaintInfo& paint_info,
- const LayoutPoint& paint_offset)
- : old_paint_info_(paint_info) {
- DCHECK(fragment.GetLayoutObject());
- const LayoutBox& box = ToLayoutBox(*fragment.GetLayoutObject());
- if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled() &&
- AdjustPaintOffset(box))
- return;
- if (UNLIKELY(box.HasSelfPaintingLayer())) {
- // There is no containing block here, we are painting from origin.
- // paint_offset is 0,0
- // box.Location is offset from Layer()
- adjusted_paint_offset_ = paint_offset + box.Location();
- } else {
- adjusted_paint_offset_ = paint_offset + fragment.Offset().ToLayoutPoint();
- }
+ const PaintInfo& paint_info)
+ : AdjustPaintOffsetScope(*fragment.GetLayoutObject(), paint_info) {}
+
+ ~AdjustPaintOffsetScope() {
+ if (paint_offset_translation_as_drawing_)
+ FinishPaintOffsetTranslationAsDrawing();
}
const PaintInfo& GetPaintInfo() const {
- return new_paint_info_ ? *new_paint_info_ : old_paint_info_;
+ return adjusted_paint_info_ ? *adjusted_paint_info_ : input_paint_info_;
}
PaintInfo& MutablePaintInfo() {
- if (!new_paint_info_)
- new_paint_info_.emplace(old_paint_info_);
- return *new_paint_info_;
+ if (!adjusted_paint_info_)
+ adjusted_paint_info_.emplace(input_paint_info_);
+ return *adjusted_paint_info_;
}
- LayoutPoint AdjustedPaintOffset() const { return adjusted_paint_offset_; }
+ LayoutPoint PaintOffset() const {
+ // TODO(wangxianzhu): Use DCHECK(fragment_to_paint_) when all painters
+ // check FragmentToPaint() before painting.
+ return fragment_to_paint_
+ ? fragment_to_paint_->PaintOffset()
+ : LayoutPoint(LayoutUnit::NearlyMax(), LayoutUnit::NearlyMax());
+ }
- // True if child will use LayoutObject::Location to compute adjusted_offset.
- static bool WillUseLegacyLocation(const LayoutBox* child);
+ const FragmentData* FragmentToPaint() const { return fragment_to_paint_; }
private:
- // Returns true if paint info and offset has been adjusted.
- bool AdjustPaintOffset(const LayoutBox&);
+ void AdjustForPaintOffsetTranslation(
+ const LayoutObject&,
+ const TransformPaintPropertyNode* paint_offset_translation);
+
+ void FinishPaintOffsetTranslationAsDrawing();
- const PaintInfo& old_paint_info_;
- LayoutPoint adjusted_paint_offset_;
- base::Optional<PaintInfo> new_paint_info_;
- base::Optional<ScopedPaintChunkProperties> contents_properties_;
+ const FragmentData* fragment_to_paint_;
+ const PaintInfo& input_paint_info_;
+ base::Optional<PaintInfo> adjusted_paint_info_;
+ base::Optional<ScopedPaintChunkProperties> chunk_properties_;
+ bool paint_offset_translation_as_drawing_ = false;
};
} // namespace blink