Class ColorShader

java.lang.Object
icyllis.arc3d.sketch.shaders.ColorShader
All Implemented Interfaces:
RefCounted, Shader

public final class ColorShader extends Object implements Shader
A Shader that represents a single color. In general, this effect can be accomplished by just using the color field on the paint, but if an actual shader object is needed, this provides that feature. Note: like all shaders, at draw time the paint's alpha will be respected, and is applied to the specified color.
  • Constructor Details

    • ColorShader

      public ColorShader(int color)
      Create a ColorShader wrapping the given sRGB color.
    • ColorShader

      @VisibleForTesting public ColorShader(float r, float g, float b, float a)
      Create a ColorShader wrapping the given sRGB color.
  • Method Details

    • make

      @Contract(pure=true) @SharedPtr public static @SharedPtr @Nullable Shader make(@Size(4L) float @NonNull [] color, @Nullable ColorSpace space)
    • make

      @Contract(pure=true) @SharedPtr public static @SharedPtr @Nullable Shader make(float r, float g, float b, float a, @Nullable ColorSpace space)
    • isOpaque

      public boolean isOpaque()
      Description copied from interface: Shader
      Returns true if the shader is guaranteed to produce only opaque colors, subject to the Paint using the shader to apply an opaque alpha value. Subclasses should override this to allow some optimizations.
      Specified by:
      isOpaque in interface Shader
    • isConstant

      public boolean isConstant()
      Returns true if the shader is guaranteed to produce only a single color. Subclasses can override this to allow loop-hoisting optimization.
      Specified by:
      isConstant in interface Shader
    • getColor

      @Contract(value=" -> new", pure=true) public float @NonNull [] getColor()
      Returns:
      a copy of non-premultiplied color.