Adding photoshop blend modes to the GFX API 46/265046/3
authorDavid Steele <david.steele@samsung.com>
Thu, 7 Oct 2021 16:41:34 +0000 (17:41 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 8 Oct 2021 12:42:26 +0000 (12:42 +0000)
Change-Id: I9274f02b9e0098ebc06caa4c569944624bc56030

automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp
automated-tests/src/dali/utc-Dali-Renderer.cpp
dali/graphics-api/graphics-types.h
dali/internal/render/renderers/pipeline-cache.cpp

index 0886719..d2d8b16 100644 (file)
@@ -379,8 +379,81 @@ GLenum GetBlendOp(Graphics::BlendOp blendOp)
     case Graphics::BlendOp::MAX:
       op = GL_MAX;
       break;
-
-      // @todo Add advanced blend equations
+    case Graphics::BlendOp::MULTIPLY:
+    {
+      op = GL_MULTIPLY;
+      break;
+    }
+    case Graphics::BlendOp::SCREEN:
+    {
+      op = GL_SCREEN;
+      break;
+    }
+    case Graphics::BlendOp::OVERLAY:
+    {
+      op = GL_OVERLAY;
+      break;
+    }
+    case Graphics::BlendOp::DARKEN:
+    {
+      op = GL_DARKEN;
+      break;
+    }
+    case Graphics::BlendOp::LIGHTEN:
+    {
+      op = GL_LIGHTEN;
+      break;
+    }
+    case Graphics::BlendOp::COLOR_DODGE:
+    {
+      op = GL_COLORDODGE;
+      break;
+    }
+    case Graphics::BlendOp::COLOR_BURN:
+    {
+      op = GL_COLORBURN;
+      break;
+    }
+    case Graphics::BlendOp::HARD_LIGHT:
+    {
+      op = GL_HARDLIGHT;
+      break;
+    }
+    case Graphics::BlendOp::SOFT_LIGHT:
+    {
+      op = GL_SOFTLIGHT;
+      break;
+    }
+    case Graphics::BlendOp::DIFFERENCE:
+    {
+      op = GL_DIFFERENCE;
+      break;
+    }
+    case Graphics::BlendOp::EXCLUSION:
+    {
+      op = GL_EXCLUSION;
+      break;
+    }
+    case Graphics::BlendOp::HUE:
+    {
+      op = GL_HSL_HUE;
+      break;
+    }
+    case Graphics::BlendOp::SATURATION:
+    {
+      op = GL_HSL_SATURATION;
+      break;
+    }
+    case Graphics::BlendOp::COLOR:
+    {
+      op = GL_HSL_COLOR;
+      break;
+    }
+    case Graphics::BlendOp::LUMINOSITY:
+    {
+      op = GL_HSL_LUMINOSITY;
+      break;
+    }
   }
   return op;
 }
index 208e9d8..8557d2c 100644 (file)
@@ -698,6 +698,8 @@ int UtcDaliRendererBlendOptions05(void)
   actor.AddRenderer(renderer);
   actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
   application.GetScene().Add(actor);
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  glAbstraction.EnableEnableDisableCallTrace(true);
 
   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX))
   {
@@ -756,48 +758,93 @@ int UtcDaliRendererBlendOptions05(void)
   {
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MULTIPLY);
     DALI_TEST_EQUALS((int)DevelBlendEquation::MULTIPLY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_MULTIPLY, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
     DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_SCREEN, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::OVERLAY);
     DALI_TEST_EQUALS((int)DevelBlendEquation::OVERLAY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_OVERLAY, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DARKEN);
     DALI_TEST_EQUALS((int)DevelBlendEquation::DARKEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_DARKEN, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LIGHTEN);
     DALI_TEST_EQUALS((int)DevelBlendEquation::LIGHTEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_LIGHTEN, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_DODGE);
     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_DODGE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_COLORDODGE, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_BURN);
     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_BURN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_COLORBURN, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HARD_LIGHT);
     DALI_TEST_EQUALS((int)DevelBlendEquation::HARD_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HARDLIGHT, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SOFT_LIGHT);
     DALI_TEST_EQUALS((int)DevelBlendEquation::SOFT_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_SOFTLIGHT, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DIFFERENCE);
     DALI_TEST_EQUALS((int)DevelBlendEquation::DIFFERENCE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_DIFFERENCE, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::EXCLUSION);
     DALI_TEST_EQUALS((int)DevelBlendEquation::EXCLUSION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_EXCLUSION, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HUE);
     DALI_TEST_EQUALS((int)DevelBlendEquation::HUE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_HUE, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SATURATION);
     DALI_TEST_EQUALS((int)DevelBlendEquation::SATURATION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_SATURATION, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR);
     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_COLOR, TEST_LOCATION);
 
     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LUMINOSITY);
     DALI_TEST_EQUALS((int)DevelBlendEquation::LUMINOSITY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
+    application.SendNotification();
+    application.Render();
+    DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_LUMINOSITY, TEST_LOCATION);
   }
 
   END_TEST;
