Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 288c8711 authored by Jim Shuma's avatar Jim Shuma
Browse files

Making Program*.Builder classes' setters return 'this'

This is for better correspondence with the Builder pattern.
See also: Effective Java, 2nd edition.

Change-Id: Iecccd42be49dea2ed8e4b8cc38ce96379cf3c11c
parent d0d5c072
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -91,8 +91,9 @@ public class Program extends BaseObj {
            mTextureCount = 0;
        }

        public void setShader(String s) {
        public BaseProgramBuilder setShader(String s) {
            mShader = s;
            return this;
        }

        public void addInput(Element e) throws IllegalStateException {
@@ -120,12 +121,13 @@ public class Program extends BaseObj {
            return mConstantCount++;
        }

        public void setTextureCount(int count) throws IllegalArgumentException {
        public BaseProgramBuilder setTextureCount(int count) throws IllegalArgumentException {
            // Should check for consistant and non-conflicting names...
            if(count >= MAX_CONSTANT) {
                throw new IllegalArgumentException("Max texture count exceeded.");
            }
            mTextureCount = count;
            return this;
        }

        protected void initProgram(Program p) {
+4 −2
Original line number Diff line number Diff line
@@ -106,16 +106,18 @@ public class ProgramFragment extends Program {
            mPointSpriteEnable = false;
        }

        public void setTexture(EnvMode env, Format fmt, int slot)
        public Builder setTexture(EnvMode env, Format fmt, int slot)
            throws IllegalArgumentException {
            if((slot < 0) || (slot >= MAX_TEXTURE)) {
                throw new IllegalArgumentException("MAX_TEXTURE exceeded.");
            }
            mSlots[slot] = new Slot(env, fmt);
            return this;
        }

        public void setPointSpriteTexCoordinateReplacement(boolean enable) {
        public Builder setPointSpriteTexCoordinateReplacement(boolean enable) {
            mPointSpriteEnable = enable;
            return this;
        }

        public ProgramFragment create() {
+6 −3
Original line number Diff line number Diff line
@@ -89,16 +89,19 @@ public class ProgramRaster extends BaseObj {
            mPointSprite = false;
        }

        public void setPointSpriteEnable(boolean enable) {
        public Builder setPointSpriteEnable(boolean enable) {
            mPointSprite = enable;
            return this;
        }

        public void setPointSmoothEnable(boolean enable) {
        public Builder setPointSmoothEnable(boolean enable) {
            mPointSmooth = enable;
            return this;
        }

        public void setLineSmoothEnable(boolean enable) {
        public Builder setLineSmoothEnable(boolean enable) {
            mLineSmooth = enable;
            return this;
        }

        static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) {
+10 −5
Original line number Diff line number Diff line
@@ -114,28 +114,33 @@ public class ProgramStore extends BaseObj {

        }

        public void setDepthFunc(DepthFunc func) {
        public Builder setDepthFunc(DepthFunc func) {
            mDepthFunc = func;
            return this;
        }

        public void setDepthMask(boolean enable) {
        public Builder setDepthMask(boolean enable) {
            mDepthMask = enable;
            return this;
        }

        public void setColorMask(boolean r, boolean g, boolean b, boolean a) {
        public Builder setColorMask(boolean r, boolean g, boolean b, boolean a) {
            mColorMaskR = r;
            mColorMaskG = g;
            mColorMaskB = b;
            mColorMaskA = a;
            return this;
        }

        public void setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
        public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
            mBlendSrc = src;
            mBlendDst = dst;
            return this;
        }

        public void setDitherEnable(boolean enable) {
        public Builder setDitherEnable(boolean enable) {
            mDither = enable;
            return this;
        }

        static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
+2 −1
Original line number Diff line number Diff line
@@ -47,8 +47,9 @@ public class ProgramVertex extends Program {
            mRS = rs;
        }

        public void setTextureMatrixEnable(boolean enable) {
        public Builder setTextureMatrixEnable(boolean enable) {
            mTextureMatrixEnable = enable;
            return this;
        }

        public ProgramVertex create() {