X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Fvisuals%2Fimage%2Fimage-visual.cpp;h=c190f0025b1dab86a56893f90a40b719921aee2c;hb=f5cd78ba46bbf1c159fa55d3693cdfafea88cb45;hp=2f0e800cd5aa88a372f8b8d27c8bcfeb626b16f6;hpb=7b673940d81536f1c7c1cdec818da110899b47a0;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 2f0e800..c190f00 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -100,6 +101,35 @@ const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); constexpr uint32_t TEXTURE_COUNT_FOR_GPU_ALPHA_MASK = 2u; +struct NameIndexMatch +{ + const char* const name; + Property::Index index; +}; + +const NameIndexMatch NAME_INDEX_MATCH_TABLE[] = + { + {IMAGE_FITTING_MODE, Toolkit::ImageVisual::Property::FITTING_MODE}, + {IMAGE_SAMPLING_MODE, Toolkit::ImageVisual::Property::SAMPLING_MODE}, + {IMAGE_DESIRED_WIDTH, Toolkit::ImageVisual::Property::DESIRED_WIDTH}, + {IMAGE_DESIRED_HEIGHT, Toolkit::ImageVisual::Property::DESIRED_HEIGHT}, + {PIXEL_AREA_UNIFORM_NAME, Toolkit::ImageVisual::Property::PIXEL_AREA}, + {IMAGE_WRAP_MODE_U, Toolkit::ImageVisual::Property::WRAP_MODE_U}, + {IMAGE_WRAP_MODE_V, Toolkit::ImageVisual::Property::WRAP_MODE_V}, + {SYNCHRONOUS_LOADING, Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING}, + {IMAGE_ATLASING, Toolkit::ImageVisual::Property::ATLASING}, + {ALPHA_MASK_URL, Toolkit::ImageVisual::Property::ALPHA_MASK_URL}, + {MASK_CONTENT_SCALE_NAME, Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE}, + {CROP_TO_MASK_NAME, Toolkit::ImageVisual::Property::CROP_TO_MASK}, + {MASKING_TYPE_NAME, Toolkit::DevelImageVisual::Property::MASKING_TYPE}, + {ENABLE_BROKEN_IMAGE, Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE}, + {LOAD_POLICY_NAME, Toolkit::ImageVisual::Property::LOAD_POLICY}, + {RELEASE_POLICY_NAME, Toolkit::ImageVisual::Property::RELEASE_POLICY}, + {ORIENTATION_CORRECTION_NAME, Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION}, + {FAST_TRACK_UPLOADING_NAME, Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING}, +}; +const int NAME_INDEX_MATCH_TABLE_SIZE = sizeof(NAME_INDEX_MATCH_TABLE) / sizeof(NAME_INDEX_MATCH_TABLE[0]); + Geometry CreateGeometry(VisualFactoryCache& factoryCache, ImageDimensions gridSize) { Geometry geometry; @@ -152,6 +182,7 @@ ImageVisual::ImageVisual(VisualFactoryCache& factoryCache, Dali::SamplingMode::Type samplingMode) : Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE), mPixelArea(FULL_TEXTURE_RECT), + mPixelAreaIndex(Property::INVALID_INDEX), mPlacementActor(), mImageUrl(imageUrl), mMaskingData(), @@ -218,77 +249,13 @@ void ImageVisual::DoSetProperties(const Property::Map& propertyMap) } else { - if(keyValue.first == IMAGE_FITTING_MODE) - { - DoSetProperty(Toolkit::ImageVisual::Property::FITTING_MODE, keyValue.second); - } - else if(keyValue.first == IMAGE_SAMPLING_MODE) - { - DoSetProperty(Toolkit::ImageVisual::Property::SAMPLING_MODE, keyValue.second); - } - else if(keyValue.first == IMAGE_DESIRED_WIDTH) - { - DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second); - } - else if(keyValue.first == IMAGE_DESIRED_HEIGHT) - { - DoSetProperty(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second); - } - else if(keyValue.first == PIXEL_AREA_UNIFORM_NAME) - { - DoSetProperty(Toolkit::ImageVisual::Property::PIXEL_AREA, keyValue.second); - } - else if(keyValue.first == IMAGE_WRAP_MODE_U) - { - DoSetProperty(Toolkit::ImageVisual::Property::WRAP_MODE_U, keyValue.second); - } - else if(keyValue.first == IMAGE_WRAP_MODE_V) - { - DoSetProperty(Toolkit::ImageVisual::Property::WRAP_MODE_V, keyValue.second); - } - else if(keyValue.first == SYNCHRONOUS_LOADING) - { - DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second); - } - else if(keyValue.first == IMAGE_ATLASING) - { - DoSetProperty(Toolkit::ImageVisual::Property::ATLASING, keyValue.second); - } - else if(keyValue.first == ALPHA_MASK_URL) - { - DoSetProperty(Toolkit::ImageVisual::Property::ALPHA_MASK_URL, keyValue.second); - } - else if(keyValue.first == MASK_CONTENT_SCALE_NAME) - { - DoSetProperty(Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, keyValue.second); - } - else if(keyValue.first == CROP_TO_MASK_NAME) - { - DoSetProperty(Toolkit::ImageVisual::Property::CROP_TO_MASK, keyValue.second); - } - else if(keyValue.first == MASKING_TYPE_NAME) - { - DoSetProperty(Toolkit::DevelImageVisual::Property::MASKING_TYPE, keyValue.second); - } - else if(keyValue.first == ENABLE_BROKEN_IMAGE) - { - DoSetProperty(Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE, keyValue.second); - } - else if(keyValue.first == LOAD_POLICY_NAME) + for(int i = 0; i < NAME_INDEX_MATCH_TABLE_SIZE; ++i) { - DoSetProperty(Toolkit::ImageVisual::Property::LOAD_POLICY, keyValue.second); - } - else if(keyValue.first == RELEASE_POLICY_NAME) - { - DoSetProperty(Toolkit::ImageVisual::Property::RELEASE_POLICY, keyValue.second); - } - else if(keyValue.first == ORIENTATION_CORRECTION_NAME) - { - DoSetProperty(Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION, keyValue.second); - } - else if(keyValue.first == FAST_TRACK_UPLOADING_NAME) - { - DoSetProperty(Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING, keyValue.second); + if(keyValue.first == NAME_INDEX_MATCH_TABLE[i].name) + { + DoSetProperty(NAME_INDEX_MATCH_TABLE[i].index, keyValue.second); + break; + } } } } @@ -372,6 +339,13 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va case Toolkit::ImageVisual::Property::PIXEL_AREA: { value.Get(mPixelArea); + + if(DALI_UNLIKELY(mImpl->mRenderer)) + { + // Unusual case. SetProperty called after OnInitialize(). + // Assume that DoAction call UPDATE_PROPERTY. + mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea); + } break; } @@ -444,7 +418,7 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va } else { - mMaskingData->mPreappliedMasking = Toolkit::DevelImageVisual::MaskingType::Type(maskingType) == Toolkit::DevelImageVisual::MaskingType::MASKING_ON_LOADING ? true : false; + mMaskingData->mPreappliedMasking = (Toolkit::DevelImageVisual::MaskingType::Type(maskingType) == Toolkit::DevelImageVisual::MaskingType::MASKING_ON_LOADING); } } break; @@ -452,11 +426,7 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va case Toolkit::DevelImageVisual::Property::ENABLE_BROKEN_IMAGE: { - bool enableBrokenImage(mEnableBrokenImage); - if(value.Get(enableBrokenImage)) - { - mEnableBrokenImage = enableBrokenImage; - } + value.Get(mEnableBrokenImage); break; } @@ -477,21 +447,13 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va } case Toolkit::ImageVisual::Property::ORIENTATION_CORRECTION: { - bool orientationCorrection(mOrientationCorrection); - if(value.Get(orientationCorrection)) - { - mOrientationCorrection = orientationCorrection; - } + value.Get(mOrientationCorrection); break; } case Toolkit::DevelImageVisual::Property::FAST_TRACK_UPLOADING: { - bool fastTrackUploading = false; - if(value.Get(fastTrackUploading)) - { - mUseFastTrackUploading = fastTrackUploading; - } + value.Get(mUseFastTrackUploading); break; } } @@ -718,9 +680,9 @@ void ImageVisual::LoadTexture(bool& atlasing, Vector4& atlasRect, TextureSet& te else { DALI_ASSERT_ALWAYS(mFastTrackLoadingTask->mTextures.size() >= 3u); - textureSet.SetTexture(0u, mFastTrackLoadingTask->mTextures[0]); - textureSet.SetTexture(1u, mFastTrackLoadingTask->mTextures[1]); textureSet.SetTexture(2u, mFastTrackLoadingTask->mTextures[2]); + textureSet.SetTexture(1u, mFastTrackLoadingTask->mTextures[1]); + textureSet.SetTexture(0u, mFastTrackLoadingTask->mTextures[0]); // We cannot determine what kind of shader will be used. // Just use unified shader, and then change shader after load completed. @@ -864,7 +826,7 @@ void ImageVisual::DoSetOnScene(Actor& actor) if(mPixelArea != FULL_TEXTURE_RECT) { - mImpl->mRenderer.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, mPixelArea); + mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea); } if(mLoadState == TextureManager::LoadState::LOAD_FINISHED) @@ -924,7 +886,17 @@ void ImageVisual::DoCreatePropertyMap(Property::Map& map) const map.Insert(Toolkit::ImageVisual::Property::FITTING_MODE, mFittingMode); map.Insert(Toolkit::ImageVisual::Property::SAMPLING_MODE, mSamplingMode); - map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea); + if(mImpl->mRenderer && mPixelAreaIndex != Property::INVALID_INDEX) + { + // Update values from Renderer + Vector4 pixelArea = mImpl->mRenderer.GetProperty(mPixelAreaIndex); + map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, pixelArea); + } + else + { + map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea); + } + map.Insert(Toolkit::ImageVisual::Property::WRAP_MODE_U, mWrapModeU); map.Insert(Toolkit::ImageVisual::Property::WRAP_MODE_V, mWrapModeV); @@ -1070,13 +1042,13 @@ void ImageVisual::FastLoadComplete(FastTrackLoadingTaskPtr task) void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureInformation) { Toolkit::Visual::ResourceStatus resourceStatus; + if(DALI_UNLIKELY(mImpl == nullptr)) + { + DALI_LOG_ERROR("Fatal error!! already destroyed object callback called! ImageVisual : %p, url : %s\n", this, mImageUrl.GetUrl().c_str()); + return; + } if(mImpl->mRenderer) { - if(textureInformation.useAtlasing) - { - mImpl->mRenderer.RegisterProperty(ATLAS_RECT_UNIFORM_NAME, mAtlasRect); - } - EnablePreMultipliedAlpha(textureInformation.preMultiplied); Actor actor = mPlacementActor.GetHandle(); @@ -1087,12 +1059,9 @@ void ImageVisual::LoadComplete(bool loadingSuccess, TextureInformation textureIn } else { - if(!textureInformation.useAtlasing) - { - Sampler sampler = Sampler::New(); - sampler.SetWrapMode(mWrapModeU, mWrapModeV); - textureInformation.textureSet.SetSampler(0u, sampler); - } + Sampler sampler = Sampler::New(); + sampler.SetWrapMode(mWrapModeU, mWrapModeV); + textureInformation.textureSet.SetSampler(0u, sampler); mImpl->mRenderer.SetTextures(textureInformation.textureSet); ComputeTextureSize(); @@ -1264,7 +1233,7 @@ Shader ImageVisual::GenerateShader() const // Create and cache the standard shader shader = mImageVisualShaderFactory.GetShader( mFactoryCache, - ImageVisualShaderFeature::FeatureBuilder() + ImageVisualShaderFeatureBuilder() .EnableTextureAtlas(mImpl->mFlags & Visual::Base::Impl::IS_ATLASING_APPLIED && !useNativeImage) .ApplyDefaultTextureWrapMode(mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE) .EnableRoundedCorner(IsRoundedCornerRequired()) @@ -1329,6 +1298,24 @@ Shader ImageVisual::GenerateShader() const return shader; } +Dali::Property ImageVisual::OnGetPropertyObject(Dali::Property::Key key) +{ + if((key.type == Property::Key::INDEX && key.indexKey == Toolkit::ImageVisual::Property::PIXEL_AREA) || (key.type == Property::Key::STRING && key.stringKey == PIXEL_AREA_UNIFORM_NAME)) + { + if(DALI_LIKELY(mImpl->mRenderer)) + { + if(mPixelAreaIndex == Property::INVALID_INDEX) + { + mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea); + } + return Dali::Property(mImpl->mRenderer, mPixelAreaIndex); + } + } + + Handle handle; + return Dali::Property(handle, Property::INVALID_INDEX); +} + void ImageVisual::CheckMaskTexture() { if(mMaskingData && !mMaskingData->mPreappliedMasking) @@ -1341,6 +1328,10 @@ void ImageVisual::CheckMaskTexture() { mImpl->mRenderer.RegisterProperty(MASK_TEXTURE_RATIO_NAME, ComputeMaskTextureRatio()); } + else + { + mImpl->mRenderer.RegisterProperty(MASK_TEXTURE_RATIO_NAME, Vector2::ONE); + } maskLoadFailed = false; }