Add ClearContents to apply specified contents to the entire render target. (flutter/engine#88)
This commit is contained in:
@@ -390,5 +390,13 @@ TEST_F(AiksTest, CanRenderEmojiTextFrame) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
TEST_F(AiksTest, CanDrawPaint) {
|
||||
Paint paint;
|
||||
paint.color = Color::MediumTurquoise();
|
||||
Canvas canvas;
|
||||
canvas.DrawPaint(paint);
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "impeller/aiks/paint_pass_delegate.h"
|
||||
#include "impeller/entity/contents/clear_contents.h"
|
||||
#include "impeller/entity/contents/clip_contents.h"
|
||||
#include "impeller/entity/contents/text_contents.h"
|
||||
#include "impeller/entity/contents/texture_contents.h"
|
||||
@@ -113,6 +114,16 @@ void Canvas::DrawPath(Path path, Paint paint) {
|
||||
GetCurrentPass().AddEntity(std::move(entity));
|
||||
}
|
||||
|
||||
void Canvas::DrawPaint(Paint paint) {
|
||||
Entity entity;
|
||||
entity.SetTransformation(GetCurrentTransformation());
|
||||
entity.SetStencilDepth(GetStencilDepth());
|
||||
entity.SetContents(
|
||||
std::make_shared<ClearContents>(paint.CreateContentsForEntity()));
|
||||
|
||||
GetCurrentPass().AddEntity(std::move(entity));
|
||||
}
|
||||
|
||||
void Canvas::DrawRect(Rect rect, Paint paint) {
|
||||
DrawPath(PathBuilder{}.AddRect(rect).TakePath(), std::move(paint));
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ class Canvas {
|
||||
|
||||
void DrawPath(Path path, Paint paint);
|
||||
|
||||
void DrawPaint(Paint paint);
|
||||
|
||||
void DrawRect(Rect rect, Paint paint);
|
||||
|
||||
void DrawCircle(Point center, Scalar radius, Paint paint);
|
||||
|
||||
@@ -397,12 +397,15 @@ void DisplayListDispatcher::clipPath(const SkPath& path,
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
void DisplayListDispatcher::drawColor(SkColor color, SkBlendMode mode) {
|
||||
UNIMPLEMENTED;
|
||||
Paint paint;
|
||||
paint.color = ToColor(color);
|
||||
FML_LOG(ERROR) << "Blend mode on drawColor ignored.";
|
||||
canvas_.DrawPaint(paint);
|
||||
}
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
void DisplayListDispatcher::drawPaint() {
|
||||
UNIMPLEMENTED;
|
||||
canvas_.DrawPaint(paint_);
|
||||
}
|
||||
|
||||
// |flutter::Dispatcher|
|
||||
|
||||
@@ -29,6 +29,8 @@ impeller_shaders("entity_shaders") {
|
||||
|
||||
impeller_component("entity") {
|
||||
sources = [
|
||||
"contents/clear_contents.cc",
|
||||
"contents/clear_contents.h",
|
||||
"contents/clip_contents.cc",
|
||||
"contents/clip_contents.h",
|
||||
"contents/content_context.cc",
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright 2013 The Flutter 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 "impeller/entity/contents/clear_contents.h"
|
||||
|
||||
#include "impeller/entity/entity.h"
|
||||
#include "impeller/geometry/path_builder.h"
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
ClearContents::ClearContents(std::shared_ptr<Contents> contents)
|
||||
: contents_(std::move(contents)) {}
|
||||
|
||||
ClearContents::~ClearContents() = default;
|
||||
|
||||
// |Contents|
|
||||
bool ClearContents::Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const {
|
||||
if (contents_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
// Instead of an entity that doesn't know its size because the render target
|
||||
// size was unknown to it at construction time, create a copy but substitute
|
||||
// the contents with the replacements.
|
||||
Entity clear_entity = entity;
|
||||
clear_entity.SetPath(
|
||||
PathBuilder{}.AddRect(Size(pass.GetRenderTargetSize())).TakePath());
|
||||
return contents_->Render(renderer, clear_entity, pass);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
33
engine/src/flutter/impeller/entity/contents/clear_contents.h
Normal file
33
engine/src/flutter/impeller/entity/contents/clear_contents.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/entity/contents/contents.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief Disregard existing contents on the render target and use the
|
||||
/// provided filter to render to the entire target.
|
||||
///
|
||||
class ClearContents final : public Contents {
|
||||
public:
|
||||
ClearContents(std::shared_ptr<Contents> contents);
|
||||
|
||||
~ClearContents();
|
||||
|
||||
// |Contents|
|
||||
bool Render(const ContentContext& renderer,
|
||||
const Entity& entity,
|
||||
RenderPass& pass) const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Contents> contents_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ClearContents);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
Reference in New Issue
Block a user