index 99984bb..55816f5 100644 (file)
@@ -165,7 +165,24 @@ enum class BlendOp
   REVERSE_SUBTRACT = 2,
   MIN              = 3,
   MAX              = 4,
-};
+  MULTIPLY         = 5,
+  SCREEN           = 6,
+  OVERLAY          = 7,
+  DARKEN           = 8,
+  LIGHTEN          = 9,
+  COLOR_DODGE      = 10,
+  COLOR_BURN       = 11,
+  HARD_LIGHT       = 12,
+  SOFT_LIGHT       = 13,
+  DIFFERENCE       = 14,
+  EXCLUSION        = 15,
+  HUE              = 16,
+  SATURATION       = 17,
+  COLOR            = 18,
+  LUMINOSITY       = 19,
+};
+
+const BlendOp ADVANCED_BLEND_OPTIONS_START(BlendOp::MULTIPLY);
 
 /**
  * @brief Compare operators
index 9584c12..3f6bcc6 100644 (file)
@@ -152,23 +152,39 @@ constexpr Graphics::BlendOp ConvertBlendEquation(DevelBlendEquation::Type blendE
     case DevelBlendEquation::REVERSE_SUBTRACT:
       return Graphics::BlendOp::REVERSE_SUBTRACT;
     case DevelBlendEquation::COLOR:
+      return Graphics::BlendOp::COLOR;
     case DevelBlendEquation::COLOR_BURN:
+      return Graphics::BlendOp::COLOR_BURN;
     case DevelBlendEquation::COLOR_DODGE:
+      return Graphics::BlendOp::COLOR_DODGE;
     case DevelBlendEquation::DARKEN:
+      return Graphics::BlendOp::DARKEN;
     case DevelBlendEquation::DIFFERENCE:
+      return Graphics::BlendOp::DIFFERENCE;
     case DevelBlendEquation::EXCLUSION:
+      return Graphics::BlendOp::EXCLUSION;
     case DevelBlendEquation::HARD_LIGHT:
+      return Graphics::BlendOp::HARD_LIGHT;
     case DevelBlendEquation::HUE:
+      return Graphics::BlendOp::HUE;
     case DevelBlendEquation::LIGHTEN:
+      return Graphics::BlendOp::LIGHTEN;
     case DevelBlendEquation::LUMINOSITY:
+      return Graphics::BlendOp::LUMINOSITY;
     case DevelBlendEquation::MAX:
+      return Graphics::BlendOp::MAX;
     case DevelBlendEquation::MIN:
+      return Graphics::BlendOp::MIN;
     case DevelBlendEquation::MULTIPLY:
+      return Graphics::BlendOp::MULTIPLY;
     case DevelBlendEquation::OVERLAY:
+      return Graphics::BlendOp::OVERLAY;
     case DevelBlendEquation::SATURATION:
+      return Graphics::BlendOp::SATURATION;
     case DevelBlendEquation::SCREEN:
+      return Graphics::BlendOp::SCREEN;
     case DevelBlendEquation::SOFT_LIGHT:
-      return Graphics::BlendOp{};
+      return Graphics::BlendOp::SOFT_LIGHT;
   }
   return Graphics::BlendOp{};
 }
@@ -414,9 +430,6 @@ PipelineResult PipelineCache::GetPipeline(const PipelineCacheQueryInfo& queryInf
 
     // Store a pipeline per renderer per render (renderer can be owned by multiple nodes,
     // and re-drawn in multiple instructions).
-    // @todo This is only needed because ColorBlend state can change. Fixme!
-    // This is ameliorated by the fact that implementation caches pipelines, and we're only storing
-    // handles.
     level2->pipeline = graphicsController->CreatePipeline(createInfo, nullptr);
   }