forked from flutter/engine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:flutter/engine into uv_computation
- Loading branch information
Showing
57 changed files
with
8,169 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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/color_source_text_contents.h" | ||
|
||
#include "impeller/entity/contents/content_context.h" | ||
#include "impeller/entity/contents/texture_contents.h" | ||
#include "impeller/renderer/render_pass.h" | ||
|
||
namespace impeller { | ||
|
||
ColorSourceTextContents::ColorSourceTextContents() = default; | ||
|
||
ColorSourceTextContents::~ColorSourceTextContents() = default; | ||
|
||
void ColorSourceTextContents::SetTextContents( | ||
std::shared_ptr<TextContents> text_contents) { | ||
text_contents_ = std::move(text_contents); | ||
} | ||
|
||
void ColorSourceTextContents::SetColorSourceContents( | ||
std::shared_ptr<ColorSourceContents> color_source_contents) { | ||
color_source_contents_ = std::move(color_source_contents); | ||
} | ||
|
||
std::optional<Rect> ColorSourceTextContents::GetCoverage( | ||
const Entity& entity) const { | ||
return text_contents_->GetCoverage(entity); | ||
} | ||
|
||
void ColorSourceTextContents::SetTextPosition(Point position) { | ||
position_ = position; | ||
} | ||
|
||
bool ColorSourceTextContents::Render(const ContentContext& renderer, | ||
const Entity& entity, | ||
RenderPass& pass) const { | ||
auto coverage = text_contents_->GetCoverage(entity); | ||
if (!coverage.has_value()) { | ||
return true; | ||
} | ||
auto transform = entity.GetTransformation(); | ||
|
||
text_contents_->SetColor(Color::Black()); | ||
color_source_contents_->SetGeometry( | ||
Geometry::MakeRect(Rect::MakeSize(coverage->size))); | ||
|
||
// offset the color source so it behaves as if it were drawn in the original | ||
// position. | ||
auto effect_transform = | ||
color_source_contents_->GetInverseMatrix().Invert().Translate(-position_); | ||
color_source_contents_->SetEffectTransform(effect_transform); | ||
|
||
auto new_texture = renderer.MakeSubpass( | ||
"Text Color Blending", ISize::Ceil(coverage.value().size), | ||
[&](const ContentContext& context, RenderPass& pass) { | ||
Entity sub_entity; | ||
sub_entity.SetTransformation(transform); | ||
sub_entity.SetContents(text_contents_); | ||
sub_entity.SetBlendMode(BlendMode::kSource); | ||
if (!sub_entity.Render(context, pass)) { | ||
return false; | ||
} | ||
|
||
sub_entity.SetContents(color_source_contents_); | ||
sub_entity.SetBlendMode(BlendMode::kSourceIn); | ||
return sub_entity.Render(context, pass); | ||
}); | ||
if (!new_texture) { | ||
return false; | ||
} | ||
|
||
auto dest_rect = Rect::MakeSize(new_texture->GetSize()) | ||
.TransformBounds(transform.Invert()) | ||
.Shift(position_); | ||
|
||
auto texture_contents = TextureContents::MakeRect(dest_rect); | ||
texture_contents->SetTexture(new_texture); | ||
texture_contents->SetSourceRect(Rect::MakeSize(new_texture->GetSize())); | ||
return texture_contents->Render(renderer, entity, pass); | ||
} | ||
|
||
} // namespace impeller |
Oops, something went wrong.