Fast bounding-box clipping feature 00/152000/8
authorTom Robinson <tom.robinson@samsung.com>
Fri, 22 Sep 2017 17:18:48 +0000 (18:18 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 6 Oct 2017 14:32:43 +0000 (15:32 +0100)
Change-Id: Id70c4eb2ba2f857d6db26efb3dd15cc14b9b08b1

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h
dali-toolkit/public-api/controls/control-impl.cpp

index c4bc01d..02439bc 100644 (file)
@@ -85,6 +85,7 @@ void TestGlAbstraction::Initialize()
   mEnableDisableTrace.Reset();
   mShaderTrace.Reset();
   mStencilFunctionTrace.Reset();
+  mScissorTrace.Reset();
   mTextureTrace.Reset();
   mTexParamaterTrace.Reset();
   mDrawTrace.Reset();
index 8408b10..b306c3e 100644 (file)
@@ -949,6 +949,15 @@ public:
     mScissorParams.y = y;
     mScissorParams.width = width;
     mScissorParams.height = height;
+
+    std::stringstream out;
+    out << x << ", " << y << ", " << width << ", " << height;
+    TraceCallStack::NamedParams namedParams;
+    namedParams["x"] = ToString( x );
+    namedParams["y"] = ToString( y );
+    namedParams["width"] = ToString( width );
+    namedParams["height"] = ToString( height );
+    mScissorTrace.PushCall( "Scissor", out.str(), namedParams );
   }
 
   inline void ShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
@@ -1951,6 +1960,11 @@ public: // TEST FUNCTIONS
   inline void ResetStencilFunctionCallStack() { mStencilFunctionTrace.Reset(); }
   inline TraceCallStack& GetStencilFunctionTrace() { return mStencilFunctionTrace; }
 
+  //Methods for Scissor verification
+  inline void EnableScissorCallTrace(bool enable) { mScissorTrace.Enable(enable); }
+  inline void ResetScissorCallStack() { mScissorTrace.Reset(); }
+  inline TraceCallStack& GetScissorTrace() { return mScissorTrace; }
+
   //Methods for Uniform function verification
   inline void EnableSetUniformCallTrace(bool enable) { mSetUniformTrace.Enable(enable); }
   inline void ResetSetUniformCallStack() { mSetUniformTrace.Reset(); }
@@ -2189,6 +2203,7 @@ private:
   TraceCallStack mDrawTrace;
   TraceCallStack mDepthFunctionTrace;
   TraceCallStack mStencilFunctionTrace;
+  TraceCallStack mScissorTrace;
   TraceCallStack mSetUniformTrace;
 
   // Shaders & Uniforms
index 1fb9f44..68fd55a 100644 (file)
@@ -60,13 +60,30 @@ namespace
 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
 #endif
 
-DALI_ENUM_TO_STRING_TABLE_BEGIN( CLIPPING_MODE )
-DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, DISABLED )
-DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, CLIP_CHILDREN )
-DALI_ENUM_TO_STRING_TABLE_END( CLIPPING_MODE )
+/**
+ * @brief Creates a clipping renderer if required.
+ * (EG. If no renders exist and clipping is enabled).
+ * @param[in] controlImpl The control implementation.
+ */
+void CreateClippingRenderer( Control& controlImpl )
+{
+  // We want to add a transparent background if we do not have one for clipping.
+  Actor self( controlImpl.Self() );
+  int clippingMode = ClippingMode::DISABLED;
+  if( self.GetProperty( Actor::Property::CLIPPING_MODE ).Get( clippingMode ) )
+  {
+    Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
 
-} // unnamed namespace
+    if( ( clippingMode == ClippingMode::CLIP_CHILDREN ) &&
+        controlDataImpl.mVisuals.Empty() &&
+        ( self.GetRendererCount() == 0u ) )
+    {
+      controlImpl.SetBackgroundColor( Color::TRANSPARENT );
+    }
+  }
+}
 
+} // unnamed namespace
 
 
 Toolkit::Control Control::New()
@@ -498,21 +515,8 @@ void Control::OnStageConnection( int depth )
     }
   }
 
-  if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() )
-  {
-    Property::Value clippingValue = self.GetProperty( Actor::Property::CLIPPING_MODE );
-    int clippingMode = ClippingMode::DISABLED;
-    if( clippingValue.Get( clippingMode ) )
-    {
-      // Add a transparent background if we do not have any renderers or visuals so we clip our children
-
-      if( clippingMode == ClippingMode::CLIP_CHILDREN )
-      {
-        // Create a transparent background visual which will also get staged.
-        SetBackgroundColor( Color::TRANSPARENT );
-      }
-    }
-  }
+  // The clipping renderer is only created if required.
+  CreateClippingRenderer( *this );
 }
 
 void Control::OnStageDisconnection()
@@ -544,24 +548,12 @@ void Control::OnChildRemove(Actor& child)
 
 void Control::OnPropertySet( Property::Index index, Property::Value propertyValue )
 {
-  Actor self( Self() );
-  if( index == Actor::Property::CLIPPING_MODE )
+  // If the clipping mode has been set, we may need to create a renderer.
+  // Only do this if we are already on-stage as the OnStageConnection will handle the off-stage clipping controls.
+  if( ( index == Actor::Property::CLIPPING_MODE ) && Self().OnStage() )
   {
-    // Only set the background if we're already on the stage and have no renderers or visuals
-
-    if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() && self.OnStage() )
-    {
-      ClippingMode::Type clippingMode = ClippingMode::DISABLED;
-      if( Scripting::GetEnumerationProperty< ClippingMode::Type >( propertyValue, CLIPPING_MODE_TABLE, CLIPPING_MODE_TABLE_COUNT, clippingMode ) )
-      {
-        // Add a transparent background if we do not have one so we clip children
-
-        if( clippingMode == ClippingMode::CLIP_CHILDREN )
-        {
-          SetBackgroundColor( Color::TRANSPARENT );
-        }
-      }
-    }
+    // Note: This method will handle whether creation of the renderer is required.
+    CreateClippingRenderer( *this );
   }
 }