Flutter Engine
texture_layer.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "flutter/flow/layers/texture_layer.h"
6 
7 #include "flutter/common/graphics/texture.h"
8 
9 namespace flutter {
10 
11 TextureLayer::TextureLayer(const SkPoint& offset,
12  const SkSize& size,
13  int64_t texture_id,
14  bool freeze,
15  const SkSamplingOptions& sampling)
16  : offset_(offset),
17  size_(size),
18  texture_id_(texture_id),
19  freeze_(freeze),
20  sampling_(sampling) {}
21 
22 #ifdef FLUTTER_ENABLE_DIFF_CONTEXT
23 
24 void TextureLayer::Diff(DiffContext* context, const Layer* old_layer) {
25  DiffContext::AutoSubtreeRestore subtree(context);
26  if (!context->IsSubtreeDirty()) {
27  FML_DCHECK(old_layer);
28  auto prev = old_layer->as_texture_layer();
29  // TODO(knopp) It would be nice to be able to determine that a texture is
30  // dirty
31  context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(prev));
32  }
33  context->AddLayerBounds(SkRect::MakeXYWH(offset_.x(), offset_.y(),
34  size_.width(), size_.height()));
35  context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
36 }
37 
38 #endif // FLUTTER_ENABLE_DIFF_CONTEXT
39 
40 void TextureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
41  TRACE_EVENT0("flutter", "TextureLayer::Preroll");
42 
43  set_paint_bounds(SkRect::MakeXYWH(offset_.x(), offset_.y(), size_.width(),
44  size_.height()));
45  context->has_texture_layer = true;
46 }
47 
48 void TextureLayer::Paint(PaintContext& context) const {
49  TRACE_EVENT0("flutter", "TextureLayer::Paint");
50  FML_DCHECK(needs_painting(context));
51 
52  std::shared_ptr<Texture> texture =
53  context.texture_registry.GetTexture(texture_id_);
54  if (!texture) {
55  TRACE_EVENT_INSTANT0("flutter", "null texture");
56  return;
57  }
58  texture->Paint(*context.leaf_nodes_canvas, paint_bounds(), freeze_,
59  context.gr_context, sampling_);
60 }
61 
62 } // namespace flutter
TextureRegistry & texture_registry
Definition: layer.h:150
G_BEGIN_DECLS FlTexture * texture
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_DCHECK(condition)
Definition: logging.h:86
#define TRACE_EVENT_INSTANT0(category_group, name)
Definition: trace_event.h:119
int64_t texture_id
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
GrDirectContext * gr_context
Definition: layer.h:146
bool needs_painting(PaintContext &context) const
Definition: layer.h:249
const SkRect & paint_bounds() const
Definition: layer.h:227
void Paint(PaintContext &context) const override
SkCanvas * leaf_nodes_canvas
Definition: layer.h:145
TextureLayer(const SkPoint &offset, const SkSize &size, int64_t texture_id, bool freeze, const SkSamplingOptions &sampling)
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:240
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
std::shared_ptr< Texture > GetTexture(int64_t id)
Definition: texture.cc:43