2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/visuals/image/image-visual.h>
22 #include <dali/devel-api/adaptor-framework/image-loading.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/rendering/renderer-devel.h>
25 #include <dali/devel-api/rendering/texture-devel.h>
26 #include <dali/devel-api/scripting/enum-helper.h>
27 #include <dali/devel-api/scripting/scripting.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/public-api/actors/layer.h>
30 #include <dali/public-api/adaptor-framework/async-task-manager.h>
31 #include <dali/public-api/rendering/decorated-visual-renderer.h>
32 #include <cstring> // for strlen()
35 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
36 #include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
37 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
38 #include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
39 #include <dali-toolkit/internal/visuals/image-visual-shader-feature-builder.h>
40 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
41 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
42 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
43 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
44 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
45 #include <dali-toolkit/internal/visuals/visual-url.h>
46 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
47 #include <dali-toolkit/public-api/visuals/visual-properties.h>
57 const int CUSTOM_PROPERTY_COUNT(7); // ltr, wrap, pixel area, atlas, pixalign, crop to mask, mask texture ratio
60 DALI_ENUM_TO_STRING_TABLE_BEGIN(FITTING_MODE)
61 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, SHRINK_TO_FIT)
62 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, SCALE_TO_FILL)
63 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, FIT_WIDTH)
64 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, FIT_HEIGHT)
65 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::FittingMode, DEFAULT)
66 DALI_ENUM_TO_STRING_TABLE_END(FITTING_MODE)
69 DALI_ENUM_TO_STRING_TABLE_BEGIN(SAMPLING_MODE)
70 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, BOX)
71 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, NEAREST)
72 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, LINEAR)
73 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, BOX_THEN_NEAREST)
74 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, BOX_THEN_LINEAR)
75 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, NO_FILTER)
76 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::SamplingMode, DONT_CARE)
77 DALI_ENUM_TO_STRING_TABLE_END(SAMPLING_MODE)
80 DALI_ENUM_TO_STRING_TABLE_BEGIN(WRAP_MODE)
81 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::WrapMode, DEFAULT)
82 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::WrapMode, CLAMP_TO_EDGE)
83 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::WrapMode, REPEAT)
84 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::WrapMode, MIRRORED_REPEAT)
85 DALI_ENUM_TO_STRING_TABLE_END(WRAP_MODE)
88 DALI_ENUM_TO_STRING_TABLE_BEGIN(LOAD_POLICY)
89 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::LoadPolicy, IMMEDIATE)
90 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::LoadPolicy, ATTACHED)
91 DALI_ENUM_TO_STRING_TABLE_END(LOAD_POLICY)
94 DALI_ENUM_TO_STRING_TABLE_BEGIN(RELEASE_POLICY)
95 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::ReleasePolicy, DETACHED)
96 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::ReleasePolicy, DESTROYED)
97 DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::ReleasePolicy, NEVER)
98 DALI_ENUM_TO_STRING_TABLE_END(RELEASE_POLICY)
100 const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
102 constexpr uint32_t TEXTURE_COUNT_FOR_GPU_ALPHA_MASK = 2u;
104 struct NameIndexMatch
106 const char* const name;
107 Property::Index index;
110 const NameIndexMatch NAME_INDEX_MATCH_TABLE[] =
112 {IMAGE_FITTING_MODE, Toolkit::ImageVisual::Property::FITTING_MODE},
113 {IMAGE_SAMPLING_MODE, Toolkit::ImageVisual::Property::SAMPLING_MODE},
114 {IMAGE_DESIRED_WIDTH, Toolkit::ImageVisual::Property::DESIRED_WIDTH},
115 {IMAGE_DESIRED_HEIGHT, Toolkit::ImageVisual::Property::DESIRED_HEIGHT},
116 {PIXEL_AREA_UNIFORM_NAME, Toolkit::ImageVisual::Property::PIXEL_AREA},
117 {IMAGE_WRAP_MODE_U, Toolkit::ImageVisual::Property::WRAP_MODE_U},
118 {IMAGE_WRAP_MODE_V, Toolkit::ImageVisual::Property::WRAP_MODE_V},
119 {SYNCHRONOUS_LOADING, Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING},
120 {IMAGE_ATLASING, Toolkit::ImageVisual::Property::ATLASING},
121 {ALPHA_MASK_URL, Toolkit::ImageVisual::Property::ALPHA_MASK_URL},
122 {MASK_CONTENT_SCALE_NAME, Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE},
123 {CROP_TO_MASK_NAME, Toolkit::ImageVisual::Property::CROP_TO_MASK},
124 {MASKING_TYPE_NAME, Toolkit::DevelImageVisual::Property::MASKING_TYPE},
125 {ENABLE_BROKEN_IMAGE, Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE},
126 {LOAD_POLICY_NAME, Toolkit::ImageVisual::Property::LOAD_POLICY},
127 {RELEASE_POLICY_NAME, Toolkit::ImageVisual::Property::RELEASE_POLICY},
128 {ORIENTATION_CORRECTION_NAME, Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION},
129 {FAST_TRACK_UPLOADING_NAME, Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING},
131 const int NAME_INDEX_MATCH_TABLE_SIZE = sizeof(NAME_INDEX_MATCH_TABLE)/sizeof(NAME_INDEX_MATCH_TABLE[0]);
133 Geometry CreateGeometry(VisualFactoryCache& factoryCache, ImageDimensions gridSize)
137 if(gridSize == ImageDimensions(1, 1))
139 geometry = factoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
142 geometry = VisualFactoryCache::CreateGridGeometry(gridSize);
148 } // unnamed namespace
150 ImageVisualPtr ImageVisual::New(VisualFactoryCache& factoryCache,
151 ImageVisualShaderFactory& shaderFactory,
152 const VisualUrl& imageUrl,
153 const Property::Map& properties,
154 ImageDimensions size,
155 FittingMode::Type fittingMode,
156 Dali::SamplingMode::Type samplingMode)
158 ImageVisualPtr imageVisualPtr(new ImageVisual(factoryCache, shaderFactory, imageUrl, size, fittingMode, samplingMode));
159 imageVisualPtr->SetProperties(properties);
160 imageVisualPtr->Initialize();
161 return imageVisualPtr;
164 ImageVisualPtr ImageVisual::New(VisualFactoryCache& factoryCache,
165 ImageVisualShaderFactory& shaderFactory,
166 const VisualUrl& imageUrl,
167 ImageDimensions size,
168 FittingMode::Type fittingMode,
169 Dali::SamplingMode::Type samplingMode)
171 ImageVisualPtr imageVisualPtr(new ImageVisual(factoryCache, shaderFactory, imageUrl, size, fittingMode, samplingMode));
172 imageVisualPtr->Initialize();
173 return imageVisualPtr;
176 ImageVisual::ImageVisual(VisualFactoryCache& factoryCache,
177 ImageVisualShaderFactory& shaderFactory,
178 const VisualUrl& imageUrl,
179 ImageDimensions size,
180 FittingMode::Type fittingMode,
181 Dali::SamplingMode::Type samplingMode)
182 : Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE),
183 mPixelArea(FULL_TEXTURE_RECT),
184 mPixelAreaIndex(Property::INVALID_INDEX),
189 mTextureId(TextureManager::INVALID_TEXTURE_ID),
191 mImageVisualShaderFactory(shaderFactory),
192 mFittingMode(fittingMode),
193 mSamplingMode(samplingMode),
194 mWrapModeU(WrapMode::DEFAULT),
195 mWrapModeV(WrapMode::DEFAULT),
196 mLoadPolicy(Toolkit::ImageVisual::LoadPolicy::ATTACHED),
197 mReleasePolicy(Toolkit::ImageVisual::ReleasePolicy::DETACHED),
198 mAtlasRect(0.0f, 0.0f, 0.0f, 0.0f),
199 mAtlasRectSize(0, 0),
200 mLoadState(TextureManager::LoadState::NOT_STARTED),
201 mAttemptAtlasing(false),
202 mOrientationCorrection(true),
203 mEnableBrokenImage(true)
205 EnablePreMultipliedAlpha(mFactoryCache.GetPreMultiplyOnLoad());
208 ImageVisual::~ImageVisual()
210 if(Stage::IsInstalled())
212 if(mImageUrl.IsValid())
214 // Decrease reference count of External Resources :
215 // EncodedImageBuffer or ExternalTextures.
216 // Ensure the stage is still valid before accessing texture manager.
217 if(mImageUrl.GetProtocolType() == VisualUrl::TEXTURE)
219 TextureManager& textureManager = mFactoryCache.GetTextureManager();
220 textureManager.RemoveExternalTexture(mImageUrl.GetUrl());
222 else if(mImageUrl.IsBufferResource())
224 TextureManager& textureManager = mFactoryCache.GetTextureManager();
225 textureManager.RemoveEncodedImageBuffer(mImageUrl.GetUrl());
229 // ImageVisual destroyed so remove texture unless ReleasePolicy is set to never release
230 if((mTextureId != TextureManager::INVALID_TEXTURE_ID) && (mReleasePolicy != Toolkit::ImageVisual::ReleasePolicy::NEVER))
235 ResetFastTrackLoadingTask();
239 void ImageVisual::DoSetProperties(const Property::Map& propertyMap)
241 // Url is already received in constructor
242 for(Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter)
244 KeyValuePair keyValue = propertyMap.GetKeyValue(iter);
245 if(keyValue.first.type == Property::Key::INDEX)
247 DoSetProperty(keyValue.first.indexKey, keyValue.second);
251 for(int i = 0; i < NAME_INDEX_MATCH_TABLE_SIZE; ++i)
253 if(keyValue.first == NAME_INDEX_MATCH_TABLE[i].name)
255 DoSetProperty(NAME_INDEX_MATCH_TABLE[i].index, keyValue.second);
261 // Load image immediately if LOAD_POLICY requires it
262 if(mLoadPolicy == Toolkit::ImageVisual::LoadPolicy::IMMEDIATE)
264 auto attemptAtlasing = AttemptAtlasing();
265 LoadTexture(attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection, TextureManager::ReloadPolicy::CACHED);
269 void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& value)
273 case Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING:
280 mImpl->mFlags |= Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
284 mImpl->mFlags &= ~Visual::Base::Impl::IS_SYNCHRONOUS_RESOURCE_LOADING;
289 DALI_LOG_ERROR("ImageVisual: synchronousLoading property has incorrect type\n");
294 case Toolkit::ImageVisual::Property::DESIRED_WIDTH:
296 int32_t desiredWidth = 0;
297 if(value.Get(desiredWidth))
299 mDesiredSize.SetWidth(desiredWidth);
303 DALI_LOG_ERROR("ImageVisual: desiredWidth property has incorrect type\n");
308 case Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
310 int32_t desiredHeight = 0;
311 if(value.Get(desiredHeight))
313 mDesiredSize.SetHeight(desiredHeight);
317 DALI_LOG_ERROR("ImageVisual: desiredHeight property has incorrect type\n");
322 case Toolkit::ImageVisual::Property::FITTING_MODE:
325 Scripting::GetEnumerationProperty(value, FITTING_MODE_TABLE, FITTING_MODE_TABLE_COUNT, fittingMode);
326 mFittingMode = Dali::FittingMode::Type(fittingMode);
330 case Toolkit::ImageVisual::Property::SAMPLING_MODE:
332 int samplingMode = 0;
333 Scripting::GetEnumerationProperty(value, SAMPLING_MODE_TABLE, SAMPLING_MODE_TABLE_COUNT, samplingMode);
334 mSamplingMode = Dali::SamplingMode::Type(samplingMode);
338 case Toolkit::ImageVisual::Property::PIXEL_AREA:
340 value.Get(mPixelArea);
342 if(DALI_UNLIKELY(mImpl->mRenderer))
344 // Unusual case. SetProperty called after OnInitialize().
345 // Assume that DoAction call UPDATE_PROPERTY.
346 mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
351 case Toolkit::ImageVisual::Property::WRAP_MODE_U:
354 Scripting::GetEnumerationProperty(value, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, wrapMode);
355 mWrapModeU = Dali::WrapMode::Type(wrapMode);
359 case Toolkit::ImageVisual::Property::WRAP_MODE_V:
362 Scripting::GetEnumerationProperty(value, WRAP_MODE_TABLE, WRAP_MODE_TABLE_COUNT, wrapMode);
363 mWrapModeV = Dali::WrapMode::Type(wrapMode);
367 case Toolkit::ImageVisual::Property::ATLASING:
369 value.Get(mAttemptAtlasing);
373 case Toolkit::ImageVisual::Property::ALPHA_MASK_URL:
375 std::string alphaUrl = "";
376 if(value.Get(alphaUrl))
379 mMaskingData->mAlphaMaskUrl = alphaUrl;
384 case Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE:
390 mMaskingData->mContentScaleFactor = scale;
395 case Toolkit::ImageVisual::Property::CROP_TO_MASK:
401 mMaskingData->mCropToMask = crop;
406 case Toolkit::DevelImageVisual::Property::MASKING_TYPE:
409 if(value.Get(maskingType))
412 if(mImageUrl.IsValid() && mImageUrl.GetProtocolType() == VisualUrl::TEXTURE)
414 // For external textures, only gpu masking is available.
415 // Therefore, MASKING_TYPE is set to MASKING_ON_RENDERING forcelly.
416 mMaskingData->mPreappliedMasking = false;
420 mMaskingData->mPreappliedMasking = (Toolkit::DevelImageVisual::MaskingType::Type(maskingType) == Toolkit::DevelImageVisual::MaskingType::MASKING_ON_LOADING);
426 case Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE:
428 value.Get(mEnableBrokenImage);
432 case Toolkit::ImageVisual::Property::RELEASE_POLICY:
434 int releasePolicy = 0;
435 Scripting::GetEnumerationProperty(value, RELEASE_POLICY_TABLE, RELEASE_POLICY_TABLE_COUNT, releasePolicy);
436 mReleasePolicy = Toolkit::ImageVisual::ReleasePolicy::Type(releasePolicy);
440 case Toolkit::ImageVisual::Property::LOAD_POLICY:
443 Scripting::GetEnumerationProperty(value, LOAD_POLICY_TABLE, LOAD_POLICY_TABLE_COUNT, loadPolicy);
444 mLoadPolicy = Toolkit::ImageVisual::LoadPolicy::Type(loadPolicy);
447 case Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION:
449 value.Get(mOrientationCorrection);
453 case Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING:
455 value.Get(mUseFastTrackUploading);
461 void ImageVisual::AllocateMaskData()
465 mMaskingData.reset(new TextureManager::MaskingData());
466 if(mImageUrl.IsValid() && mImageUrl.GetProtocolType() == VisualUrl::TEXTURE)
468 mMaskingData->mPreappliedMasking = false;
473 void ImageVisual::GetNaturalSize(Vector2& naturalSize)
475 if(mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0)
477 naturalSize.x = mDesiredSize.GetWidth();
478 naturalSize.y = mDesiredSize.GetHeight();
481 else if(mImpl->mRenderer) // Check if we have a loaded image
483 if(mImpl->mFlags & Visual::Base::Impl::IS_ATLASING_APPLIED)
485 naturalSize.x = mAtlasRectSize.GetWidth();
486 naturalSize.y = mAtlasRectSize.GetHeight();
490 auto textureSet = mImpl->mRenderer.GetTextures();
491 if(textureSet && textureSet.GetTextureCount())
493 if(mTextureSize != Vector2::ZERO)
495 naturalSize = mTextureSize;
501 if(mMaskingData != NULL && mMaskingData->mAlphaMaskUrl.IsValid() &&
502 mMaskingData->mCropToMask)
504 ImageDimensions dimensions = Dali::GetClosestImageSize(mMaskingData->mAlphaMaskUrl.GetUrl());
505 if(dimensions != ImageDimensions(0, 0))
507 naturalSize.x = dimensions.GetWidth();
508 naturalSize.y = dimensions.GetHeight();
512 else if(mImageUrl.IsValid())
514 if(mImageUrl.GetProtocolType() == VisualUrl::LOCAL)
516 ImageDimensions dimensions = Dali::GetClosestImageSize(mImageUrl.GetUrl());
518 if(dimensions != ImageDimensions(0, 0))
520 naturalSize.x = dimensions.GetWidth();
521 naturalSize.y = dimensions.GetHeight();
525 Actor actor = mPlacementActor.GetHandle();
526 Vector2 imageSize = Vector2::ZERO;
529 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
533 imageSize = mPlacementActorSize;
536 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
537 Texture brokenImage = mImpl->mRenderer.GetTextures().GetTexture(0);
538 naturalSize.x = brokenImage.GetWidth();
539 naturalSize.y = brokenImage.GetWidth();
544 naturalSize = Vector2::ZERO;
547 void ImageVisual::OnInitialize()
552 if(mImpl->mCustomShader)
554 geometry = CreateGeometry(mFactoryCache, mImpl->mCustomShader->mGridSize);
556 else // Get any geometry associated with the texture
558 TextureManager& textureManager = mFactoryCache.GetTextureManager();
560 uint32_t firstElementCount{0u};
561 uint32_t secondElementCount{0u};
562 geometry = textureManager.GetRenderGeometry(mTextureId, firstElementCount, secondElementCount);
564 if(!firstElementCount && !secondElementCount) // Otherwise use quad
566 geometry = CreateGeometry(mFactoryCache, ImageDimensions(1, 1));
570 // Increase reference count of External Resources :
571 // EncodedImageBuffer or ExternalTextures.
572 // Reference count will be decreased at destructor of the visual.
573 if(mImageUrl.IsValid() && (mImageUrl.IsBufferResource() || mImageUrl.GetProtocolType() == VisualUrl::TEXTURE))
575 TextureManager& textureManager = mFactoryCache.GetTextureManager();
576 textureManager.UseExternalResource(mImageUrl.GetUrl());
579 Shader shader = GenerateShader();
581 // Create the renderer
582 mImpl->mRenderer = DecoratedVisualRenderer::New(geometry, shader);
583 mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
585 //Register transform properties
586 mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
588 EnablePreMultipliedAlpha(IsPreMultipliedAlphaEnabled());
592 mImpl->mRenderer.RegisterProperty(CROP_TO_MASK_NAME, static_cast<float>(mMaskingData->mCropToMask));
596 void ImageVisual::LoadTexture(bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection, TextureManager::ReloadPolicy forceReload)
598 TextureManager& textureManager = mFactoryCache.GetTextureManager();
600 ImageAtlasManagerPtr atlasManager = nullptr;
601 AtlasUploadObserver* atlasUploadObserver = nullptr;
602 auto textureObserver = this;
606 atlasManager = mFactoryCache.GetAtlasManager();
607 atlasUploadObserver = this;
610 auto preMultiplyOnLoad = IsPreMultipliedAlphaEnabled() && !mImpl->mCustomShader
611 ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
612 : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
614 bool synchronousLoading = IsSynchronousLoadingRequired();
615 bool loadingStatus = false;
617 // Remove previous loading task.
618 ResetFastTrackLoadingTask();
620 // Rare case. If someone call LoadTexture during fast track loading task running, (Ex : Action::RELOAD)
621 // we should remove previously added renderer now.
624 Actor actor = mPlacementActor.GetHandle();
627 actor.RemoveRenderer(mImpl->mRenderer);
628 mRendererAdded = false;
633 * @brief Check whether FastTrackUploading is avaliable or not.
634 * @return True if we can use fast track uploading feature. False otherwise.
636 auto IsFastTrackUploadingAvailable = [&]() {
637 if(mUseFastTrackUploading &&
638 mLoadPolicy == Toolkit::ImageVisual::LoadPolicy::ATTACHED &&
639 mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED &&
640 forceReload == TextureManager::ReloadPolicy::CACHED &&
641 (mImageUrl.GetProtocolType() == VisualUrl::LOCAL || mImageUrl.GetProtocolType() == VisualUrl::REMOTE) &&
642 !synchronousLoading &&
644 !mImpl->mCustomShader &&
645 !(mMaskingData && mMaskingData->mAlphaMaskUrl.IsValid()))
649 else if(mUseFastTrackUploading)
651 DALI_LOG_DEBUG_INFO("FastTrack : Fail to load fast track. mUrl : [%s]%s%s%s%s%s%s%s%s\n",
652 mImageUrl.GetUrl().c_str(),
653 (mLoadPolicy != Toolkit::ImageVisual::LoadPolicy::ATTACHED) ? "/ mLoadPolicy != ATTACHED" : "",
654 (mReleasePolicy != Toolkit::ImageVisual::ReleasePolicy::DETACHED) ? "/ mReleasePolicy != DETACHED" : "",
655 (forceReload != TextureManager::ReloadPolicy::CACHED) ? "/ forceReload != CACHED" : "",
656 (!(mImageUrl.GetProtocolType() == VisualUrl::LOCAL || mImageUrl.GetProtocolType() == VisualUrl::REMOTE)) ? "/ url is not image" : "",
657 (synchronousLoading) ? "/ synchronousLoading" : "",
658 (atlasing) ? "/ atlasing" : "",
659 (mImpl->mCustomShader) ? "/ use customs shader" : "",
660 (mMaskingData && mMaskingData->mAlphaMaskUrl.IsValid()) ? "/ use masking url" : "");
665 if(IsFastTrackUploadingAvailable())
667 // Enable PremultipliedAlpha first.
668 EnablePreMultipliedAlpha(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
670 // Set new TextureSet with fast track loading task
671 mFastTrackLoadingTask = new FastTrackLoadingTask(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mOrientationCorrection, preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF, mFactoryCache.GetLoadYuvPlanes(), MakeCallback(this, &ImageVisual::FastLoadComplete));
673 TextureSet textureSet = TextureSet::New();
674 if(!mFastTrackLoadingTask->mLoadPlanesAvaliable)
676 DALI_ASSERT_ALWAYS(mFastTrackLoadingTask->mTextures.size() >= 1u);
677 textureSet.SetTexture(0u, mFastTrackLoadingTask->mTextures[0]);
681 DALI_ASSERT_ALWAYS(mFastTrackLoadingTask->mTextures.size() >= 3u);
682 textureSet.SetTexture(0u, mFastTrackLoadingTask->mTextures[0]);
683 textureSet.SetTexture(1u, mFastTrackLoadingTask->mTextures[1]);
684 textureSet.SetTexture(2u, mFastTrackLoadingTask->mTextures[2]);
686 // We cannot determine what kind of shader will be used.
687 // Just use unified shader, and then change shader after load completed.
688 mNeedUnifiedYuvAndRgb = true;
691 mImpl->mRenderer.SetTextures(textureSet);
693 Dali::AsyncTaskManager::Get().AddTask(mFastTrackLoadingTask);
695 mLoadState = TextureManager::LoadState::LOADING;
699 textures = textureManager.LoadTexture(mImageUrl, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mTextureId, atlasRect, mAtlasRectSize, atlasing, loadingStatus, textureObserver, atlasUploadObserver, atlasManager, mOrientationCorrection, forceReload, preMultiplyOnLoad);
706 mLoadState = TextureManager::LoadState::LOADING;
710 mLoadState = TextureManager::LoadState::LOAD_FINISHED;
713 EnablePreMultipliedAlpha(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
716 Sampler sampler = Sampler::New();
717 sampler.SetWrapMode(mWrapModeU, mWrapModeV);
718 textures.SetSampler(0u, sampler);
721 else if(synchronousLoading)
723 // Synchronous loading is failed
724 mLoadState = TextureManager::LoadState::LOAD_FAILED;
727 if(atlasing) // Flag needs to be set before creating renderer
729 mImpl->mFlags |= Visual::Base::Impl::IS_ATLASING_APPLIED;
733 mImpl->mFlags &= ~Visual::Base::Impl::IS_ATLASING_APPLIED;
737 bool ImageVisual::AttemptAtlasing()
739 return (!mImpl->mCustomShader && (mImageUrl.IsLocalResource() || mImageUrl.IsBufferResource()) && mAttemptAtlasing);
742 void ImageVisual::InitializeRenderer()
744 auto attemptAtlasing = AttemptAtlasing();
746 // Load Texture if mTextures is empty.
747 // mTextures is already set, the mTexture can be used to create Renderer.
748 // There are two cases mTextures is empty.
749 // 1. mTextureId == TextureManager::INVALID_TEXTURE_ID
750 // - Visual is on stage with LoadPolicy::ATTACHED
751 // 2. mTextureId != TextureManager::INVALID_TEXTURE_ID
752 // - If ReleasePolicy is DESTROYED, InitializeRenderer called every on stage called.
753 // - Then every resources those contained in Visual are Reset but mTextureId is remained when the Off stage time,
754 // - So, mTextures needed to be get from texture manager to created resources like mImpl->mRenderer.
757 if(mTextureId == TextureManager::INVALID_TEXTURE_ID)
759 LoadTexture(attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection, TextureManager::ReloadPolicy::CACHED);
763 mTextures = mFactoryCache.GetTextureManager().GetTextureSet(mTextureId);
764 if(!(mImpl->mFlags & Visual::Base::Impl::IS_ATLASING_APPLIED) && mTextures)
766 Sampler sampler = Sampler::New();
767 sampler.SetWrapMode(mWrapModeU, mWrapModeV);
768 mTextures.SetSampler(0u, sampler);
775 mImpl->mRenderer.SetTextures(mTextures);
776 ComputeTextureSize();
779 bool needToUpdateShader = DevelTexture::IsNative(mTextures.GetTexture(0));
781 if(mTextures.GetTextureCount() == 3)
783 if(mTextures.GetTexture(0).GetPixelFormat() == Pixel::L8 && mTextures.GetTexture(1).GetPixelFormat() == Pixel::CHROMINANCE_U && mTextures.GetTexture(2).GetPixelFormat() == Pixel::CHROMINANCE_V)
785 mNeedYuvToRgb = true;
786 needToUpdateShader = true;
790 if(needToUpdateShader)
794 mTextures.Reset(); // Visual should not keep a handle to the texture after this point.
797 if(attemptAtlasing) // the texture is packed inside atlas
799 mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, mAtlasRect);
801 bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
803 if(!defaultWrapMode) // custom wrap mode
805 Vector2 wrapMode(mWrapModeU - WrapMode::CLAMP_TO_EDGE, mWrapModeV - WrapMode::CLAMP_TO_EDGE);
806 wrapMode.Clamp(Vector2::ZERO, Vector2(2.f, 2.f));
807 mImpl->mRenderer.RegisterProperty(WRAP_MODE_UNIFORM_NAME, wrapMode);
812 void ImageVisual::DoSetOnScene(Actor& actor)
814 if(mImageUrl.IsValid())
816 InitializeRenderer();
819 if(!mImpl->mRenderer)
824 mPlacementActor = actor;
826 if(mPixelArea != FULL_TEXTURE_RECT)
828 mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
831 if(mLoadState == TextureManager::LoadState::LOAD_FINISHED)
833 actor.AddRenderer(mImpl->mRenderer);
834 mRendererAdded = true;
835 mPlacementActor.Reset();
837 // Image loaded and ready to display
838 ResourceReady(Toolkit::Visual::ResourceStatus::READY);
840 else if(mLoadState == TextureManager::LoadState::LOAD_FAILED)
843 ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
847 if(mFastTrackLoadingTask)
849 actor.AddRenderer(mImpl->mRenderer);
850 mRendererAdded = true;
855 void ImageVisual::DoSetOffScene(Actor& actor)
857 // Visual::Base::SetOffScene only calls DoSetOffScene if mRenderer exists (is on onstage)
859 // Image release is dependent on the ReleasePolicy, renderer is removed.
860 actor.RemoveRenderer(mImpl->mRenderer);
861 mRendererAdded = false;
863 if(mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED)
868 mPlacementActor.Reset();
871 void ImageVisual::DoCreatePropertyMap(Property::Map& map) const
874 map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
876 bool sync = IsSynchronousLoadingRequired();
877 map.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, sync);
878 if(mImageUrl.IsValid())
880 map.Insert(Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl());
881 map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
882 map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
885 map.Insert(Toolkit::ImageVisual::Property::FITTING_MODE, mFittingMode);
886 map.Insert(Toolkit::ImageVisual::Property::SAMPLING_MODE, mSamplingMode);
888 if(mImpl->mRenderer && mPixelAreaIndex != Property::INVALID_INDEX)
890 // Update values from Renderer
891 Vector4 pixelArea = mImpl->mRenderer.GetProperty<Vector4>(mPixelAreaIndex);
892 map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, pixelArea);
896 map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea);
899 map.Insert(Toolkit::ImageVisual::Property::WRAP_MODE_U, mWrapModeU);
900 map.Insert(Toolkit::ImageVisual::Property::WRAP_MODE_V, mWrapModeV);
902 map.Insert(Toolkit::ImageVisual::Property::ATLASING, mAttemptAtlasing);
904 if(mMaskingData != NULL)
906 map.Insert(Toolkit::ImageVisual::Property::ALPHA_MASK_URL, mMaskingData->mAlphaMaskUrl.GetUrl());
907 map.Insert(Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, mMaskingData->mContentScaleFactor);
908 map.Insert(Toolkit::ImageVisual::Property::CROP_TO_MASK, mMaskingData->mCropToMask);
909 map.Insert(Toolkit::DevelImageVisual::Property::MASKING_TYPE, mMaskingData->mPreappliedMasking ? DevelImageVisual::MaskingType::MASKING_ON_LOADING : DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
912 map.Insert(Toolkit::ImageVisual::Property::LOAD_POLICY, mLoadPolicy);
913 map.Insert(Toolkit::ImageVisual::Property::RELEASE_POLICY, mReleasePolicy);
914 map.Insert(Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION, mOrientationCorrection);
916 map.Insert(Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING, mUseFastTrackUploading);
919 void ImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
922 map.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
923 if(mImageUrl.IsValid())
925 map.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth());
926 map.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight());
930 void ImageVisual::OnDoAction(const Dali::Property::Index actionId, const Dali::Property::Value& attributes)
932 // Check if action is valid for this visual type and perform action if possible
936 case DevelImageVisual::Action::RELOAD:
938 auto attemptAtlasing = AttemptAtlasing();
939 LoadTexture(attemptAtlasing, mAtlasRect, mTextures, mOrientationCorrection, TextureManager::ReloadPolicy::FORCED);
945 void ImageVisual::OnSetTransform()
949 mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
953 void ImageVisual::UpdateShader()
957 Shader shader = GenerateShader();
958 mImpl->mRenderer.SetShader(shader);
962 // From existing atlas manager
963 void ImageVisual::UploadCompleted()
965 // Texture has been uploaded. If weak handle is holding a placement actor,
966 // it is the time to add the renderer to actor.
967 Actor actor = mPlacementActor.GetHandle();
970 mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, mAtlasRect);
971 actor.AddRenderer(mImpl->mRenderer);
972 mRendererAdded = true;
973 // reset the weak handle so that the renderer only get added to actor once
974 mPlacementActor.Reset();
978 ResourceReady(Toolkit::Visual::ResourceStatus::READY);
979 mLoadState = TextureManager::LoadState::LOAD_FINISHED;
982 // From FastTrackLoadingTask
983 void ImageVisual::FastLoadComplete(FastTrackLoadingTaskPtr task)
985 Toolkit::Visual::ResourceStatus resourceStatus;
987 DALI_ASSERT_ALWAYS(mFastTrackLoadingTask == task && "Task was not canceled successfully!");
988 DALI_ASSERT_ALWAYS(mRendererAdded && "Some FastTrack logic missed!");
990 Actor actor = mPlacementActor.GetHandle();
992 if(mFastTrackLoadingTask && mFastTrackLoadingTask->mLoadSuccess)
994 resourceStatus = Toolkit::Visual::ResourceStatus::READY;
995 mLoadState = TextureManager::LoadState::LOAD_FINISHED;
997 // Change premultiplied alpha flag after change renderer.
998 EnablePreMultipliedAlpha(mFastTrackLoadingTask->mPremultiplied);
1000 if(mFastTrackLoadingTask->mLoadPlanesAvaliable)
1002 if(mFastTrackLoadingTask->mPlanesLoaded)
1004 // Let we use regular yuv cases.
1005 mNeedYuvToRgb = true;
1009 // Let we use regular image cases.
1010 mNeedYuvToRgb = false;
1012 auto textureSet = mImpl->mRenderer.GetTextures();
1013 DALI_ASSERT_ALWAYS(textureSet && textureSet.GetTextureCount() > 0u && "Previous texture set must exist!");
1015 Dali::TextureSet newTextureSet = TextureSet::New();
1016 newTextureSet.SetTexture(0u, textureSet.GetTexture(0u));
1017 mImpl->mRenderer.SetTextures(newTextureSet);
1020 // We can specify what kind of shader we need to use now. Update shader.
1021 mNeedUnifiedYuvAndRgb = false;
1027 resourceStatus = Toolkit::Visual::ResourceStatus::FAILED;
1028 mLoadState = TextureManager::LoadState::LOAD_FAILED;
1030 // Change renderer as broken.
1034 mFastTrackLoadingTask.Reset();
1036 // Signal to observers ( control ) that resources are ready. Must be all resources.
1037 ResourceReady(resourceStatus);
1040 // From Texture Manager
1041 void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureInformation)
1043 Toolkit::Visual::ResourceStatus resourceStatus;
1044 if(mImpl->mRenderer)
1046 if(textureInformation.useAtlasing)
1048 mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, mAtlasRect);
1051 EnablePreMultipliedAlpha(textureInformation.preMultiplied);
1053 Actor actor = mPlacementActor.GetHandle();
1057 textureInformation.textureSet = mImpl->mRenderer.GetTextures();
1061 if(!textureInformation.useAtlasing)
1063 Sampler sampler = Sampler::New();
1064 sampler.SetWrapMode(mWrapModeU, mWrapModeV);
1065 textureInformation.textureSet.SetSampler(0u, sampler);
1068 mImpl->mRenderer.SetTextures(textureInformation.textureSet);
1069 ComputeTextureSize();
1072 if(textureInformation.textureSet.GetTextureCount() == 3)
1074 if(textureInformation.textureSet.GetTexture(0).GetPixelFormat() == Pixel::L8 && textureInformation.textureSet.GetTexture(1).GetPixelFormat() == Pixel::CHROMINANCE_U && textureInformation.textureSet.GetTexture(2).GetPixelFormat() == Pixel::CHROMINANCE_V)
1076 mNeedYuvToRgb = true;
1083 actor.AddRenderer(mImpl->mRenderer);
1084 mRendererAdded = true;
1085 // reset the weak handle so that the renderer only get added to actor once
1086 mPlacementActor.Reset();
1091 // Storing TextureSet needed when renderer staged.
1092 if(!mImpl->mRenderer)
1094 mTextures = textureInformation.textureSet;
1097 // Image loaded, set status regardless of staged status.
1100 resourceStatus = Toolkit::Visual::ResourceStatus::READY;
1101 mLoadState = TextureManager::LoadState::LOAD_FINISHED;
1105 resourceStatus = Toolkit::Visual::ResourceStatus::FAILED;
1106 mLoadState = TextureManager::LoadState::LOAD_FAILED;
1109 // use geometry if needed
1112 uint32_t firstElementCount{0u};
1113 uint32_t secondElementCount{0u};
1114 auto geometry = mFactoryCache.GetTextureManager().GetRenderGeometry(mTextureId, firstElementCount, secondElementCount);
1115 if(mImpl->mRenderer && geometry)
1117 mImpl->mRenderer.SetGeometry(geometry);
1118 Dali::DevelRenderer::DrawCommand drawCommand{};
1119 drawCommand.drawType = DevelRenderer::DrawType::INDEXED;
1121 if(firstElementCount)
1123 drawCommand.firstIndex = 0;
1124 drawCommand.elementCount = firstElementCount;
1125 drawCommand.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
1126 DevelRenderer::AddDrawCommand(mImpl->mRenderer, drawCommand);
1129 if(secondElementCount)
1131 drawCommand.firstIndex = firstElementCount;
1132 drawCommand.elementCount = secondElementCount;
1133 drawCommand.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
1134 DevelRenderer::AddDrawCommand(mImpl->mRenderer, drawCommand);
1139 // Signal to observers ( control ) that resources are ready. Must be all resources.
1140 ResourceReady(resourceStatus);
1143 void ImageVisual::RemoveTexture()
1145 if(mTextureId != TextureManager::INVALID_TEXTURE_ID)
1147 mFactoryCache.GetTextureManager().RequestRemove(mTextureId, this);
1148 mTextureId = TextureManager::INVALID_TEXTURE_ID;
1152 ResetFastTrackLoadingTask();
1154 Vector4 atlasRect(0.f, 0.f, 1.f, 1.f);
1155 Property::Index index = mImpl->mRenderer.GetPropertyIndex(ATLAS_RECT_UNIFORM_NAME);
1156 if(index != Property::INVALID_INDEX)
1158 Property::Value atlasRectValue = mImpl->mRenderer.GetProperty(index);
1159 atlasRectValue.Get(atlasRect);
1162 TextureSet textureSet = mImpl->mRenderer.GetTextures();
1164 if(index != Property::INVALID_INDEX)
1166 mFactoryCache.GetAtlasManager()->Remove(textureSet, atlasRect);
1171 void ImageVisual::ComputeTextureSize()
1173 if(mImpl->mRenderer)
1175 auto textureSet = mImpl->mRenderer.GetTextures();
1176 if(textureSet && textureSet.GetTextureCount())
1178 auto texture = textureSet.GetTexture(0);
1181 mTextureSize.x = texture.GetWidth();
1182 mTextureSize.y = texture.GetHeight();
1183 if(textureSet.GetTextureCount() > 1u && mMaskingData && !mMaskingData->mPreappliedMasking && mMaskingData->mCropToMask)
1185 Texture maskTexture = textureSet.GetTexture(1);
1188 mTextureSize.x = std::min(static_cast<uint32_t>(mTextureSize.x * mMaskingData->mContentScaleFactor), maskTexture.GetWidth());
1189 mTextureSize.y = std::min(static_cast<uint32_t>(mTextureSize.y * mMaskingData->mContentScaleFactor), maskTexture.GetHeight());
1197 Vector2 ImageVisual::ComputeMaskTextureRatio()
1199 Vector2 maskTextureRatio;
1200 if(mImpl->mRenderer)
1202 auto textureSet = mImpl->mRenderer.GetTextures();
1203 if(textureSet && textureSet.GetTextureCount())
1205 auto texture = textureSet.GetTexture(0);
1208 if(textureSet.GetTextureCount() > 1u && mMaskingData && !mMaskingData->mPreappliedMasking && mMaskingData->mCropToMask)
1210 Texture maskTexture = textureSet.GetTexture(1);
1213 float textureWidth = std::max(static_cast<float>(texture.GetWidth() * mMaskingData->mContentScaleFactor), Dali::Math::MACHINE_EPSILON_1);
1214 float textureHeight = std::max(static_cast<float>(texture.GetHeight() * mMaskingData->mContentScaleFactor), Dali::Math::MACHINE_EPSILON_1);
1215 maskTextureRatio = Vector2(std::min(static_cast<float>(maskTexture.GetWidth()), textureWidth) / textureWidth,
1216 std::min(static_cast<float>(maskTexture.GetHeight()), textureHeight) / textureHeight);
1222 return maskTextureRatio;
1225 Shader ImageVisual::GenerateShader() const
1229 const bool useStandardShader = !mImpl->mCustomShader;
1230 const bool useNativeImage = (mTextures && DevelTexture::IsNative(mTextures.GetTexture(0)));
1232 if(useStandardShader)
1234 bool requiredAlphaMaskingOnRendering = (mMaskingData && !mMaskingData->mMaskImageLoadingFailed) ? !mMaskingData->mPreappliedMasking : false;
1235 // Create and cache the standard shader
1236 shader = mImageVisualShaderFactory.GetShader(
1238 ImageVisualShaderFeatureBuilder()
1239 .EnableTextureAtlas(mImpl->mFlags & Visual::Base::Impl::IS_ATLASING_APPLIED && !useNativeImage)
1240 .ApplyDefaultTextureWrapMode(mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE)
1241 .EnableRoundedCorner(IsRoundedCornerRequired())
1242 .EnableBorderline(IsBorderlineRequired())
1243 .SetTextureForFragmentShaderCheck(useNativeImage ? mTextures.GetTexture(0) : Dali::Texture())
1244 .EnableAlphaMaskingOnRendering(requiredAlphaMaskingOnRendering)
1245 .EnableYuvToRgb(mNeedYuvToRgb, mNeedUnifiedYuvAndRgb));
1249 bool usesWholeTexture = true;
1250 std::string_view vertexShaderView;
1251 std::string_view fragmentShaderView;
1253 if(mImpl->mCustomShader && !mImpl->mCustomShader->mVertexShader.empty())
1255 vertexShaderView = mImpl->mCustomShader->mVertexShader;
1256 usesWholeTexture = false; // Impossible to tell.
1260 vertexShaderView = mImageVisualShaderFactory.GetVertexShaderSource();
1263 if(mImpl->mCustomShader && !mImpl->mCustomShader->mFragmentShader.empty())
1265 fragmentShaderView = mImpl->mCustomShader->mFragmentShader;
1269 fragmentShaderView = mImageVisualShaderFactory.GetFragmentShaderSource();
1272 // If the texture is native, we may need to change prefix and sampler in
1273 // the fragment shader
1276 bool modifiedFragmentShader = false;
1277 Texture nativeTexture = mTextures.GetTexture(0);
1278 std::string fragmentShaderString = std::string(fragmentShaderView);
1280 modifiedFragmentShader = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragmentShaderString);
1281 if(modifiedFragmentShader)
1283 fragmentShaderView = fragmentShaderString;
1286 // Create shader here cause fragmentShaderString scope issue
1287 shader = Shader::New(vertexShaderView, fragmentShaderView, mImpl->mCustomShader->mHints);
1291 shader = Shader::New(vertexShaderView, fragmentShaderView, mImpl->mCustomShader->mHints);
1294 if(usesWholeTexture)
1296 shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT);
1303 Dali::Property ImageVisual::OnGetPropertyObject(Dali::Property::Key key)
1305 if((key.type == Property::Key::INDEX && key.indexKey == Toolkit::ImageVisual::Property::PIXEL_AREA) || (key.type == Property::Key::STRING && key.stringKey == PIXEL_AREA_UNIFORM_NAME))
1307 if(DALI_LIKELY(mImpl->mRenderer))
1309 if(mPixelAreaIndex == Property::INVALID_INDEX)
1311 mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
1313 return Dali::Property(mImpl->mRenderer, mPixelAreaIndex);
1318 return Dali::Property(handle, Property::INVALID_INDEX);
1321 void ImageVisual::CheckMaskTexture()
1323 if(mMaskingData && !mMaskingData->mPreappliedMasking)
1325 bool maskLoadFailed = true;
1326 TextureSet textures = mImpl->mRenderer.GetTextures();
1327 if(textures && textures.GetTextureCount() >= TEXTURE_COUNT_FOR_GPU_ALPHA_MASK)
1329 if(mMaskingData->mCropToMask)
1331 mImpl->mRenderer.RegisterProperty(MASK_TEXTURE_RATIO_NAME, ComputeMaskTextureRatio());
1333 maskLoadFailed = false;
1336 if(mMaskingData->mMaskImageLoadingFailed != maskLoadFailed)
1338 mMaskingData->mMaskImageLoadingFailed = maskLoadFailed;
1344 void ImageVisual::ResetRenderer()
1346 RemoveTexture(); // If INVALID_TEXTURE_ID then removal will be attempted on atlas
1347 mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING;
1349 TextureSet textureSet = TextureSet::New();
1350 mImpl->mRenderer.SetTextures(textureSet);
1351 ComputeTextureSize();
1353 mLoadState = TextureManager::LoadState::NOT_STARTED;
1356 void ImageVisual::ShowBrokenImage()
1358 if(mEnableBrokenImage)
1360 Actor actor = mPlacementActor.GetHandle();
1362 Vector2 imageSize = Vector2::ZERO;
1365 imageSize = actor.GetProperty(Actor::Property::SIZE).Get<Vector2>();
1366 mPlacementActorSize = imageSize;
1370 actor.RemoveRenderer(mImpl->mRenderer);
1371 mRendererAdded = false;
1375 mFactoryCache.UpdateBrokenImageRenderer(mImpl->mRenderer, imageSize);
1378 actor.AddRenderer(mImpl->mRenderer);
1379 mRendererAdded = true;
1380 mPlacementActor.Reset();
1387 Actor actor = mPlacementActor.GetHandle();
1390 actor.RemoveRenderer(mImpl->mRenderer);
1391 mRendererAdded = false;
1398 void ImageVisual::ResetFastTrackLoadingTask()
1400 if(mFastTrackLoadingTask)
1402 Dali::AsyncTaskManager::Get().RemoveTask(mFastTrackLoadingTask);
1403 mFastTrackLoadingTask.Reset();
1407 } // namespace Internal
1409 } // namespace Toolkit