Commit b70180a6e9554c70e54fbad940f63e9ef89671ea
1 parent
0b5959ae
Improved NativeImageSource example
Change-Id: I6b4629923ff9d20b48a0ba0b07369bea00900bfb
Showing
1 changed file
with
239 additions
and
96 deletions
examples/native-image-source/native-image-source-example.cpp
| @@ -32,6 +32,12 @@ using namespace Toolkit; | @@ -32,6 +32,12 @@ using namespace Toolkit; | ||
| 32 | namespace | 32 | namespace |
| 33 | { | 33 | { |
| 34 | 34 | ||
| 35 | +const float BUTTON_HEIGHT = 100.0f; | ||
| 36 | +const float BUTTON_COUNT = 5.0f; | ||
| 37 | + | ||
| 38 | +const std::string JPG_FILENAME = DEMO_IMAGE_DIR "gallery-medium-4.jpg"; | ||
| 39 | +const std::string CAPTURE_FILENAME = "/tmp/native-image-capture.png"; | ||
| 40 | + | ||
| 35 | /** | 41 | /** |
| 36 | * @brief Creates a shader used to render a native image | 42 | * @brief Creates a shader used to render a native image |
| 37 | * @param[in] nativeImageInterface The native image interface | 43 | * @param[in] nativeImageInterface The native image interface |
| @@ -98,28 +104,6 @@ Shader CreateShader( NativeImageInterface& nativeImageInterface ) | @@ -98,28 +104,6 @@ Shader CreateShader( NativeImageInterface& nativeImageInterface ) | ||
| 98 | } | 104 | } |
| 99 | } | 105 | } |
| 100 | 106 | ||
| 101 | -/** | ||
| 102 | - * @brief Creates an actor to render a native image | ||
| 103 | - * @param[in] texture The texture creates from a native image | ||
| 104 | - * @param[in] nativeImageInterface The native image interface used to create the texture | ||
| 105 | - * @return An actor that renders the texture | ||
| 106 | - */ | ||
| 107 | -Actor CreateNativeActor( Texture texture, NativeImageInterface& nativeImageInterface ) | ||
| 108 | -{ | ||
| 109 | - Actor actor = Actor::New(); | ||
| 110 | - Geometry geometry = DemoHelper::CreateTexturedQuad(); | ||
| 111 | - Shader shader = CreateShader(nativeImageInterface); | ||
| 112 | - Renderer renderer = Renderer::New( geometry, shader ); | ||
| 113 | - TextureSet textureSet = TextureSet::New(); | ||
| 114 | - textureSet.SetTexture( 0u, texture ); | ||
| 115 | - renderer.SetTextures( textureSet ); | ||
| 116 | - | ||
| 117 | - actor.AddRenderer( renderer ); | ||
| 118 | - actor.SetSize( texture.GetWidth(), texture.GetHeight() ); | ||
| 119 | - return actor; | ||
| 120 | -} | ||
| 121 | - | ||
| 122 | -const std::string JPG_FILENAME = DEMO_IMAGE_DIR "gallery-medium-4.jpg"; | ||
| 123 | } | 107 | } |
| 124 | 108 | ||
| 125 | // This example shows how to create and use a NativeImageSource as the target of the render task. | 109 | // This example shows how to create and use a NativeImageSource as the target of the render task. |
| @@ -129,7 +113,8 @@ class NativeImageSourceController : public ConnectionTracker | @@ -129,7 +113,8 @@ class NativeImageSourceController : public ConnectionTracker | ||
| 129 | public: | 113 | public: |
| 130 | 114 | ||
| 131 | NativeImageSourceController( Application& application ) | 115 | NativeImageSourceController( Application& application ) |
| 132 | - : mApplication( application ) | 116 | + : mApplication( application ), |
| 117 | + mRefreshAlways( true ) | ||
| 133 | { | 118 | { |
| 134 | // Connect to the Application's Init signal | 119 | // Connect to the Application's Init signal |
| 135 | mApplication.InitSignal().Connect( this, &NativeImageSourceController::Create ); | 120 | mApplication.InitSignal().Connect( this, &NativeImageSourceController::Create ); |
| @@ -152,121 +137,259 @@ public: | @@ -152,121 +137,259 @@ public: | ||
| 152 | 137 | ||
| 153 | stage.KeyEventSignal().Connect(this, &NativeImageSourceController::OnKeyEvent); | 138 | stage.KeyEventSignal().Connect(this, &NativeImageSourceController::OnKeyEvent); |
| 154 | 139 | ||
| 140 | + CreateButtonArea(); | ||
| 141 | + | ||
| 142 | + CreateContentAreas(); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + void CreateButtonArea() | ||
| 146 | + { | ||
| 147 | + Stage stage = Stage::GetCurrent(); | ||
| 148 | + Vector2 stageSize = stage.GetSize(); | ||
| 149 | + | ||
| 150 | + mButtonArea = Layer::New(); | ||
| 151 | + mButtonArea.SetSize( stageSize.x, BUTTON_HEIGHT ); | ||
| 152 | + mButtonArea.SetParentOrigin( ParentOrigin::TOP_CENTER ); | ||
| 153 | + mButtonArea.SetAnchorPoint( AnchorPoint::TOP_CENTER ); | ||
| 154 | + stage.Add( mButtonArea ); | ||
| 155 | + | ||
| 156 | + mButtonShow = PushButton::New(); | ||
| 157 | + mButtonShow.SetProperty( Button::Property::TOGGLABLE, true ); | ||
| 158 | + mButtonShow.SetProperty( Toolkit::Button::Property::LABEL, "SHOW" ); | ||
| 159 | + mButtonShow.SetParentOrigin( ParentOrigin::TOP_LEFT ); | ||
| 160 | + mButtonShow.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 161 | + mButtonShow.SetSize( stageSize.x / BUTTON_COUNT, BUTTON_HEIGHT ); | ||
| 162 | + mButtonShow.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); | ||
| 163 | + mButtonArea.Add( mButtonShow ); | ||
| 164 | + | ||
| 155 | mButtonRefreshAlways = PushButton::New(); | 165 | mButtonRefreshAlways = PushButton::New(); |
| 156 | mButtonRefreshAlways.SetProperty( Button::Property::TOGGLABLE, true ); | 166 | mButtonRefreshAlways.SetProperty( Button::Property::TOGGLABLE, true ); |
| 157 | - mButtonRefreshAlways.SetProperty( Button::Property::SELECTED, true ); | ||
| 158 | - mButtonRefreshAlways.SetProperty( Toolkit::Button::Property::LABEL, "Refresh ALWAYS" ); | 167 | + mButtonRefreshAlways.SetProperty( Toolkit::Button::Property::LABEL, "ALWAYS" ); |
| 159 | mButtonRefreshAlways.SetParentOrigin( ParentOrigin::TOP_LEFT ); | 168 | mButtonRefreshAlways.SetParentOrigin( ParentOrigin::TOP_LEFT ); |
| 160 | mButtonRefreshAlways.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | 169 | mButtonRefreshAlways.SetAnchorPoint( AnchorPoint::TOP_LEFT ); |
| 170 | + mButtonRefreshAlways.SetSize( stageSize.x / BUTTON_COUNT, BUTTON_HEIGHT ); | ||
| 171 | + mButtonRefreshAlways.SetPosition( (stageSize.x / BUTTON_COUNT)*1.0f, 0.0f ); | ||
| 161 | mButtonRefreshAlways.StateChangedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); | 172 | mButtonRefreshAlways.StateChangedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); |
| 162 | - stage.Add( mButtonRefreshAlways ); | 173 | + mButtonArea.Add( mButtonRefreshAlways ); |
| 163 | 174 | ||
| 164 | mButtonRefreshOnce = PushButton::New(); | 175 | mButtonRefreshOnce = PushButton::New(); |
| 165 | - mButtonRefreshOnce.SetProperty( Toolkit::Button::Property::LABEL, "Refresh ONCE" ); | ||
| 166 | - mButtonRefreshOnce.SetParentOrigin( ParentOrigin::TOP_RIGHT ); | ||
| 167 | - mButtonRefreshOnce.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); | 176 | + mButtonRefreshOnce.SetProperty( Toolkit::Button::Property::LABEL, "ONCE" ); |
| 177 | + mButtonRefreshOnce.SetParentOrigin( ParentOrigin::TOP_LEFT ); | ||
| 178 | + mButtonRefreshOnce.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 179 | + mButtonRefreshOnce.SetSize( stageSize.x / BUTTON_COUNT, BUTTON_HEIGHT ); | ||
| 180 | + mButtonRefreshOnce.SetPosition( (stageSize.x / BUTTON_COUNT)*2.0f, 0.0f ); | ||
| 168 | mButtonRefreshOnce.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); | 181 | mButtonRefreshOnce.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); |
| 169 | - stage.Add( mButtonRefreshOnce); | ||
| 170 | - | ||
| 171 | - CreateScene(); | 182 | + mButtonArea.Add( mButtonRefreshOnce ); |
| 183 | + | ||
| 184 | + mButtonCapture = PushButton::New(); | ||
| 185 | + mButtonCapture.SetProperty( Toolkit::Button::Property::LABEL, "CAPTURE" ); | ||
| 186 | + mButtonCapture.SetParentOrigin( ParentOrigin::TOP_LEFT ); | ||
| 187 | + mButtonCapture.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 188 | + mButtonCapture.SetSize( stageSize.x / BUTTON_COUNT, BUTTON_HEIGHT ); | ||
| 189 | + mButtonCapture.SetPosition( (stageSize.x / BUTTON_COUNT)*3.0f, 0.0f ); | ||
| 190 | + mButtonCapture.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); | ||
| 191 | + mButtonArea.Add( mButtonCapture ); | ||
| 192 | + | ||
| 193 | + mButtonReset = PushButton::New(); | ||
| 194 | + mButtonReset.SetProperty( Toolkit::Button::Property::LABEL, "RESET" ); | ||
| 195 | + mButtonReset.SetParentOrigin( ParentOrigin::TOP_LEFT ); | ||
| 196 | + mButtonReset.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 197 | + mButtonReset.SetSize( stageSize.x / BUTTON_COUNT, BUTTON_HEIGHT ); | ||
| 198 | + mButtonReset.SetPosition( (stageSize.x / BUTTON_COUNT)*4.0f, 0.0f ); | ||
| 199 | + mButtonReset.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); | ||
| 200 | + mButtonArea.Add( mButtonReset ); | ||
| 172 | } | 201 | } |
| 173 | 202 | ||
| 174 | - bool CreateScene() | 203 | + void CreateContentAreas() |
| 175 | { | 204 | { |
| 176 | Stage stage = Stage::GetCurrent(); | 205 | Stage stage = Stage::GetCurrent(); |
| 177 | Vector2 stageSize = stage.GetSize(); | 206 | Vector2 stageSize = stage.GetSize(); |
| 178 | 207 | ||
| 179 | - float buttonHeight = 100.f; | ||
| 180 | - mButtonRefreshAlways.SetSize( stageSize.x / 2.f, buttonHeight ); | ||
| 181 | - mButtonRefreshOnce.SetSize( stageSize.x / 2.f, buttonHeight ); | 208 | + float contentHeight( (stageSize.y - BUTTON_HEIGHT)/2.0f ); |
| 182 | 209 | ||
| 183 | - Vector2 imageSize( stageSize.x, (stageSize.y-buttonHeight)/2.f ); | 210 | + mTopContentArea = Actor::New(); |
| 211 | + mTopContentArea.SetSize( stageSize.x, contentHeight ); | ||
| 212 | + mTopContentArea.SetParentOrigin( ParentOrigin::TOP_CENTER ); | ||
| 213 | + mTopContentArea.SetAnchorPoint( AnchorPoint::TOP_CENTER ); | ||
| 214 | + mTopContentArea.SetY( BUTTON_HEIGHT ); | ||
| 215 | + stage.Add( mTopContentArea ); | ||
| 184 | 216 | ||
| 185 | - // Create the native image source | ||
| 186 | - NativeImageSourcePtr nativeImageSourcePtr = NativeImageSource::New( imageSize.width, imageSize.height, NativeImageSource::COLOR_DEPTH_DEFAULT ); | 217 | + mBottomContentArea = Actor::New(); |
| 218 | + mBottomContentArea.SetSize( stageSize.x, contentHeight ); | ||
| 219 | + mBottomContentArea.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | ||
| 220 | + mBottomContentArea.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | ||
| 221 | + stage.Add( mBottomContentArea ); | ||
| 187 | 222 | ||
| 188 | - // Create a image view as source actor to be renderer to the native image source | ||
| 189 | - Actor sourceActor = ImageView::New(JPG_FILENAME); | ||
| 190 | - sourceActor.SetParentOrigin( ParentOrigin::CENTER); | ||
| 191 | - sourceActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 192 | - sourceActor.SetY( - (imageSize.height-buttonHeight)/2.f ); | ||
| 193 | - stage.Add( sourceActor ); | 223 | + mSourceActor = ImageView::New(JPG_FILENAME); |
| 224 | + mSourceActor.SetParentOrigin( ParentOrigin::CENTER); | ||
| 225 | + mSourceActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 226 | + mTopContentArea.Add( mSourceActor ); | ||
| 194 | 227 | ||
| 195 | Animation animation = Animation::New(2.f); | 228 | Animation animation = Animation::New(2.f); |
| 196 | Degree relativeRotationDegrees(90.0f); | 229 | Degree relativeRotationDegrees(90.0f); |
| 197 | Radian relativeRotationRadians(relativeRotationDegrees); | 230 | Radian relativeRotationRadians(relativeRotationDegrees); |
| 198 | - animation.AnimateTo( Property( sourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(0.f, 0.5f)); | ||
| 199 | - animation.AnimateBy( Property( sourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(0.5f, 0.5f)); | ||
| 200 | - animation.AnimateBy( Property( sourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(1.f, 0.5f)); | ||
| 201 | - animation.AnimateBy( Property( sourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(1.5f, 0.5f)); | 231 | + animation.AnimateTo( Property( mSourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(0.f, 0.5f)); |
| 232 | + animation.AnimateBy( Property( mSourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(0.5f, 0.5f)); | ||
| 233 | + animation.AnimateBy( Property( mSourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(1.f, 0.5f)); | ||
| 234 | + animation.AnimateBy( Property( mSourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(1.5f, 0.5f)); | ||
| 202 | animation.SetLooping(true); | 235 | animation.SetLooping(true); |
| 203 | animation.Play(); | 236 | animation.Play(); |
| 204 | 237 | ||
| 205 | - // create a offscreen renderer task to render content into the native image source | ||
| 206 | - Texture nativeTexture = Texture::New( *nativeImageSourcePtr ); | ||
| 207 | - // Create a FrameBuffer object with no default attachments. | ||
| 208 | - FrameBuffer targetBuffer = FrameBuffer::New( nativeTexture.GetWidth(), nativeTexture.GetHeight(), FrameBuffer::Attachment::NONE ); | ||
| 209 | - // Add a color attachment to the FrameBuffer object. | ||
| 210 | - targetBuffer.AttachColorTexture( nativeTexture ); | ||
| 211 | - | ||
| 212 | - CameraActor cameraActor = CameraActor::New(imageSize); | ||
| 213 | - cameraActor.SetParentOrigin(ParentOrigin::TOP_CENTER); | ||
| 214 | - cameraActor.SetParentOrigin( AnchorPoint::TOP_CENTER ); | ||
| 215 | - cameraActor.SetY( buttonHeight + imageSize.height/2.f ); | ||
| 216 | - stage.Add(cameraActor); | ||
| 217 | - | ||
| 218 | - RenderTaskList taskList = stage.GetRenderTaskList(); | ||
| 219 | - mOffscreenRenderTask = taskList.CreateTask(); | ||
| 220 | - mOffscreenRenderTask.SetSourceActor( sourceActor ); | ||
| 221 | - mOffscreenRenderTask.SetClearColor( Color::WHITE ); | ||
| 222 | - mOffscreenRenderTask.SetClearEnabled(true); | ||
| 223 | - mOffscreenRenderTask.SetCameraActor(cameraActor); | ||
| 224 | - mOffscreenRenderTask.GetCameraActor().SetInvertYAxis(true); | ||
| 225 | - mOffscreenRenderTask.SetFrameBuffer( targetBuffer ); | ||
| 226 | - mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ALWAYS ); | ||
| 227 | - | ||
| 228 | - // Display the native image on the screen | ||
| 229 | - Actor nativeImageActor = CreateNativeActor( nativeTexture, *nativeImageSourcePtr ); | ||
| 230 | - nativeImageActor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | ||
| 231 | - nativeImageActor.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | ||
| 232 | - stage.Add( nativeImageActor ); | ||
| 233 | - | ||
| 234 | - TextLabel textLabel1 = TextLabel::New( "Resource Image" ); | ||
| 235 | - textLabel1.SetParentOrigin( ParentOrigin::TOP_CENTER ); | 238 | + TextLabel textLabel1 = TextLabel::New( "Image" ); |
| 239 | + textLabel1.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | ||
| 236 | textLabel1.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | 240 | textLabel1.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); |
| 237 | - nativeImageActor.Add( textLabel1 ); | 241 | + mTopContentArea.Add( textLabel1 ); |
| 242 | + | ||
| 243 | + // Wait until button press before creating mOffscreenRenderTask | ||
| 238 | 244 | ||
| 239 | TextLabel textLabel2 = TextLabel::New( "Native Image" ); | 245 | TextLabel textLabel2 = TextLabel::New( "Native Image" ); |
| 240 | textLabel2.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); | 246 | textLabel2.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); |
| 241 | textLabel2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | 247 | textLabel2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); |
| 242 | - nativeImageActor.Add( textLabel2 ); | ||
| 243 | - | ||
| 244 | - return false; | 248 | + mBottomContentArea.Add( textLabel2 ); |
| 245 | } | 249 | } |
| 246 | 250 | ||
| 247 | - bool OnButtonSelected( Toolkit::Button button ) | 251 | + void SetupNativeImage() |
| 248 | { | 252 | { |
| 249 | - bool isSelected = mButtonRefreshAlways.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>(); | 253 | + if( ! mOffscreenRenderTask ) |
| 254 | + { | ||
| 255 | + Stage stage = Stage::GetCurrent(); | ||
| 256 | + Vector2 stageSize = stage.GetSize(); | ||
| 257 | + | ||
| 258 | + float contentHeight( (stageSize.y - BUTTON_HEIGHT)/2.0f ); | ||
| 259 | + Vector2 imageSize( stageSize.x, contentHeight ); | ||
| 260 | + | ||
| 261 | + mNativeImageSourcePtr = NativeImageSource::New( imageSize.width, imageSize.height, NativeImageSource::COLOR_DEPTH_DEFAULT ); | ||
| 262 | + mNativeTexture = Texture::New( *mNativeImageSourcePtr ); | ||
| 263 | + | ||
| 264 | + mFrameBuffer = FrameBuffer::New( mNativeTexture.GetWidth(), mNativeTexture.GetHeight(), FrameBuffer::Attachment::NONE ); | ||
| 265 | + mFrameBuffer.AttachColorTexture( mNativeTexture ); | ||
| 266 | + | ||
| 267 | + mCameraActor = CameraActor::New( imageSize ); | ||
| 268 | + mCameraActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 269 | + mCameraActor.SetParentOrigin( AnchorPoint::CENTER ); | ||
| 270 | + mTopContentArea.Add( mCameraActor ); | ||
| 271 | + | ||
| 272 | + RenderTaskList taskList = stage.GetRenderTaskList(); | ||
| 273 | + mOffscreenRenderTask = taskList.CreateTask(); | ||
| 274 | + mOffscreenRenderTask.SetSourceActor( mSourceActor ); | ||
| 275 | + mOffscreenRenderTask.SetClearColor( Color::WHITE ); | ||
| 276 | + mOffscreenRenderTask.SetClearEnabled( true ); | ||
| 277 | + mOffscreenRenderTask.SetCameraActor( mCameraActor ); | ||
| 278 | + mOffscreenRenderTask.GetCameraActor().SetInvertYAxis( true ); | ||
| 279 | + mOffscreenRenderTask.SetFrameBuffer( mFrameBuffer ); | ||
| 280 | + } | ||
| 250 | 281 | ||
| 251 | - Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( button ); | ||
| 252 | - if( pushButton == mButtonRefreshAlways ) | 282 | + if( mRefreshAlways ) |
| 253 | { | 283 | { |
| 254 | - if( isSelected ) | ||
| 255 | - { | ||
| 256 | - mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ALWAYS ); | ||
| 257 | - } | ||
| 258 | - else | 284 | + mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ALWAYS ); |
| 285 | + } | ||
| 286 | + else | ||
| 287 | + { | ||
| 288 | + mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ONCE ); | ||
| 289 | + } | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + void SetupDisplayActor( bool show ) | ||
| 293 | + { | ||
| 294 | + if( show ) | ||
| 295 | + { | ||
| 296 | + if( ! mDisplayActor ) | ||
| 259 | { | 297 | { |
| 260 | - mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ONCE ); | 298 | + // Make sure we have something to display |
| 299 | + SetupNativeImage(); | ||
| 300 | + | ||
| 301 | + mDisplayActor = Actor::New(); | ||
| 302 | + mDisplayActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 303 | + mDisplayActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 304 | + | ||
| 305 | + Geometry geometry = DemoHelper::CreateTexturedQuad(); | ||
| 306 | + | ||
| 307 | + Shader shader = CreateShader( *mNativeImageSourcePtr ); | ||
| 308 | + | ||
| 309 | + Renderer renderer = Renderer::New( geometry, shader ); | ||
| 310 | + | ||
| 311 | + TextureSet textureSet = TextureSet::New(); | ||
| 312 | + textureSet.SetTexture( 0u, mNativeTexture ); | ||
| 313 | + renderer.SetTextures( textureSet ); | ||
| 314 | + | ||
| 315 | + mDisplayActor.AddRenderer( renderer ); | ||
| 316 | + mDisplayActor.SetSize( mNativeTexture.GetWidth(), mNativeTexture.GetHeight() ); | ||
| 317 | + | ||
| 318 | + mBottomContentArea.Add( mDisplayActor ); | ||
| 261 | } | 319 | } |
| 262 | } | 320 | } |
| 321 | + else | ||
| 322 | + { | ||
| 323 | + UnparentAndReset( mDisplayActor ); | ||
| 324 | + } | ||
| 325 | + } | ||
| 326 | + | ||
| 327 | + void Capture() | ||
| 328 | + { | ||
| 329 | + mRefreshAlways = false; | ||
| 330 | + SetupNativeImage(); | ||
| 331 | + | ||
| 332 | + mOffscreenRenderTask.FinishedSignal().Connect( this, &NativeImageSourceController::DoCapture ); | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + void DoCapture(RenderTask& task) | ||
| 336 | + { | ||
| 337 | + task.FinishedSignal().Disconnect( this, &NativeImageSourceController::DoCapture ); | ||
| 338 | + | ||
| 339 | + mNativeImageSourcePtr->EncodeToFile( CAPTURE_FILENAME ); | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + void Reset() | ||
| 343 | + { | ||
| 344 | + SetupDisplayActor( false ); | ||
| 345 | + | ||
| 346 | + Stage stage = Stage::GetCurrent(); | ||
| 347 | + RenderTaskList taskList = stage.GetRenderTaskList(); | ||
| 348 | + taskList.RemoveTask( mOffscreenRenderTask ); | ||
| 349 | + mOffscreenRenderTask.Reset(); | ||
| 350 | + mCameraActor.Reset(); | ||
| 351 | + | ||
| 352 | + mFrameBuffer.Reset(); | ||
| 353 | + mNativeTexture.Reset(); | ||
| 354 | + mNativeImageSourcePtr.Reset(); | ||
| 355 | + } | ||
| 356 | + | ||
| 357 | + bool OnButtonSelected( Toolkit::Button button ) | ||
| 358 | + { | ||
| 359 | + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( button ); | ||
| 360 | + | ||
| 361 | + if( pushButton == mButtonShow ) | ||
| 362 | + { | ||
| 363 | + bool isSelected = mButtonShow.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>(); | ||
| 364 | + | ||
| 365 | + SetupDisplayActor( isSelected ); | ||
| 366 | + } | ||
| 367 | + else if( pushButton == mButtonRefreshAlways ) | ||
| 368 | + { | ||
| 369 | + bool isSelected = mButtonRefreshAlways.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>(); | ||
| 370 | + | ||
| 371 | + mRefreshAlways = isSelected; | ||
| 372 | + SetupNativeImage(); | ||
| 373 | + } | ||
| 263 | else if( pushButton == mButtonRefreshOnce ) | 374 | else if( pushButton == mButtonRefreshOnce ) |
| 264 | { | 375 | { |
| 376 | + bool isSelected = mButtonRefreshAlways.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>(); | ||
| 377 | + | ||
| 265 | if( isSelected ) | 378 | if( isSelected ) |
| 266 | { | 379 | { |
| 267 | mButtonRefreshAlways.SetProperty( Button::Property::SELECTED, false ); | 380 | mButtonRefreshAlways.SetProperty( Button::Property::SELECTED, false ); |
| 268 | } | 381 | } |
| 269 | - mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ONCE ); | 382 | + |
| 383 | + mRefreshAlways = false; | ||
| 384 | + SetupNativeImage(); | ||
| 385 | + } | ||
| 386 | + else if( pushButton == mButtonCapture ) | ||
| 387 | + { | ||
| 388 | + Capture(); | ||
| 389 | + } | ||
| 390 | + else if( pushButton == mButtonReset ) | ||
| 391 | + { | ||
| 392 | + Reset(); | ||
| 270 | } | 393 | } |
| 271 | 394 | ||
| 272 | return true; | 395 | return true; |
| @@ -284,11 +407,31 @@ public: | @@ -284,11 +407,31 @@ public: | ||
| 284 | } | 407 | } |
| 285 | 408 | ||
| 286 | private: | 409 | private: |
| 410 | + | ||
| 287 | Application& mApplication; | 411 | Application& mApplication; |
| 288 | - RenderTask mOffscreenRenderTask; | 412 | + |
| 413 | + Layer mButtonArea; | ||
| 414 | + Actor mTopContentArea; | ||
| 415 | + Actor mBottomContentArea; | ||
| 416 | + | ||
| 417 | + PushButton mButtonShow; | ||
| 289 | PushButton mButtonRefreshAlways; | 418 | PushButton mButtonRefreshAlways; |
| 290 | PushButton mButtonRefreshOnce; | 419 | PushButton mButtonRefreshOnce; |
| 420 | + PushButton mButtonCapture; | ||
| 421 | + PushButton mButtonReset; | ||
| 422 | + | ||
| 423 | + Actor mSourceActor; | ||
| 424 | + | ||
| 425 | + NativeImageSourcePtr mNativeImageSourcePtr; | ||
| 426 | + Texture mNativeTexture; | ||
| 427 | + FrameBuffer mFrameBuffer; | ||
| 428 | + | ||
| 429 | + RenderTask mOffscreenRenderTask; | ||
| 430 | + CameraActor mCameraActor; | ||
| 431 | + | ||
| 432 | + Actor mDisplayActor; | ||
| 291 | 433 | ||
| 434 | + bool mRefreshAlways; | ||
| 292 | }; | 435 | }; |
| 293 | 436 | ||
| 294 | void RunTest( Application& application ) | 437 | void RunTest( Application& application ) |