From bc55eec80ef376208b3c1bfc65d8dc8b672d59f0 Mon Sep 17 00:00:00 2001 From: "halcanary@google.com" Date: Tue, 10 Dec 2013 18:33:07 +0000 Subject: Implement SkAshmemDiscardableMemory - Implement ashmem-backed SkDiscardableMemory subclass: This class in only accesible via the SkDiscardableMemory::Create() function, which replaces the mock implementation in SkDiscardableMemory_none.cpp - Added SkDiscardableMemory_ashmem.cpp to the Android port of Skia Removed SkDiscardableMemory_none.cpp from the Android port. - Added DiscardableMemoryTest. Still needs work. - SkDiscardablePixelRef Bugfix: onLockPixels() now calls SkDELETE on the SkDiscardableMemory pointer when it fails to unlock. - Improved documentation inside ashmem.h BUG= R=scroggo@google.com Review URL: https://codereview.chromium.org/83563002 git-svn-id: http://skia.googlecode.com/svn/trunk@12608 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/DiscardableMemoryTest.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/DiscardableMemoryTest.cpp (limited to 'tests/DiscardableMemoryTest.cpp') diff --git a/tests/DiscardableMemoryTest.cpp b/tests/DiscardableMemoryTest.cpp new file mode 100644 index 0000000000..1fbc28478f --- /dev/null +++ b/tests/DiscardableMemoryTest.cpp @@ -0,0 +1,34 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkDiscardableMemory.h" + +#include "Test.h" +#include "TestClassDef.h" + +DEF_TEST(DiscardableMemory, reporter) { + const char testString[] = "HELLO, WORLD!"; + const size_t len = sizeof(testString); + SkAutoTDelete dm(SkDiscardableMemory::Create(len)); + REPORTER_ASSERT(reporter, dm.get() != NULL); + if (NULL == dm.get()) { + return; + } + void* ptr = dm->data(); + REPORTER_ASSERT(reporter, ptr != NULL); + memcpy(ptr, testString, sizeof(testString)); + dm->unlock(); + bool success = dm->lock(); + REPORTER_ASSERT(reporter, success); + if (!success) { + return; + } + ptr = dm->data(); + REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, len)); + dm->unlock(); +} + -- cgit v1.2.3