summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/graphics/paint/drawing_display_item.h
blob: a6fa2cd2fa443f10a36f3cd45564b4f8ca2e72d6 (plain)
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
// Copyright 2014 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_DRAWING_DISPLAY_ITEM_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_DRAWING_DISPLAY_ITEM_H_

#include "base/compiler_specific.h"
#include "third_party/blink/renderer/platform/graphics/paint/display_item.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/skia/include/core/SkRefCnt.h"

namespace blink {

// DrawingDisplayItem contains recorded painting operations which can be
// replayed to produce a rastered output.
//
// This class has two notions of the bounds around the content that was recorded
// and will be produced by the item. The first is the |record_bounds| which
// describes the bounds of all content in the |record| in the space of the
// record. The second is the |visual_rect| which should describe the same thing,
// but takes into account transforms and clips that would apply to the
// PaintRecord, and is in the space of the DisplayItemList. This allows the
// visual_rect to be compared between DrawingDisplayItems, and to give bounds
// around what the user can actually see from the PaintRecord.
class PLATFORM_EXPORT DrawingDisplayItem : public DisplayItem {
 public:
  DISABLE_CFI_PERF
  DrawingDisplayItem(const DisplayItemClient& client,
                     Type type,
                     sk_sp<const PaintRecord> record);

  const sk_sp<const PaintRecord>& GetPaintRecord() const { return record_; }

  bool Equals(const DisplayItem& other) const final;

  bool KnownToBeOpaque() const {
    if (!RuntimeEnabledFeatures::CompositeAfterPaintEnabled())
      return false;
    if (!known_to_be_opaque_.has_value())
      known_to_be_opaque_.emplace(CalculateKnownToBeOpaque(record_.get()));
    return *known_to_be_opaque_;
  }
  void SetKnownToBeOpaqueForTesting() { known_to_be_opaque_.emplace(true); }

  SkColor BackgroundColor() const;

 private:
  bool CalculateKnownToBeOpaque(const PaintRecord*) const;

  sk_sp<const PaintRecord> record_;
  mutable base::Optional<bool> known_to_be_opaque_;
};

// TODO(dcheng): Move this ctor back inline once the clang plugin is fixed.
DISABLE_CFI_PERF
inline DrawingDisplayItem::DrawingDisplayItem(const DisplayItemClient& client,
                                              Type type,
                                              sk_sp<const PaintRecord> record)
    : DisplayItem(client,
                  type,
                  sizeof(*this),
                  /* draws_content*/ record && record->size()),
      record_(DrawsContent() ? std::move(record) : nullptr) {
  DCHECK(IsDrawingType(type));
}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_DRAWING_DISPLAY_ITEM_H_