move compose-shader into base-class as factory
authorreed <reed@google.com>
Wed, 10 Feb 2016 16:53:15 +0000 (08:53 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 10 Feb 2016 16:53:15 +0000 (08:53 -0800)
next steps:
1. this lands
2. update android to call the new factory
3. move SkComposeShader.h into private

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1686803003

Review URL: https://codereview.chromium.org/1686803003

include/core/SkShader.h
src/core/SkComposeShader.cpp

index 297091d54206fe64b427f5760c70bb8a07086d81..36256f6f09e4e73cc9d7e22d31982e6b1aecfc07 100644 (file)
@@ -323,7 +323,7 @@ public:
      *  the colorfilter.
      */
     SkShader* newWithColorFilter(SkColorFilter*) const;
-    
+
     //////////////////////////////////////////////////////////////////////////
     //  Factory methods for stock shaders
     
@@ -338,6 +338,18 @@ public:
      */
     static SkShader* CreateColorShader(SkColor);
 
+    static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode::Mode);
+
+    /**
+     *  Create a new compose shader, given shaders dst, src, and a combining xfermode mode.
+     *  The xfermode is called with the output of the two shaders, and its output is returned.
+     *  If xfer is null, SkXfermode::kSrcOver_Mode is assumed.
+     *
+     *  Ownership of the shaders, and the xfermode if not null, is not transfered, so the caller
+     *  is still responsible for managing its reference-count for those objects.
+     */
+    static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode* xfer);
+
     /** Call this to create a new shader that will draw with the specified bitmap.
      *
      *  If the bitmap cannot be used (e.g. has no pixels, or its dimensions
index d433ff2d435077ced0a3bdff7ec851c62082e54e..c49d8a48ae261e202d523835fe1753d650824a64 100644 (file)
@@ -252,3 +252,17 @@ void SkComposeShader::toString(SkString* str) const {
     str->append(")");
 }
 #endif
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode* xfer) {
+    if (!dst || !src) {
+        return nullptr;
+    }
+    return new SkComposeShader(dst, src, xfer);
+}
+
+SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode::Mode mode) {
+    SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode));
+    return CreateComposeShader(dst, src, xfer);
+}