X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Ftext%2Ftext-visual.cpp;h=9744ca548f3b4cde5f1621d46d7b31df720e6556;hp=b8d848d44eebeca37b7b0bf7d86ac0222e6f4f2d;hb=ba2b1aa2e87716f4ef107e0fa627573475e93470;hpb=564bc0be615a00d681e01d00250a0279068efcf7 diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index b8d848d..9744ca5 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include #include +#include #include // INTERNAL HEADER @@ -49,6 +50,8 @@ namespace Internal { namespace { +const int CUSTOM_PROPERTY_COUNT(5); // anim,premul,size,offset,multicol + const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); /** @@ -237,6 +240,15 @@ void TextVisual::DoCreateInstancePropertyMap(Property::Map& map) const map.Insert(Toolkit::TextVisual::Property::TEXT, text); } +void TextVisual::EnablePreMultipliedAlpha(bool preMultiplied) +{ + // Make always enable pre multiplied alpha whether preMultiplied value is false. + if(!preMultiplied) + { + DALI_LOG_WARNING("Note : TextVisual cannot disable PreMultipliedAlpha\n"); + } +} + TextVisual::TextVisual(VisualFactoryCache& factoryCache) : Visual::Base(factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::TEXT), mController(Text::Controller::New()), @@ -245,6 +257,8 @@ TextVisual::TextVisual(VisualFactoryCache& factoryCache) mTextColorAnimatableIndex(Property::INVALID_INDEX), mRendererUpdateNeeded(false) { + // Enable the pre-multiplied alpha to improve the text quality + mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; } TextVisual::~TextVisual() @@ -256,7 +270,8 @@ void TextVisual::OnInitialize() Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); Shader shader = GetTextShader(mFactoryCache, TextType::SINGLE_COLOR_TEXT, TextType::NO_EMOJI, TextType::NO_STYLES); - mImpl->mRenderer = Renderer::New(geometry, shader); + mImpl->mRenderer = VisualRenderer::New(geometry, shader); + mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT); } void TextVisual::DoSetProperties(const Property::Map& propertyMap) @@ -291,13 +306,10 @@ void TextVisual::DoSetOnScene(Actor& actor) mImpl->mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, Toolkit::DepthIndex::CONTENT); - // Enable the pre-multiplied alpha to improve the text quality - EnablePreMultipliedAlpha(true); - const Vector4& defaultColor = mController->GetTextModel()->GetDefaultColor(); if(mTextColorAnimatableIndex == Property::INVALID_INDEX) { - mTextColorAnimatableIndex = mImpl->mRenderer.RegisterProperty("uTextColorAnimatable", defaultColor); + mTextColorAnimatableIndex = mImpl->mRenderer.RegisterUniqueProperty("uTextColorAnimatable", defaultColor); } else { @@ -320,6 +332,7 @@ void TextVisual::DoSetOnScene(Actor& actor) // Make zero if the alpha value of text color is zero to skip rendering text if(!mOpacityConstraint) { + // VisualRenderer::Property::OPACITY uses same animatable property internally. mOpacityConstraint = Constraint::New(mImpl->mRenderer, Dali::DevelRenderer::Property::OPACITY, OpacityConstraint); mOpacityConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex)); } @@ -555,7 +568,7 @@ void TextVisual::UpdateRenderer() const bool markupProcessorEnabled = mController->IsMarkupProcessorEnabled(); const bool strikethroughEnabled = mController->GetTextModel()->IsStrikethroughEnabled(); - const bool styleEnabled = (shadowEnabled || underlineEnabled || outlineEnabled || backgroundEnabled || markupProcessorEnabled || strikethroughEnabled); + const bool styleEnabled = (shadowEnabled || underlineEnabled || outlineEnabled || backgroundEnabled || markupProcessorEnabled || strikethroughEnabled); const bool isOverlayStyle = underlineEnabled || strikethroughEnabled; AddRenderer(control, relayoutSize, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle); @@ -593,7 +606,7 @@ PixelData TextVisual::ConvertToPixelData(unsigned char* buffer, int width, int h return pixelData; } -void TextVisual::CreateTextureSet(TilingInfo& info, Renderer& renderer, Sampler& sampler, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled, bool isOverlayStyle) +void TextVisual::CreateTextureSet(TilingInfo& info, VisualRenderer& renderer, Sampler& sampler, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled, bool isOverlayStyle) { TextureSet textureSet = TextureSet::New(); unsigned int textureSetIndex = 0u; @@ -607,16 +620,16 @@ void TextVisual::CreateTextureSet(TilingInfo& info, Renderer& renderer, Sampler& ++textureSetIndex; } - if(styleEnabled && info.styleBuffer) + if(styleEnabled && info.styleBuffer && info.overlayStyleBuffer) { PixelData styleData = ConvertToPixelData(info.styleBuffer, info.width, info.height, info.offsetPosition, Pixel::RGBA8888); AddTexture(textureSet, styleData, sampler, textureSetIndex); ++textureSetIndex; - } - if(styleEnabled && isOverlayStyle && info.styleBuffer) - { - PixelData overlayStyleData = ConvertToPixelData(info.styleBuffer, info.width, info.height, info.offsetPosition, Pixel::RGBA8888); + // TODO : We need to seperate whether use overlayStyle or not. + // Current text visual shader required both of them. + + PixelData overlayStyleData = ConvertToPixelData(info.overlayStyleBuffer, info.width, info.height, info.offsetPosition, Pixel::RGBA8888); AddTexture(textureSet, overlayStyleData, sampler, textureSetIndex); ++textureSetIndex; } @@ -630,17 +643,17 @@ void TextVisual::CreateTextureSet(TilingInfo& info, Renderer& renderer, Sampler& renderer.SetTextures(textureSet); //Register transform properties - mImpl->mTransform.RegisterUniforms(renderer, Direction::LEFT_TO_RIGHT); + mImpl->mTransform.SetUniforms(renderer, Direction::LEFT_TO_RIGHT); // Enable the pre-multiplied alpha to improve the text quality renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true); renderer.RegisterProperty(PREMULTIPLIED_ALPHA, 1.0f); // Set size and offset for the tiling. - renderer.RegisterProperty(SIZE, Vector2(info.width, info.height)); - renderer.RegisterProperty(OFFSET, Vector2(info.offSet.x, info.offSet.y)); - renderer.RegisterProperty("uHasMultipleTextColors", static_cast(hasMultipleTextColors)); + renderer.SetProperty(VisualRenderer::Property::TRANSFORM_SIZE, Vector2(info.width, info.height)); + renderer.SetProperty(VisualRenderer::Property::TRANSFORM_OFFSET, Vector2(info.offSet.x, info.offSet.y)); renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + renderer.RegisterProperty("uHasMultipleTextColors", static_cast(hasMultipleTextColors)); mRendererList.push_back(renderer); } @@ -660,7 +673,7 @@ void TextVisual::AddRenderer(Actor& actor, const Vector2& size, bool hasMultiple mImpl->mRenderer.SetTextures(textureSet); //Register transform properties - mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); + mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT); mImpl->mRenderer.RegisterProperty("uHasMultipleTextColors", static_cast(hasMultipleTextColors)); mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); @@ -698,6 +711,14 @@ void TextVisual::AddRenderer(Actor& actor, const Vector2& size, bool hasMultiple PixelData styleData = mTypesetter->Render(size, textDirection, Text::Typesetter::RENDER_NO_TEXT, false, Pixel::RGBA8888); Dali::DevelPixelData::PixelDataBuffer stylePixelData = Dali::DevelPixelData::ReleasePixelDataBuffer(styleData); info.styleBuffer = stylePixelData.buffer; + + // TODO : We need to seperate whether use overlayStyle or not. + // Current text visual shader required both of them. + + // Create RGBA texture for all the overlay styles + PixelData overlayStyleData = mTypesetter->Render(size, textDirection, Text::Typesetter::RENDER_OVERLAY_STYLE, false, Pixel::RGBA8888); + Dali::DevelPixelData::PixelDataBuffer overlayStylePixelData = Dali::DevelPixelData::ReleasePixelDataBuffer(overlayStyleData); + info.overlayStyleBuffer = overlayStylePixelData.buffer; } if(containsColorGlyph && !hasMultipleTextColors) @@ -728,7 +749,7 @@ void TextVisual::AddRenderer(Actor& actor, const Vector2& size, bool hasMultiple // Create a renderer by cutting maxTextureSize. while(verifiedHeight > 0) { - Renderer tilingRenderer = Renderer::New(geometry, shader); + VisualRenderer tilingRenderer = VisualRenderer::New(geometry, shader); tilingRenderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, Toolkit::DepthIndex::CONTENT); // New offset position of buffer for tiling. info.offsetPosition += offsetPosition; @@ -784,6 +805,10 @@ TextureSet TextVisual::GetTextTexture(const Vector2& size, bool hasMultipleTextC PixelData styleData = mTypesetter->Render(size, textDirection, Text::Typesetter::RENDER_NO_TEXT, false, Pixel::RGBA8888); AddTexture(textureSet, styleData, sampler, textureSetIndex); ++textureSetIndex; + + // TODO : We need to seperate whether use overlayStyle or not. + // Current text visual shader required both of them. + // Create RGBA texture for overlay styles such as underline and strikethrough (without the text itself) PixelData overlayStyleData = mTypesetter->Render(size, textDirection, Text::Typesetter::RENDER_OVERLAY_STYLE, false, Pixel::RGBA8888); AddTexture(textureSet, overlayStyleData, sampler, textureSetIndex); @@ -875,4 +900,4 @@ Shader TextVisual::GetTextShader(VisualFactoryCache& factoryCache, bool hasMulti } // namespace Toolkit -} // namespace Dali \ No newline at end of file +} // namespace Dali