diff options
author | 2011-01-25 23:50:57 +0000 | |
---|---|---|
committer | 2011-01-25 23:50:57 +0000 | |
commit | 3636ed558fb2af5a48a9634efec55fd8a87c88d7 (patch) | |
tree | c071bddf09196e6adc25b5cd5eaa89d44ba6ba88 | |
parent | 0e190d0e126991cfba4bc7415c1911761d7be87b (diff) |
embed a refdict inside SkDevice
udate unittests to test refdict's destructor
git-svn-id: http://skia.googlecode.com/svn/trunk@731 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkDevice.h | 10 | ||||
-rw-r--r-- | include/core/SkRefDict.h | 16 | ||||
-rw-r--r-- | src/core/SkRefDict.cpp | 16 | ||||
-rw-r--r-- | tests/RefDictTest.cpp | 14 | ||||
-rw-r--r-- | xcode/core/core.xcodeproj/project.pbxproj | 4 |
5 files changed, 58 insertions, 2 deletions
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index ec620334a6..b9a96d9aae 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -21,6 +21,7 @@ #include "SkBitmap.h" #include "SkCanvas.h" #include "SkColor.h" +#include "SkRefDict.h" class SkDevice; class SkDraw; @@ -184,6 +185,10 @@ public: virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, const SkPaint&); + /////////////////////////////////////////////////////////////////////////// + + SkRefDict& getRefDict() { return fRefDict; } + protected: /** Update as needed the pixel value in the bitmap, so that the caller can access the pixels directly. Note: only the pixels field should be altered. The config/width/height/rowbytes @@ -199,8 +204,9 @@ protected: } private: - SkCanvas* fCanvas; - SkBitmap fBitmap; + SkCanvas* fCanvas; + SkBitmap fBitmap; + SkRefDict fRefDict; }; #endif diff --git a/include/core/SkRefDict.h b/include/core/SkRefDict.h index c66f808b5d..3ee27d91b0 100644 --- a/include/core/SkRefDict.h +++ b/include/core/SkRefDict.h @@ -1,3 +1,19 @@ +/* + Copyright 2011 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + #ifndef SkRefDict_DEFINED #define SkRefDict_DEFINED diff --git a/src/core/SkRefDict.cpp b/src/core/SkRefDict.cpp index 572ed7e180..6f1e7ca378 100644 --- a/src/core/SkRefDict.cpp +++ b/src/core/SkRefDict.cpp @@ -1,3 +1,19 @@ +/* + Copyright 2011 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + #include "SkRefDict.h" #include "SkString.h" diff --git a/tests/RefDictTest.cpp b/tests/RefDictTest.cpp index 61f64e9a2c..f52541b0bb 100644 --- a/tests/RefDictTest.cpp +++ b/tests/RefDictTest.cpp @@ -46,6 +46,20 @@ static void TestRefDict(skiatest::Reporter* reporter) { dict.removeAll(); REPORTER_ASSERT(reporter, NULL == dict.find("foo")); REPORTER_ASSERT(reporter, NULL == dict.find("bar")); + REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); + REPORTER_ASSERT(reporter, 1 == data1.getRefCnt()); + + { + SkRefDict d; + REPORTER_ASSERT(reporter, NULL == d.find("foo")); + REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); + d.set("foo", &data0); + REPORTER_ASSERT(reporter, &data0 == d.find("foo")); + REPORTER_ASSERT(reporter, 2 == data0.getRefCnt()); + // let d go out of scope still with a ref on data0 + } + // be sure d's destructor lowered data0's owner count back to 1 + REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); } #include "TestClassDef.h" diff --git a/xcode/core/core.xcodeproj/project.pbxproj b/xcode/core/core.xcodeproj/project.pbxproj index 1f24d0138b..3c468fa19f 100644 --- a/xcode/core/core.xcodeproj/project.pbxproj +++ b/xcode/core/core.xcodeproj/project.pbxproj @@ -124,6 +124,7 @@ 005F25E60EF94F7900582A90 /* SkWriter32.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F256D0EF94F7900582A90 /* SkWriter32.cpp */; }; 005F25E70EF94F7900582A90 /* SkXfermode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F256E0EF94F7900582A90 /* SkXfermode.cpp */; }; 005F26960EF955D400582A90 /* SkComposeShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F26950EF955D400582A90 /* SkComposeShader.cpp */; }; + 006EB61412EF97E100686979 /* SkRefDict.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 006EB61312EF97E100686979 /* SkRefDict.cpp */; }; 007C786A0F3B4D5F0004B142 /* SkQuadClipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 007C78690F3B4D5F0004B142 /* SkQuadClipper.cpp */; }; 008AE3D612E4A3D6002516FE /* opts_check_SSE2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 008AE3D112E4A3D6002516FE /* opts_check_SSE2.cpp */; }; 008AE3D712E4A3D6002516FE /* SkBitmapProcState_opts_SSE2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 008AE3D212E4A3D6002516FE /* SkBitmapProcState_opts_SSE2.cpp */; }; @@ -259,6 +260,7 @@ 005F256D0EF94F7900582A90 /* SkWriter32.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkWriter32.cpp; path = ../../src/core/SkWriter32.cpp; sourceTree = SOURCE_ROOT; }; 005F256E0EF94F7900582A90 /* SkXfermode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkXfermode.cpp; path = ../../src/core/SkXfermode.cpp; sourceTree = SOURCE_ROOT; }; 005F26950EF955D400582A90 /* SkComposeShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkComposeShader.cpp; path = ../../src/core/SkComposeShader.cpp; sourceTree = SOURCE_ROOT; }; + 006EB61312EF97E100686979 /* SkRefDict.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkRefDict.cpp; path = ../../src/core/SkRefDict.cpp; sourceTree = SOURCE_ROOT; }; 007C78690F3B4D5F0004B142 /* SkQuadClipper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkQuadClipper.cpp; path = ../../src/core/SkQuadClipper.cpp; sourceTree = SOURCE_ROOT; }; 008AE3D112E4A3D6002516FE /* opts_check_SSE2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = opts_check_SSE2.cpp; path = ../../src/opts/opts_check_SSE2.cpp; sourceTree = SOURCE_ROOT; }; 008AE3D212E4A3D6002516FE /* SkBitmapProcState_opts_SSE2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkBitmapProcState_opts_SSE2.cpp; path = ../../src/opts/SkBitmapProcState_opts_SSE2.cpp; sourceTree = SOURCE_ROOT; }; @@ -340,6 +342,7 @@ 08FB7795FE84155DC02AAC07 /* src */ = { isa = PBXGroup; children = ( + 006EB61312EF97E100686979 /* SkRefDict.cpp */, 00B5785E12BFDC2A00393BE9 /* SkFlate.cpp */, 277670F312B840CA006811C2 /* SkRegion_rects.cpp */, 277670F412B840CA006811C2 /* SkScalar.cpp */, @@ -673,6 +676,7 @@ 008AE3D712E4A3D6002516FE /* SkBitmapProcState_opts_SSE2.cpp in Sources */, 008AE3D812E4A3D6002516FE /* SkBlitRow_opts_SSE2.cpp in Sources */, 008AE3DA12E4A3D6002516FE /* SkUtils_opts_SSE2.cpp in Sources */, + 006EB61412EF97E100686979 /* SkRefDict.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |