Skip to content

Commit 6e77886

Browse files
chinmaygardednfield
authored andcommitted
Add ClearContents to apply specified contents to the entire render target. (flutter#88)
1 parent 503dff6 commit 6e77886

File tree

7 files changed

+95
-2
lines changed

7 files changed

+95
-2
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,5 +390,13 @@ TEST_F(AiksTest, CanRenderEmojiTextFrame) {
390390
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
391391
}
392392

393+
TEST_F(AiksTest, CanDrawPaint) {
394+
Paint paint;
395+
paint.color = Color::MediumTurquoise();
396+
Canvas canvas;
397+
canvas.DrawPaint(paint);
398+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
399+
}
400+
393401
} // namespace testing
394402
} // namespace impeller

impeller/aiks/canvas.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "flutter/fml/logging.h"
1010
#include "impeller/aiks/paint_pass_delegate.h"
11+
#include "impeller/entity/contents/clear_contents.h"
1112
#include "impeller/entity/contents/clip_contents.h"
1213
#include "impeller/entity/contents/text_contents.h"
1314
#include "impeller/entity/contents/texture_contents.h"
@@ -113,6 +114,16 @@ void Canvas::DrawPath(Path path, Paint paint) {
113114
GetCurrentPass().AddEntity(std::move(entity));
114115
}
115116

117+
void Canvas::DrawPaint(Paint paint) {
118+
Entity entity;
119+
entity.SetTransformation(GetCurrentTransformation());
120+
entity.SetStencilDepth(GetStencilDepth());
121+
entity.SetContents(
122+
std::make_shared<ClearContents>(paint.CreateContentsForEntity()));
123+
124+
GetCurrentPass().AddEntity(std::move(entity));
125+
}
126+
116127
void Canvas::DrawRect(Rect rect, Paint paint) {
117128
DrawPath(PathBuilder{}.AddRect(rect).TakePath(), std::move(paint));
118129
}

impeller/aiks/canvas.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class Canvas {
5959

6060
void DrawPath(Path path, Paint paint);
6161

62+
void DrawPaint(Paint paint);
63+
6264
void DrawRect(Rect rect, Paint paint);
6365

6466
void DrawCircle(Point center, Scalar radius, Paint paint);

impeller/display_list/display_list_dispatcher.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,15 @@ void DisplayListDispatcher::clipPath(const SkPath& path,
397397

398398
// |flutter::Dispatcher|
399399
void DisplayListDispatcher::drawColor(SkColor color, SkBlendMode mode) {
400-
UNIMPLEMENTED;
400+
Paint paint;
401+
paint.color = ToColor(color);
402+
FML_LOG(ERROR) << "Blend mode on drawColor ignored.";
403+
canvas_.DrawPaint(paint);
401404
}
402405

403406
// |flutter::Dispatcher|
404407
void DisplayListDispatcher::drawPaint() {
405-
UNIMPLEMENTED;
408+
canvas_.DrawPaint(paint_);
406409
}
407410

408411
// |flutter::Dispatcher|

impeller/entity/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ impeller_shaders("entity_shaders") {
2929

3030
impeller_component("entity") {
3131
sources = [
32+
"contents/clear_contents.cc",
33+
"contents/clear_contents.h",
3234
"contents/clip_contents.cc",
3335
"contents/clip_contents.h",
3436
"contents/content_context.cc",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 "impeller/entity/contents/clear_contents.h"
6+
7+
#include "impeller/entity/entity.h"
8+
#include "impeller/geometry/path_builder.h"
9+
#include "impeller/renderer/render_pass.h"
10+
11+
namespace impeller {
12+
13+
ClearContents::ClearContents(std::shared_ptr<Contents> contents)
14+
: contents_(std::move(contents)) {}
15+
16+
ClearContents::~ClearContents() = default;
17+
18+
// |Contents|
19+
bool ClearContents::Render(const ContentContext& renderer,
20+
const Entity& entity,
21+
RenderPass& pass) const {
22+
if (contents_ == nullptr) {
23+
return false;
24+
}
25+
// Instead of an entity that doesn't know its size because the render target
26+
// size was unknown to it at construction time, create a copy but substitute
27+
// the contents with the replacements.
28+
Entity clear_entity = entity;
29+
clear_entity.SetPath(
30+
PathBuilder{}.AddRect(Size(pass.GetRenderTargetSize())).TakePath());
31+
return contents_->Render(renderer, clear_entity, pass);
32+
}
33+
34+
} // namespace impeller
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
#pragma once
6+
7+
#include "flutter/fml/macros.h"
8+
#include "impeller/entity/contents/contents.h"
9+
10+
namespace impeller {
11+
12+
//------------------------------------------------------------------------------
13+
/// @brief Disregard existing contents on the render target and use the
14+
/// provided filter to render to the entire target.
15+
///
16+
class ClearContents final : public Contents {
17+
public:
18+
ClearContents(std::shared_ptr<Contents> contents);
19+
20+
~ClearContents();
21+
22+
// |Contents|
23+
bool Render(const ContentContext& renderer,
24+
const Entity& entity,
25+
RenderPass& pass) const override;
26+
27+
private:
28+
std::shared_ptr<Contents> contents_;
29+
30+
FML_DISALLOW_COPY_AND_ASSIGN(ClearContents);
31+
};
32+
33+
} // namespace impeller

0 commit comments

Comments
 (0)