2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkUtils_DEFINED
|
|
|
|
#define SkUtils_DEFINED
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2011-04-10 01:04:37 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Similar to memset(), but it assigns a 16bit value into the buffer.
|
|
|
|
@param buffer The memory to have value copied into it
|
|
|
|
@param value The 16bit value to be copied into buffer
|
|
|
|
@param count The number of times value should be copied into the buffer.
|
|
|
|
*/
|
Choose memset procs once.
TSAN shows us racing on the function pointers. Might as well fix it.
WARNING: ThreadSanitizer: data race (pid=19995)
Read of size 8 at 0x7f703affb048 by thread T12 (mutexes: write M2957):
#0 SkBitmap::internalErase(SkIRect const&, unsigned int, unsigned int, unsigned int, unsigned int) const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:886 (tests+0x0000003511ca)
#1 SkBitmap::eraseARGB(unsigned int, unsigned int, unsigned int, unsigned int) const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:919 (tests+0x0000003534bf)
#2 (anonymous namespace)::DecodingImageGenerator::getPixels(SkImageInfo const&, void*, unsigned long) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/images/SkDecodingImageGenerator.cpp:195 (tests+0x00000051bee1)
#3 SkDiscardablePixelRef::onNewLockPixels(SkPixelRef::LockRec*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/lazy/SkDiscardablePixelRef.cpp:63 (tests+0x00000039ad9c)
#4 SkPixelRef::lockPixels(SkPixelRef::LockRec*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkPixelRef.cpp:179 (tests+0x0000003fec23)
#5 SkBitmap::lockPixels() const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:414 (tests+0x00000034e41e)
#6 SkAutoLockPixels /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/include/core/SkBitmap.h:819 (tests+0x0000002752f3)
#7 ImageDecoderOptions(skiatest::Reporter*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/ImageDecodingTest.cpp:565 (tests+0x000000275d03)
#8 skiatest::Test::run() /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/Test.cpp:107 (tests+0x0000002263e7)
#9 SkTestRunnable::run() /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/skia_test.cpp:108 (tests+0x0000001d8607)
#10 SkThreadPoolPrivate::ThreadLocal<void>::run(SkTRunnable<void>*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/include/utils/SkThreadPool.h:108 (tests+0x0000001d817e)
#11 thread_start(void*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/utils/SkThreadUtils_pthread.cpp:66 (tests+0x000000604347)
Previous write of size 8 at 0x7f703affb048 by thread T26:
[failed to restore the stack]
BUG=skia:1792
R=bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/250503003
git-svn-id: http://skia.googlecode.com/svn/trunk@14548 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-05-02 20:28:56 +00:00
|
|
|
void sk_memset16(uint16_t dst[], uint16_t value, int count);
|
2009-11-16 21:09:00 +00:00
|
|
|
typedef void (*SkMemset16Proc)(uint16_t dst[], uint16_t value, int count);
|
|
|
|
SkMemset16Proc SkMemset16GetPlatformProc();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Similar to memset(), but it assigns a 32bit value into the buffer.
|
|
|
|
@param buffer The memory to have value copied into it
|
|
|
|
@param value The 32bit value to be copied into buffer
|
|
|
|
@param count The number of times value should be copied into the buffer.
|
|
|
|
*/
|
Choose memset procs once.
TSAN shows us racing on the function pointers. Might as well fix it.
WARNING: ThreadSanitizer: data race (pid=19995)
Read of size 8 at 0x7f703affb048 by thread T12 (mutexes: write M2957):
#0 SkBitmap::internalErase(SkIRect const&, unsigned int, unsigned int, unsigned int, unsigned int) const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:886 (tests+0x0000003511ca)
#1 SkBitmap::eraseARGB(unsigned int, unsigned int, unsigned int, unsigned int) const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:919 (tests+0x0000003534bf)
#2 (anonymous namespace)::DecodingImageGenerator::getPixels(SkImageInfo const&, void*, unsigned long) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/images/SkDecodingImageGenerator.cpp:195 (tests+0x00000051bee1)
#3 SkDiscardablePixelRef::onNewLockPixels(SkPixelRef::LockRec*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/lazy/SkDiscardablePixelRef.cpp:63 (tests+0x00000039ad9c)
#4 SkPixelRef::lockPixels(SkPixelRef::LockRec*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkPixelRef.cpp:179 (tests+0x0000003fec23)
#5 SkBitmap::lockPixels() const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:414 (tests+0x00000034e41e)
#6 SkAutoLockPixels /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/include/core/SkBitmap.h:819 (tests+0x0000002752f3)
#7 ImageDecoderOptions(skiatest::Reporter*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/ImageDecodingTest.cpp:565 (tests+0x000000275d03)
#8 skiatest::Test::run() /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/Test.cpp:107 (tests+0x0000002263e7)
#9 SkTestRunnable::run() /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/skia_test.cpp:108 (tests+0x0000001d8607)
#10 SkThreadPoolPrivate::ThreadLocal<void>::run(SkTRunnable<void>*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/include/utils/SkThreadPool.h:108 (tests+0x0000001d817e)
#11 thread_start(void*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/utils/SkThreadUtils_pthread.cpp:66 (tests+0x000000604347)
Previous write of size 8 at 0x7f703affb048 by thread T26:
[failed to restore the stack]
BUG=skia:1792
R=bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/250503003
git-svn-id: http://skia.googlecode.com/svn/trunk@14548 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-05-02 20:28:56 +00:00
|
|
|
void sk_memset32(uint32_t dst[], uint32_t value, int count);
|
2009-11-16 21:09:00 +00:00
|
|
|
typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count);
|
|
|
|
SkMemset32Proc SkMemset32GetPlatformProc();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-05-21 12:43:07 +00:00
|
|
|
/** Similar to memcpy(), but it copies count 32bit values from src to dst.
|
|
|
|
@param dst The memory to have value copied into it
|
|
|
|
@param src The memory to have value copied from it
|
|
|
|
@param count The number of values should be copied.
|
|
|
|
*/
|
|
|
|
void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count);
|
|
|
|
typedef void (*SkMemcpy32Proc)(uint32_t dst[], const uint32_t src[], int count);
|
|
|
|
SkMemcpy32Proc SkMemcpy32GetPlatformProc();
|
|
|
|
|
2011-04-10 01:04:37 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#define kMaxBytesInUTF8Sequence 4
|
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
int SkUTF8_LeadByteToCount(unsigned c);
|
|
|
|
#else
|
|
|
|
#define SkUTF8_LeadByteToCount(c) ((((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1)
|
|
|
|
#endif
|
|
|
|
|
2011-04-10 01:04:37 +00:00
|
|
|
inline int SkUTF8_CountUTF8Bytes(const char utf8[]) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkASSERT(utf8);
|
|
|
|
return SkUTF8_LeadByteToCount(*(const uint8_t*)utf8);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SkUTF8_CountUnichars(const char utf8[]);
|
|
|
|
int SkUTF8_CountUnichars(const char utf8[], size_t byteLength);
|
|
|
|
SkUnichar SkUTF8_ToUnichar(const char utf8[]);
|
|
|
|
SkUnichar SkUTF8_NextUnichar(const char**);
|
|
|
|
SkUnichar SkUTF8_PrevUnichar(const char**);
|
|
|
|
|
|
|
|
/** Return the number of bytes need to convert a unichar
|
|
|
|
into a utf8 sequence. Will be 1..kMaxBytesInUTF8Sequence,
|
|
|
|
or 0 if uni is illegal.
|
|
|
|
*/
|
|
|
|
size_t SkUTF8_FromUnichar(SkUnichar uni, char utf8[] = NULL);
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define SkUTF16_IsHighSurrogate(c) (((c) & 0xFC00) == 0xD800)
|
|
|
|
#define SkUTF16_IsLowSurrogate(c) (((c) & 0xFC00) == 0xDC00)
|
|
|
|
|
|
|
|
int SkUTF16_CountUnichars(const uint16_t utf16[]);
|
2013-11-21 14:24:16 +00:00
|
|
|
int SkUTF16_CountUnichars(const uint16_t utf16[], int numberOf16BitValues);
|
2008-12-17 15:59:43 +00:00
|
|
|
// returns the current unichar and then moves past it (*p++)
|
|
|
|
SkUnichar SkUTF16_NextUnichar(const uint16_t**);
|
|
|
|
// this guy backs up to the previus unichar value, and returns it (*--p)
|
|
|
|
SkUnichar SkUTF16_PrevUnichar(const uint16_t**);
|
|
|
|
size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL);
|
|
|
|
|
|
|
|
size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues,
|
2013-11-21 14:24:16 +00:00
|
|
|
char utf8[] = NULL);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-12-21 16:31:23 +00:00
|
|
|
inline bool SkUnichar_IsVariationSelector(SkUnichar uni) {
|
2011-12-21 15:21:32 +00:00
|
|
|
/* The 'true' ranges are:
|
|
|
|
* 0x180B <= uni <= 0x180D
|
|
|
|
* 0xFE00 <= uni <= 0xFE0F
|
|
|
|
* 0xE0100 <= uni <= 0xE01EF
|
|
|
|
*/
|
|
|
|
if (uni < 0x180B || uni > 0xE01EF) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((uni > 0x180D && uni < 0xFE00) || (uni > 0xFE0F && uni < 0xE0100)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class SkAutoTrace {
|
|
|
|
public:
|
|
|
|
/** NOTE: label contents are not copied, just the ptr is
|
|
|
|
retained, so DON'T DELETE IT.
|
|
|
|
*/
|
|
|
|
SkAutoTrace(const char label[]) : fLabel(label) {
|
|
|
|
SkDebugf("--- trace: %s Enter\n", fLabel);
|
|
|
|
}
|
|
|
|
~SkAutoTrace() {
|
|
|
|
SkDebugf("--- trace: %s Leave\n", fLabel);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
const char* fLabel;
|
|
|
|
};
|
2013-11-18 16:03:59 +00:00
|
|
|
#define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace)
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#endif
|