From 9c970453fd1cb6e9618e37c61507465772deca80 Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Fri, 3 Apr 2009 14:26:10 +0000 Subject: import portability fixes from Chrome around floats move porting functions for SkDebugf into /ports directory git-svn-id: http://skia.googlecode.com/svn/trunk@147 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkDebug_stdio.cpp | 61 ------------------------------------------- src/core/SkDrawing.cpp | 36 ++++++++++++------------- src/core/SkFP.h | 2 +- src/core/core_files.mk | 1 - src/effects/SkEmbossMask.cpp | 2 +- src/ports/SkDebug_android.cpp | 43 ++++++++++++++++++++++++++++++ src/ports/SkDebug_stdio.cpp | 33 +++++++++++++++++++++++ src/ports/ports_files.mk | 1 + 8 files changed, 97 insertions(+), 82 deletions(-) delete mode 100644 src/core/SkDebug_stdio.cpp create mode 100644 src/ports/SkDebug_android.cpp create mode 100644 src/ports/SkDebug_stdio.cpp (limited to 'src') diff --git a/src/core/SkDebug_stdio.cpp b/src/core/SkDebug_stdio.cpp deleted file mode 100644 index c8a0d8123e..0000000000 --- a/src/core/SkDebug_stdio.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* libs/corecg/SkDebug_stdio.cpp -** -** Copyright 2006, The Android Open Source Project -** -** 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 "SkTypes.h" - -static const size_t kBufferSize = 256; - -#ifdef ANDROID - -#define LOG_TAG "skia" -#include - -void Android_SkDebugf(const char* file, int line, const char* function, - const char* format, ...) -{ - if (format[0] == '\n' && format[1] == '\0') - return; - va_list args; - va_start(args, format); -#ifdef HAVE_ANDROID_OS - char buffer[kBufferSize + 1]; - vsnprintf(buffer, kBufferSize, format, args); - if (buffer[0] != 0) - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "%s", buffer); -#else - android_vprintLog(ANDROID_LOG_DEBUG, NULL, LOG_TAG, format, args); -#endif - va_end(args); -} - -#else - -#include -#include - -void SkDebugf(const char format[], ...) -{ - char buffer[kBufferSize + 1]; - va_list args; - va_start(args, format); - vsnprintf(buffer, kBufferSize, format, args); - va_end(args); - fprintf(stderr, buffer); -} - -#endif - diff --git a/src/core/SkDrawing.cpp b/src/core/SkDrawing.cpp index 85f3175bdb..f54afcc1f4 100644 --- a/src/core/SkDrawing.cpp +++ b/src/core/SkDrawing.cpp @@ -1,28 +1,28 @@ -#include "SkDrawable.h" +#include "SkDrawing.h" #include "SkCanvas.h" -SkDrawable::SkDrawable() { +SkDrawing::SkDrawing() { fMatrix.reset(); fParent = fFirstChild = fNextSibling = fPrevSibling = NULL; } -SkDrawable::~SkDrawable() { +SkDrawing::~SkDrawing() { this->detachAllChildren(); } /////////////////////////////////////////////////////////////////////////////// -void SkDrawable::resetMatrix() { +void SkDrawing::resetMatrix() { fMatrix.reset(); } -void SkDrawable::getMatrix(SkMatrix* matrix) const { +void SkDrawing::getMatrix(SkMatrix* matrix) const { if (matrix) { *matrix = fMatrix; } } -void SkDrawable::setMatrix(const SkMatrix& matrix) { +void SkDrawing::setMatrix(const SkMatrix& matrix) { if (fMatrix != matrix) { this->inval(); fMatrix = matrix; @@ -30,7 +30,7 @@ void SkDrawable::setMatrix(const SkMatrix& matrix) { } } -void SkDrawable::draw(SkCanvas* canvas) { +void SkDrawing::draw(SkCanvas* canvas) { SkAutoCanvasRestore ar(canvas, false); canvas->save(SkCanvas::kMatrix_SaveFlag); canvas->concat(fMatrix); @@ -38,7 +38,7 @@ void SkDrawable::draw(SkCanvas* canvas) { this->onDraw(canvas); B2FIter iter(this); - SkDrawable* child; + SkDrawing* child; while ((child = iter.next()) != NULL) { child->draw(canvas); } @@ -46,8 +46,8 @@ void SkDrawable::draw(SkCanvas* canvas) { /////////////////////////////////////////////////////////////////////////////// -void SkDrawable::detachFromParent() { - SkDrawable* parent = fParent; +void SkDrawing::detachFromParent() { + SkDrawing* parent = fParent; if (NULL == parent) { return; @@ -55,7 +55,7 @@ void SkDrawable::detachFromParent() { this->inval(); - SkDrawable* next = NULL; + SkDrawing* next = NULL; if (fNextSibling != this) { // do we have any siblings fNextSibling->fPrevSibling = fPrevSibling; @@ -71,7 +71,7 @@ void SkDrawable::detachFromParent() { this->unref(); } -SkDrawable* SkDrawable::attachChildToBack(SkDrawable* child) { +SkDrawing* SkDrawing::attachChildToBack(SkDrawing* child) { SkASSERT(child != this); if (child == NULL || fFirstChild == child) { @@ -97,7 +97,7 @@ SkDrawable* SkDrawable::attachChildToBack(SkDrawable* child) { return child; } -SkDrawable* SkDrawable::attachChildToFront(SkDrawable* child) { +SkDrawing* SkDrawing::attachChildToFront(SkDrawing* child) { SkASSERT(child != this); if (child == NULL || fFirstChild && fFirstChild->fPrevSibling == child) { @@ -123,7 +123,7 @@ SkDrawable* SkDrawable::attachChildToFront(SkDrawable* child) { return child; } -void SkDrawable::detachAllChildren() { +void SkDrawing::detachAllChildren() { while (fFirstChild) { fFirstChild->detachFromParent(); } @@ -131,16 +131,16 @@ void SkDrawable::detachAllChildren() { /////////////////////////////////////////////////////////////////////////////// -SkDrawable::B2FIter::B2FIter(const SkDrawable* parent) { +SkDrawing::B2FIter::B2FIter(const SkDrawing* parent) { fFirstChild = parent ? parent->fFirstChild : NULL; fChild = fFirstChild; } -SkDrawable* SkDrawable::B2FIter::next() { - SkDrawable* curr = fChild; +SkDrawing* SkDrawing::B2FIter::next() { + SkDrawing* curr = fChild; if (fChild) { - SkDrawable* next = fChild->fNextSibling; + SkDrawing* next = fChild->fNextSibling; if (next == fFirstChild) { next = NULL; } diff --git a/src/core/SkFP.h b/src/core/SkFP.h index 5e25d22372..3aab411ace 100644 --- a/src/core/SkFP.h +++ b/src/core/SkFP.h @@ -41,7 +41,7 @@ #define SkFPDivInt(a, n) ((a) / (n)) #define SkFPInvert(x) SkScalarInvert(x) #define SkFPSqrt(x) SkScalarSqrt(x) - #define SkFPCubeRoot(x) static_cast(pow(x, 0.33333333333)) + #define SkFPCubeRoot(x) sk_float_pow(x, 0.3333333f) #define SkFPLT(a, b) ((a) < (b)) #define SkFPLE(a, b) ((a) <= (b)) diff --git a/src/core/core_files.mk b/src/core/core_files.mk index 37c55e1800..27849e7021 100644 --- a/src/core/core_files.mk +++ b/src/core/core_files.mk @@ -27,7 +27,6 @@ SOURCE := \ SkCordic.cpp \ SkCubicClipper.cpp \ SkDebug.cpp \ - SkDebug_stdio.cpp \ SkDeque.cpp \ SkDevice.cpp \ SkDither.cpp \ diff --git a/src/effects/SkEmbossMask.cpp b/src/effects/SkEmbossMask.cpp index 28e38a142f..fd11f543b0 100644 --- a/src/effects/SkEmbossMask.cpp +++ b/src/effects/SkEmbossMask.cpp @@ -75,7 +75,7 @@ void SkEmbossMask_BuildTable() if ((dy & 15) == 0) ::fprintf(file, "\t"); - U16 value = SkToU16((1 << 15) / SkSqrt32(dx * dx + dy * dy + kDelta*kDelta/4)); + uint16_t value = SkToU16((1 << 15) / SkSqrt32(dx * dx + dy * dy + kDelta*kDelta/4)); ::fprintf(file, "0x%04X", value); if (dx * 128 + dy < 128*128-1) diff --git a/src/ports/SkDebug_android.cpp b/src/ports/SkDebug_android.cpp new file mode 100644 index 0000000000..f1fd34f004 --- /dev/null +++ b/src/ports/SkDebug_android.cpp @@ -0,0 +1,43 @@ +/* libs/corecg/SkDebug_stdio.cpp +** +** Copyright 2006, The Android Open Source Project +** +** 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 "SkTypes.h" + +static const size_t kBufferSize = 256; + +#define LOG_TAG "skia" +#include + +void Android_SkDebugf(const char* file, int line, const char* function, + const char* format, ...) +{ + if (format[0] == '\n' && format[1] == '\0') + return; + va_list args; + va_start(args, format); +#ifdef HAVE_ANDROID_OS + char buffer[kBufferSize + 1]; + vsnprintf(buffer, kBufferSize, format, args); + if (buffer[0] != 0) + __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "%s", buffer); +#else + android_vprintLog(ANDROID_LOG_DEBUG, NULL, LOG_TAG, format, args); +#endif + va_end(args); +} + + diff --git a/src/ports/SkDebug_stdio.cpp b/src/ports/SkDebug_stdio.cpp new file mode 100644 index 0000000000..f5bf687644 --- /dev/null +++ b/src/ports/SkDebug_stdio.cpp @@ -0,0 +1,33 @@ +/* libs/corecg/SkDebug_stdio.cpp +** +** Copyright 2006, The Android Open Source Project +** +** 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 "SkTypes.h" + +static const size_t kBufferSize = 256; + +#include +#include + +void SkDebugf(const char format[], ...) { + char buffer[kBufferSize + 1]; + va_list args; + va_start(args, format); + vsnprintf(buffer, kBufferSize, format, args); + va_end(args); + fprintf(stderr, buffer); +} + diff --git a/src/ports/ports_files.mk b/src/ports/ports_files.mk index 07dacfa244..8760ae11f5 100644 --- a/src/ports/ports_files.mk +++ b/src/ports/ports_files.mk @@ -1,4 +1,5 @@ SOURCE := \ + SkDebug_stdio.cpp \ SkFontHost_none.cpp \ SkGlobals_global.cpp \ SkOSFile_stdio.cpp \ -- cgit v1.2.3