[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / video-view / video-view-impl.cpp
1 /*
2  * Copyright (c) 2024 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "video-view-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/window-devel.h>
24 #include <dali/devel-api/rendering/texture-devel.h>
25 #include <dali/devel-api/scripting/scripting.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/adaptor-framework/native-image-source.h>
28 #include <dali/public-api/animation/constraint.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/public-api/object/type-registry.h>
31 #include <cstring>
32
33 // INTERNAL INCLUDES
34 #include <dali-toolkit/devel-api/controls/control-devel.h>
35 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
36 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
37 #include <dali-toolkit/public-api/controls/video-view/video-view.h>
38 #include <dali/integration-api/adaptor-framework/adaptor.h>
39
40 namespace Dali
41 {
42 namespace Toolkit
43 {
44 namespace Internal
45 {
46 namespace
47 {
48 BaseHandle Create()
49 {
50   return Toolkit::VideoView::New();
51 }
52
53 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::VideoView, Toolkit::Control, Create);
54
55 DALI_PROPERTY_REGISTRATION(Toolkit, VideoView, "video", MAP, VIDEO)
56 DALI_PROPERTY_REGISTRATION(Toolkit, VideoView, "looping", BOOLEAN, LOOPING)
57 DALI_PROPERTY_REGISTRATION(Toolkit, VideoView, "muted", BOOLEAN, MUTED)
58 DALI_PROPERTY_REGISTRATION(Toolkit, VideoView, "volume", MAP, VOLUME)
59 DALI_PROPERTY_REGISTRATION(Toolkit, VideoView, "underlay", BOOLEAN, UNDERLAY)
60 DALI_PROPERTY_REGISTRATION(Toolkit, VideoView, "playPosition", INTEGER, PLAY_POSITION)
61 DALI_PROPERTY_REGISTRATION(Toolkit, VideoView, "displayMode", INTEGER, DISPLAY_MODE)
62
63 DALI_SIGNAL_REGISTRATION(Toolkit, VideoView, "finished", FINISHED_SIGNAL)
64
65 DALI_ACTION_REGISTRATION(Toolkit, VideoView, "play", ACTION_VIDEOVIEW_PLAY)
66 DALI_ACTION_REGISTRATION(Toolkit, VideoView, "pause", ACTION_VIDEOVIEW_PAUSE)
67 DALI_ACTION_REGISTRATION(Toolkit, VideoView, "stop", ACTION_VIDEOVIEW_STOP)
68 DALI_ACTION_REGISTRATION(Toolkit, VideoView, "forward", ACTION_VIDEOVIEW_FORWARD)
69 DALI_ACTION_REGISTRATION(Toolkit, VideoView, "backward", ACTION_VIDEOVIEW_BACKWARD)
70
71 DALI_TYPE_REGISTRATION_END()
72
73 const char* const VOLUME_LEFT("volumeLeft");
74 const char* const VOLUME_RIGHT("volumeRight");
75
76 // 3.0 TC uses RENDERING_TARGET. It should be removed in next release
77 const char* const RENDERING_TARGET("renderingTarget");
78 const char* const WINDOW_SURFACE_TARGET("windowSurfaceTarget");
79 const char* const NATIVE_IMAGE_TARGET("nativeImageTarget");
80
81 const char* const CUSTOM_SHADER("shader");
82 const char* const CUSTOM_VERTEX_SHADER("vertexShader");
83 const char* const CUSTOM_FRAGMENT_SHADER("fragmentShader");
84 const char* const DEFAULT_SAMPLER_TYPE_NAME("sampler2D");
85 const char* const CUSTOM_SAMPLER_TYPE_NAME("samplerExternalOES");
86
87 const char* const IS_VIDEO_VIEW_PROPERTY_NAME = "isVideoView";
88
89 } // namespace
90
91 VideoView::VideoView(Dali::VideoSyncMode syncMode)
92 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
93   mCurrentVideoPlayPosition(0),
94   mFrameID(0),
95   mIsPlay(false),
96   mIsUnderlay(true),
97   mSyncMode(syncMode),
98   mSiblingOrder(0)
99 {
100 }
101
102 VideoView::~VideoView()
103 {
104 }
105
106 Toolkit::VideoView VideoView::New(VideoSyncMode syncMode)
107 {
108   VideoView*         impl   = new VideoView(syncMode);
109   Toolkit::VideoView handle = Toolkit::VideoView(*impl);
110
111   impl->mVideoPlayer = Dali::VideoPlayer::New(impl->Self(), syncMode);
112   impl->Initialize();
113   return handle;
114 }
115
116 void VideoView::OnInitialize()
117 {
118   Actor self = Self();
119   mVideoPlayer.FinishedSignal().Connect(this, &VideoView::EmitSignalFinish);
120
121   // Accessibility
122   self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::VIDEO);
123   self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
124
125   //update self property
126   self.RegisterProperty(IS_VIDEO_VIEW_PROPERTY_NAME, true, Property::READ_WRITE);
127 }
128
129 void VideoView::SetUrl(const std::string& url)
130 {
131   mUrl = url;
132   mPropertyMap.Clear();
133
134   mVideoPlayer.SetUrl(mUrl);
135 }
136
137 void VideoView::SetPropertyMap(Property::Map map)
138 {
139   mPropertyMap = map;
140
141   Property::Value* target = map.Find(RENDERING_TARGET);
142   std::string      targetType;
143
144   if(target && target->Get(targetType) && targetType == WINDOW_SURFACE_TARGET)
145   {
146     mIsUnderlay = true;
147     SetWindowSurfaceTarget();
148   }
149   else if(target && target->Get(targetType) && targetType == NATIVE_IMAGE_TARGET)
150   {
151     mIsUnderlay = false;
152     SetNativeImageTarget();
153   }
154
155   // Custom shader
156   Property::Value* shaderValue;
157   if(!map.Empty())
158   {
159     shaderValue = map.Find(CUSTOM_SHADER);
160
161     if(shaderValue)
162     {
163       Property::Map* shaderMap = shaderValue->GetMap();
164       if(shaderMap)
165       {
166         mEffectPropertyMap = *shaderMap;
167       }
168     }
169   }
170
171   if(mTextureRenderer && !mEffectPropertyMap.Empty())
172   {
173     Dali::Shader shader = CreateShader();
174     mTextureRenderer.SetShader(shader);
175   }
176
177   RelayoutRequest();
178 }
179
180 std::string VideoView::GetUrl()
181 {
182   return mUrl;
183 }
184
185 void VideoView::SetLooping(bool looping)
186 {
187   mVideoPlayer.SetLooping(looping);
188 }
189
190 bool VideoView::IsLooping()
191 {
192   return mVideoPlayer.IsLooping();
193 }
194
195 void VideoView::Play()
196 {
197   mVideoPlayer.Play();
198   mIsPlay = true;
199 }
200
201 void VideoView::Pause()
202 {
203   mVideoPlayer.Pause();
204   mIsPlay = false;
205 }
206
207 void VideoView::Stop()
208 {
209   mVideoPlayer.Stop();
210   mIsPlay = false;
211 }
212
213 void VideoView::Forward(int millisecond)
214 {
215   int curPos = mVideoPlayer.GetPlayPosition();
216
217   int nextPos = curPos + millisecond;
218
219   mVideoPlayer.SetPlayPosition(nextPos);
220 }
221
222 void VideoView::Backward(int millisecond)
223 {
224   int curPos = mVideoPlayer.GetPlayPosition();
225
226   int nextPos = curPos - millisecond;
227   nextPos     = (nextPos < 0) ? 0 : nextPos;
228
229   mVideoPlayer.SetPlayPosition(nextPos);
230 }
231
232 void VideoView::SetMute(bool mute)
233 {
234   mVideoPlayer.SetMute(mute);
235 }
236
237 bool VideoView::IsMuted()
238 {
239   return mVideoPlayer.IsMuted();
240 }
241
242 void VideoView::SetVolume(float left, float right)
243 {
244   mVideoPlayer.SetVolume(left, right);
245 }
246
247 void VideoView::GetVolume(float& left, float& right)
248 {
249   mVideoPlayer.GetVolume(left, right);
250 }
251
252 Dali::Toolkit::VideoView::VideoViewSignalType& VideoView::FinishedSignal()
253 {
254   return mFinishedSignal;
255 }
256
257 void VideoView::EmitSignalFinish()
258 {
259   if(!mFinishedSignal.Empty())
260   {
261     Dali::Toolkit::VideoView handle(GetOwner());
262     mFinishedSignal.Emit(handle);
263   }
264 }
265
266 bool VideoView::DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes)
267 {
268   bool ret = false;
269
270   Dali::BaseHandle   handle(object);
271   Toolkit::VideoView videoView = Toolkit::VideoView::DownCast(handle);
272
273   if(!videoView)
274   {
275     return ret;
276   }
277
278   VideoView& impl = GetImpl(videoView);
279
280   if(strcmp(actionName.c_str(), ACTION_VIDEOVIEW_PLAY) == 0)
281   {
282     impl.Play();
283     ret = true;
284   }
285   else if(strcmp(actionName.c_str(), ACTION_VIDEOVIEW_PAUSE) == 0)
286   {
287     impl.Pause();
288     ret = true;
289   }
290   else if(strcmp(actionName.c_str(), ACTION_VIDEOVIEW_STOP) == 0)
291   {
292     impl.Stop();
293     ret = true;
294   }
295   else if(strcmp(actionName.c_str(), ACTION_VIDEOVIEW_FORWARD) == 0)
296   {
297     int millisecond = 0;
298     if(attributes["videoForward"].Get(millisecond))
299     {
300       impl.Forward(millisecond);
301       ret = true;
302     }
303   }
304   else if(strcmp(actionName.c_str(), ACTION_VIDEOVIEW_BACKWARD) == 0)
305   {
306     int millisecond = 0;
307     if(attributes["videoBackward"].Get(millisecond))
308     {
309       impl.Backward(millisecond);
310       ret = true;
311     }
312   }
313
314   return ret;
315 }
316
317 bool VideoView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
318 {
319   Dali::BaseHandle handle(object);
320
321   bool               connected(true);
322   Toolkit::VideoView videoView = Toolkit::VideoView::DownCast(handle);
323
324   if(0 == strcmp(signalName.c_str(), FINISHED_SIGNAL))
325   {
326     videoView.FinishedSignal().Connect(tracker, functor);
327   }
328   else
329   {
330     // signalName does not match any signal
331     connected = false;
332   }
333
334   return connected;
335 }
336
337 void VideoView::SetPropertyInternal(Property::Index index, const Property::Value& value)
338 {
339   switch(index)
340   {
341     case Toolkit::VideoView::Property::VIDEO:
342     {
343       std::string   videoUrl;
344       Property::Map map;
345
346       if(value.Get(videoUrl))
347       {
348         SetUrl(videoUrl);
349       }
350       else if(value.Get(map))
351       {
352         SetPropertyMap(map);
353       }
354       break;
355     }
356     case Toolkit::VideoView::Property::LOOPING:
357     {
358       bool looping;
359       if(value.Get(looping))
360       {
361         SetLooping(looping);
362       }
363       break;
364     }
365     case Toolkit::VideoView::Property::MUTED:
366     {
367       bool mute;
368       if(value.Get(mute))
369       {
370         SetMute(mute);
371       }
372       break;
373     }
374     case Toolkit::VideoView::Property::VOLUME:
375     {
376       Property::Map map;
377       float         left, right;
378       if(value.Get(map))
379       {
380         Property::Value* volumeLeft  = map.Find(VOLUME_LEFT);
381         Property::Value* volumeRight = map.Find(VOLUME_RIGHT);
382         if(volumeLeft && volumeLeft->Get(left) && volumeRight && volumeRight->Get(right))
383         {
384           SetVolume(left, right);
385         }
386       }
387       break;
388     }
389     case Toolkit::VideoView::Property::UNDERLAY:
390     {
391       bool underlay;
392       if(value.Get(underlay))
393       {
394         SetUnderlay(underlay);
395       }
396       break;
397     }
398     case Toolkit::VideoView::Property::PLAY_POSITION:
399     {
400       int pos;
401       if(value.Get(pos))
402       {
403         SetPlayPosition(pos);
404       }
405       break;
406     }
407     case Toolkit::VideoView::Property::DISPLAY_MODE:
408     {
409       int mode;
410       if(value.Get(mode))
411       {
412         SetDisplayMode(mode);
413       }
414       break;
415     }
416   }
417 }
418
419 void VideoView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
420 {
421   Toolkit::VideoView videoView = Toolkit::VideoView::DownCast(Dali::BaseHandle(object));
422
423   if(videoView)
424   {
425     VideoView& impl = GetImpl(videoView);
426
427     impl.SetPropertyInternal(index, value);
428
429     if(index != Toolkit::VideoView::Property::UNDERLAY)
430     {
431       // Backup values.
432       // These values will be used when underlay mode is changed.
433       impl.mPropertyBackup[index] = value;
434     }
435   }
436 }
437
438 Property::Value VideoView::GetProperty(BaseObject* object, Property::Index propertyIndex)
439 {
440   Property::Value    value;
441   Toolkit::VideoView videoView = Toolkit::VideoView::DownCast(Dali::BaseHandle(object));
442
443   if(videoView)
444   {
445     VideoView& impl = GetImpl(videoView);
446
447     switch(propertyIndex)
448     {
449       case Toolkit::VideoView::Property::VIDEO:
450       {
451         if(!impl.mUrl.empty())
452         {
453           value = impl.mUrl;
454         }
455         else if(!impl.mPropertyMap.Empty())
456         {
457           value = impl.mPropertyMap;
458         }
459         break;
460       }
461       case Toolkit::VideoView::Property::LOOPING:
462       {
463         value = impl.IsLooping();
464         break;
465       }
466       case Toolkit::VideoView::Property::MUTED:
467       {
468         value = impl.IsMuted();
469         break;
470       }
471       case Toolkit::VideoView::Property::VOLUME:
472       {
473         Property::Map map;
474         float         left, right;
475
476         impl.GetVolume(left, right);
477         map.Insert(VOLUME_LEFT, left);
478         map.Insert(VOLUME_RIGHT, right);
479         value = map;
480         break;
481       }
482       case Toolkit::VideoView::Property::UNDERLAY:
483       {
484         value = impl.IsUnderlay();
485         break;
486       }
487       case Toolkit::VideoView::Property::PLAY_POSITION:
488       {
489         value = impl.GetPlayPosition();
490         break;
491       }
492       case Toolkit::VideoView::Property::DISPLAY_MODE:
493       {
494         value = impl.GetDisplayMode();
495         break;
496       }
497     }
498   }
499
500   return value;
501 }
502
503 void VideoView::SetDepthIndex(int depthIndex)
504 {
505   if(mTextureRenderer)
506   {
507     mTextureRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
508   }
509 }
510
511 void VideoView::OnSceneConnection(int depth)
512 {
513   Actor self = Self();
514   if(mIsUnderlay)
515   {
516     mSiblingOrder = self.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER);
517     DevelActor::ChildOrderChangedSignal(self.GetParent()).Connect(this, &VideoView::OnChildOrderChanged);
518     SetWindowSurfaceTarget();
519   }
520
521   Control::OnSceneConnection(depth);
522 }
523
524 void VideoView::OnSceneDisconnection()
525 {
526   Control::OnSceneDisconnection();
527 }
528
529 void VideoView::OnSizeSet(const Vector3& targetSize)
530 {
531   if(mIsUnderlay && mSyncMode == Dali::VideoSyncMode::ENABLED)
532   {
533     SetFrameRenderCallback();
534     mVideoPlayer.StartSynchronization();
535   }
536   Control::OnSizeSet(targetSize);
537 }
538
539 void VideoView::OnChildOrderChanged(Actor actor)
540 {
541   Actor self                = Self();
542   int   currentSiblingOrder = self.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER);
543   if(currentSiblingOrder != mSiblingOrder)
544   {
545     Actor parent = self.GetParent();
546     Actor child;
547     Actor upper;
548     Actor lower;
549
550     int numChildren = static_cast<int>(parent.GetChildCount());
551     for(int i = 0; i < numChildren; i++)
552     {
553       child = parent.GetChildAt(i);
554       if(!IsVideoView(child))
555       {
556         continue;
557       }
558
559       if(child == self)
560       {
561         continue;
562       }
563
564       if(i < currentSiblingOrder)
565       {
566         lower = child;
567       }
568       else if(i > currentSiblingOrder)
569       {
570         upper = child;
571         break;
572       }
573     }
574
575     if(lower)
576     {
577       Toolkit::VideoView lowerView = Toolkit::VideoView::DownCast(lower);
578       mVideoPlayer.RaiseAbove(GetImpl(lowerView).GetVideoPlayer());
579     }
580
581     if(upper)
582     {
583       Toolkit::VideoView upperView = Toolkit::VideoView::DownCast(upper);
584       mVideoPlayer.LowerBelow(GetImpl(upperView).GetVideoPlayer());
585     }
586     mSiblingOrder = currentSiblingOrder;
587   }
588 }
589
590 Vector3 VideoView::GetNaturalSize()
591 {
592   Vector3 size;
593   size.x = mVideoSize.GetWidth();
594   size.y = mVideoSize.GetHeight();
595
596   if(size.x > 0 && size.y > 0)
597   {
598     size.z = std::min(size.x, size.y);
599     return size;
600   }
601   else
602   {
603     return Control::GetNaturalSize();
604   }
605 }
606
607 void VideoView::SetWindowSurfaceTarget()
608 {
609   Actor self = Self();
610
611   if(!self.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
612   {
613     // When the control is off the stage, it does not have Window.
614     return;
615   }
616
617   Dali::Window window = DevelWindow::Get(self);
618   window.ResizeSignal().Connect(this, &VideoView::OnWindowResized);
619
620   int curPos = mVideoPlayer.GetPlayPosition();
621
622   if(mIsPlay)
623   {
624     mVideoPlayer.Pause();
625   }
626
627   mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
628   mSizeUpdateNotification     = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
629   mScaleUpdateNotification    = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
630   mPositionUpdateNotification.NotifySignal().Connect(this, &VideoView::UpdateDisplayArea);
631   mSizeUpdateNotification.NotifySignal().Connect(this, &VideoView::UpdateDisplayArea);
632   mScaleUpdateNotification.NotifySignal().Connect(this, &VideoView::UpdateDisplayArea);
633
634   if(mTextureRenderer)
635   {
636     self.RemoveRenderer(mTextureRenderer);
637   }
638
639   // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping)
640   mVideoPlayer.SetRenderingTarget(Dali::Adaptor::Get().GetNativeWindowHandle(self));
641
642   ApplyBackupProperties();
643
644   if(!mOverlayRenderer)
645   {
646     // For underlay rendering mode, video display area have to be transparent.
647     Geometry geometry = VisualFactoryCache::CreateQuadGeometry();
648     Shader   shader   = Shader::New(SHADER_VIDEO_VIEW_VERT, SHADER_VIDEO_VIEW_FRAG, Shader::Hint::NONE, "VIDEO_VIEW_OVERLAY");
649     mOverlayRenderer  = Renderer::New(geometry, shader);
650     mOverlayRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
651   }
652   Self().AddRenderer(mOverlayRenderer);
653
654   if(mIsPlay)
655   {
656     Play();
657   }
658
659   if(curPos > 0)
660   {
661     mVideoPlayer.SetPlayPosition(curPos);
662   }
663 }
664
665 void VideoView::SetNativeImageTarget()
666 {
667   if(mVideoPlayer.IsVideoTextureSupported() == false)
668   {
669     DALI_LOG_ERROR("Platform doesn't support decoded video frame images\n");
670     mIsUnderlay = true;
671     return;
672   }
673
674   if(mIsPlay)
675   {
676     mVideoPlayer.Pause();
677   }
678
679   Actor self(Self());
680
681   if(mOverlayRenderer)
682   {
683     self.RemoveRenderer(mOverlayRenderer);
684
685     mOverlayRenderer.Reset();
686   }
687
688   self.RemovePropertyNotification(mPositionUpdateNotification);
689   self.RemovePropertyNotification(mSizeUpdateNotification);
690   self.RemovePropertyNotification(mScaleUpdateNotification);
691
692   int curPos = mVideoPlayer.GetPlayPosition();
693
694   Any                        source;
695   Dali::NativeImageSourcePtr nativeImageSourcePtr = Dali::NativeImageSource::New(source);
696   mNativeTexture                                  = Dali::Texture::New(*nativeImageSourcePtr);
697
698   if(!mTextureRenderer)
699   {
700     Dali::Geometry   geometry   = VisualFactoryCache::CreateQuadGeometry();
701     Dali::Shader     shader     = CreateShader();
702     Dali::TextureSet textureSet = Dali::TextureSet::New();
703     textureSet.SetTexture(0u, mNativeTexture);
704
705     mTextureRenderer = Renderer::New(geometry, shader);
706     mTextureRenderer.SetTextures(textureSet);
707   }
708   else
709   {
710     Dali::TextureSet textureSet = mTextureRenderer.GetTextures();
711     textureSet.SetTexture(0u, mNativeTexture);
712   }
713   Self().AddRenderer(mTextureRenderer);
714
715   // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping)
716   mVideoPlayer.SetRenderingTarget(nativeImageSourcePtr);
717
718   ApplyBackupProperties();
719
720   if(mIsPlay)
721   {
722     Play();
723   }
724
725   if(curPos > 0)
726   {
727     mVideoPlayer.SetPlayPosition(curPos);
728   }
729 }
730
731 void VideoView::UpdateDisplayArea(Dali::PropertyNotification& source)
732 {
733   // If mSyncMode is enabled, Video player's size and poistion is updated in Video player's constraint.
734   // Because video view and player should be work syncronization.
735   if(!mIsUnderlay || mSyncMode == Dali::VideoSyncMode::ENABLED)
736   {
737     return;
738   }
739
740   Actor self(Self());
741
742   bool    positionUsesAnchorPoint = self.GetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT).Get<bool>();
743   Vector3 actorSize               = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
744   Vector3 anchorPointOffSet       = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
745
746   Vector2 screenPosition = self.GetProperty(Actor::Property::SCREEN_POSITION).Get<Vector2>();
747
748   mDisplayArea.x      = screenPosition.x - anchorPointOffSet.x;
749   mDisplayArea.y      = screenPosition.y - anchorPointOffSet.y;
750   mDisplayArea.width  = actorSize.x;
751   mDisplayArea.height = actorSize.y;
752
753   mVideoPlayer.SetDisplayArea(mDisplayArea);
754 }
755
756 void VideoView::SetUnderlay(bool set)
757 {
758   if(set != mIsUnderlay)
759   {
760     mIsUnderlay = set;
761
762     if(mIsUnderlay)
763     {
764       SetWindowSurfaceTarget();
765     }
766     else
767     {
768       SetNativeImageTarget();
769     }
770
771     RelayoutRequest();
772   }
773 }
774
775 bool VideoView::IsUnderlay()
776 {
777   return mIsUnderlay;
778 }
779
780 void VideoView::SetSWCodec(bool on)
781 {
782   // If setting SW or HW type is failed , video-view shows video by default codec type.
783   // The default codec type is selected by platform.
784   if(on)
785   {
786     mVideoPlayer.SetCodecType(Dali::VideoPlayerPlugin::CodecType::SW);
787   }
788   else
789   {
790     mVideoPlayer.SetCodecType(Dali::VideoPlayerPlugin::CodecType::HW);
791   }
792 }
793
794 int VideoView::GetPlayPosition()
795 {
796   return mVideoPlayer.GetPlayPosition();
797 }
798
799 void VideoView::SetPlayPosition(int pos)
800 {
801   mVideoPlayer.SetPlayPosition(pos);
802 }
803
804 void VideoView::SetDisplayMode(int mode)
805 {
806   mVideoPlayer.SetDisplayMode(static_cast<Dali::VideoPlayerPlugin::DisplayMode::Type>(mode));
807 }
808
809 int VideoView::GetDisplayMode() const
810 {
811   return static_cast<int>(mVideoPlayer.GetDisplayMode());
812 }
813
814 Any VideoView::GetMediaPlayer()
815 {
816   return mVideoPlayer.GetMediaPlayer();
817 }
818
819 void VideoView::OnAnimationFinished(Animation& animation)
820 {
821   // send desync
822   SetFrameRenderCallback();
823 }
824
825 void VideoView::OnWindowResized(Dali::Window winHandle, Dali::Window::WindowSize size)
826 {
827   Dali::VideoPlayerPlugin::DisplayRotation videoAngle  = mVideoPlayer.GetDisplayRotation();
828   int                                      windowAngle = (DevelWindow::GetPhysicalOrientation(winHandle) / 90);
829
830   if(windowAngle != videoAngle)
831   {
832     mVideoPlayer.SetDisplayRotation(static_cast<Dali::VideoPlayerPlugin::DisplayRotation>(windowAngle));
833   }
834 }
835
836 void VideoView::PlayAnimation(Dali::Animation animation)
837 {
838   if(mIsUnderlay && mSyncMode == Dali::VideoSyncMode::ENABLED)
839   {
840     mVideoPlayer.StartSynchronization();
841     animation.FinishedSignal().Connect(this, &VideoView::OnAnimationFinished);
842   }
843   animation.Play();
844 }
845
846 Dali::Shader VideoView::CreateShader()
847 {
848   std::string fragmentShader;
849   std::string vertexShader;
850   std::string customFragmentShader;
851   bool        checkShader = false;
852
853   if(!mEffectPropertyMap.Empty())
854   {
855     Property::Value* vertexShaderValue = mEffectPropertyMap.Find(CUSTOM_VERTEX_SHADER);
856     if(vertexShaderValue)
857     {
858       checkShader = GetStringFromProperty(*vertexShaderValue, vertexShader);
859     }
860
861     if(!vertexShaderValue || !checkShader)
862     {
863       vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
864     }
865
866     Property::Value* fragmentShaderValue = mEffectPropertyMap.Find(CUSTOM_FRAGMENT_SHADER);
867     if(fragmentShaderValue)
868     {
869       checkShader = GetStringFromProperty(*fragmentShaderValue, customFragmentShader);
870
871       if(checkShader)
872       {
873         fragmentShader = customFragmentShader;
874       }
875     }
876
877     if(!fragmentShaderValue || !checkShader)
878     {
879       fragmentShader = SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
880       DevelTexture::ApplyNativeFragmentShader(mNativeTexture, fragmentShader);
881     }
882   }
883   else
884   {
885     vertexShader   = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
886     fragmentShader = SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
887     DevelTexture::ApplyNativeFragmentShader(mNativeTexture, fragmentShader);
888   }
889
890   return Dali::Shader::New(vertexShader, fragmentShader, Shader::Hint::NONE, "VIDEO_VIEW");
891 }
892
893 bool VideoView::GetStringFromProperty(const Dali::Property::Value& value, std::string& output)
894 {
895   bool extracted = false;
896   if(value.Get(output))
897   {
898     extracted = true;
899   }
900
901   return extracted;
902 }
903
904 void VideoView::ApplyBackupProperties()
905 {
906   Property::Map::SizeType pos   = 0;
907   Property::Map::SizeType count = mPropertyBackup.Count();
908
909   for(; pos < count; pos++)
910   {
911     KeyValuePair property = mPropertyBackup.GetKeyValue(pos);
912
913     SetPropertyInternal(property.first.indexKey, property.second);
914   }
915 }
916
917 void VideoView::FrameRenderCallback(int frameID)
918 {
919   // send desync
920   if(frameID == mFrameID)
921   {
922     mVideoPlayer.FinishSynchronization();
923     mFrameID = 0;
924   }
925 }
926
927 void VideoView::SetFrameRenderCallback()
928 {
929   mFrameID++;
930   DevelWindow::AddFrameRenderedCallback(DevelWindow::Get(Self()),
931                                         std::unique_ptr<CallbackBase>(MakeCallback(this, &VideoView::FrameRenderCallback)),
932                                         mFrameID);
933 }
934
935 bool VideoView::IsVideoView(Actor actor) const
936 {
937   // Check whether the actor is a VideoView
938   bool isVideoView = false;
939
940   if(actor)
941   {
942     Property::Index propertyIsVideoView = actor.GetPropertyIndex(IS_VIDEO_VIEW_PROPERTY_NAME);
943     if(propertyIsVideoView != Property::INVALID_INDEX)
944     {
945       isVideoView = actor.GetProperty<bool>(propertyIsVideoView);
946     }
947   }
948
949   return isVideoView;
950 }
951
952 VideoPlayer VideoView::GetVideoPlayer()
953 {
954   return mVideoPlayer;
955 }
956
957 } // namespace Internal
958
959 } // namespace Toolkit
960
961 } // namespace Dali