Use element-by-element assignment in GrSamplerState::operator= instead of memcpy
authortomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 31 May 2012 14:23:28 +0000 (14:23 +0000)
committertomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 31 May 2012 14:23:28 +0000 (14:23 +0000)
so that we can handle refcounting correctly.

http://codereview.appspot.com/6262049/

git-svn-id: http://skia.googlecode.com/svn/trunk@4092 2bbb7eff-a529-9590-31e7-b0007b416f81

include/gpu/GrSamplerState.h

index a481502..618b0b1 100644 (file)
@@ -140,7 +140,28 @@ public:
     bool operator !=(const GrSamplerState& s) const { return !(*this == s); }
 
     GrSamplerState& operator =(const GrSamplerState s) {
-        memcpy(this, &s, sizeof(GrSamplerState));
+        // memcpy() breaks refcounting
+        fWrapX = s.fWrapX;
+        fWrapY = s.fWrapY;
+        fFilterDirection = s.fFilterDirection;
+        fSampleMode = s.fSampleMode;
+        fFilter = s.fFilter;
+        fMatrix = s.fMatrix;
+        fSwapRAndB = s.fSwapRAndB;
+        fTextureDomain = s.fTextureDomain;
+
+        fRadial2CenterX1 = s.fRadial2CenterX1;
+        fRadial2Radius0 = s.fRadial2Radius0;
+        fRadial2PosRoot = s.fRadial2PosRoot;
+
+        fKernelWidth = s.fKernelWidth;
+        if (kConvolution_Filter == kFilter) {
+            memcpy(fKernel, s.fKernel, MAX_KERNEL_WIDTH * sizeof(float));
+        }
+
+        fCustomStage = s.fCustomStage;
+        SkSafeRef(fCustomStage);
+
         return *this;
     }