import portability fixes from Chrome around floats
authorreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 3 Apr 2009 14:26:10 +0000 (14:26 +0000)
committerreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 3 Apr 2009 14:26:10 +0000 (14:26 +0000)
move porting functions for SkDebugf into /ports directory

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

include/core/SkFloatingPoint.h
src/core/SkDrawing.cpp
src/core/SkFP.h
src/core/core_files.mk
src/effects/SkEmbossMask.cpp
src/ports/SkDebug_android.cpp [moved from src/core/SkDebug_stdio.cpp with 81% similarity]
src/ports/SkDebug_stdio.cpp [new file with mode: 0644]
src/ports/ports_files.mk
xcode/core/core.xcodeproj/project.pbxproj
xcode/maccore/maccore.xcodeproj/project.pbxproj

index 68bf6ef..e6856cf 100644 (file)
 #include <float.h>
 #include "SkFloatBits.h"
 
+// If math.h had powf(float, float), I could remove this wrapper
+static inline float sk_float_pow(float base, float exp) {
+    return static_cast<float>(pow(static_cast<double>(base),
+                                  static_cast<double>(exp)));
+}
+
 #ifdef SK_BUILD_FOR_WINCE
     #define sk_float_sqrt(x)        (float)::sqrt(x)
     #define sk_float_sin(x)         (float)::sin(x)
index 85f3175..f54afcc 100644 (file)
@@ -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;
         }
index 5e25d22..3aab411 100644 (file)
@@ -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<float>(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))
index 37c55e1..27849e7 100644 (file)
@@ -27,7 +27,6 @@ SOURCE := \
     SkCordic.cpp \
     SkCubicClipper.cpp \
     SkDebug.cpp \
-    SkDebug_stdio.cpp \
     SkDeque.cpp \
     SkDevice.cpp \
     SkDither.cpp \
index 28e38a1..fd11f54 100644 (file)
@@ -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)
similarity index 81%
rename from src/core/SkDebug_stdio.cpp
rename to src/ports/SkDebug_android.cpp
index c8a0d81..f1fd34f 100644 (file)
@@ -19,8 +19,6 @@
 
 static const size_t kBufferSize = 256;
 
-#ifdef ANDROID
-
 #define LOG_TAG "skia"
 #include <utils/Log.h>
 
@@ -42,20 +40,4 @@ void Android_SkDebugf(const char* file, int line, const char* function,
     va_end(args);
 }
 
-#else
-
-#include <stdarg.h>
-#include <stdio.h>
-
-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/ports/SkDebug_stdio.cpp b/src/ports/SkDebug_stdio.cpp
new file mode 100644 (file)
index 0000000..f5bf687
--- /dev/null
@@ -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 <stdarg.h>
+#include <stdio.h>
+
+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);
+}
+
index 07dacfa..8760ae1 100644 (file)
@@ -1,4 +1,5 @@
 SOURCE := \
+    SkDebug_stdio.cpp \
     SkFontHost_none.cpp \
     SkGlobals_global.cpp \
     SkOSFile_stdio.cpp \
index af3f3c0..1f1ee10 100644 (file)
@@ -50,7 +50,6 @@
                005F25970EF94F7900582A90 /* SkCordic.h in Headers */ = {isa = PBXBuildFile; fileRef = 005F251E0EF94F7900582A90 /* SkCordic.h */; };
                005F25980EF94F7900582A90 /* SkCoreBlitters.h in Headers */ = {isa = PBXBuildFile; fileRef = 005F251F0EF94F7900582A90 /* SkCoreBlitters.h */; };
                005F25990EF94F7900582A90 /* SkDebug.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F25200EF94F7900582A90 /* SkDebug.cpp */; };
-               005F259A0EF94F7900582A90 /* SkDebug_stdio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F25210EF94F7900582A90 /* SkDebug_stdio.cpp */; };
                005F259B0EF94F7900582A90 /* SkDeque.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F25220EF94F7900582A90 /* SkDeque.cpp */; };
                005F259C0EF94F7900582A90 /* SkDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F25230EF94F7900582A90 /* SkDevice.cpp */; };
                005F259D0EF94F7900582A90 /* SkDither.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F25240EF94F7900582A90 /* SkDither.cpp */; };
                005F251E0EF94F7900582A90 /* SkCordic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkCordic.h; path = ../../src/core/SkCordic.h; sourceTree = SOURCE_ROOT; };
                005F251F0EF94F7900582A90 /* SkCoreBlitters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkCoreBlitters.h; path = ../../src/core/SkCoreBlitters.h; sourceTree = SOURCE_ROOT; };
                005F25200EF94F7900582A90 /* SkDebug.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkDebug.cpp; path = ../../src/core/SkDebug.cpp; sourceTree = SOURCE_ROOT; };
-               005F25210EF94F7900582A90 /* SkDebug_stdio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkDebug_stdio.cpp; path = ../../src/core/SkDebug_stdio.cpp; sourceTree = SOURCE_ROOT; };
                005F25220EF94F7900582A90 /* SkDeque.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkDeque.cpp; path = ../../src/core/SkDeque.cpp; sourceTree = SOURCE_ROOT; };
                005F25230EF94F7900582A90 /* SkDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkDevice.cpp; path = ../../src/core/SkDevice.cpp; sourceTree = SOURCE_ROOT; };
                005F25240EF94F7900582A90 /* SkDither.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkDither.cpp; path = ../../src/core/SkDither.cpp; sourceTree = SOURCE_ROOT; };
                                005F251E0EF94F7900582A90 /* SkCordic.h */,
                                005F251F0EF94F7900582A90 /* SkCoreBlitters.h */,
                                005F25200EF94F7900582A90 /* SkDebug.cpp */,
-                               005F25210EF94F7900582A90 /* SkDebug_stdio.cpp */,
                                005F25220EF94F7900582A90 /* SkDeque.cpp */,
                                005F25230EF94F7900582A90 /* SkDevice.cpp */,
                                005F25240EF94F7900582A90 /* SkDither.cpp */,
                                005F25950EF94F7900582A90 /* SkColorTable.cpp in Sources */,
                                005F25960EF94F7900582A90 /* SkCordic.cpp in Sources */,
                                005F25990EF94F7900582A90 /* SkDebug.cpp in Sources */,
-                               005F259A0EF94F7900582A90 /* SkDebug_stdio.cpp in Sources */,
                                005F259B0EF94F7900582A90 /* SkDeque.cpp in Sources */,
                                005F259C0EF94F7900582A90 /* SkDevice.cpp in Sources */,
                                005F259D0EF94F7900582A90 /* SkDither.cpp in Sources */,
index 4b84b43..6bc1a33 100644 (file)
@@ -12,6 +12,7 @@
                002884A60EFAB5DE0083E387 /* SkThread_pthread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 002884A30EFAB5DE0083E387 /* SkThread_pthread.cpp */; };
                002884A70EFAB5DE0083E387 /* SkTime_Unix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 002884A40EFAB5DE0083E387 /* SkTime_Unix.cpp */; };
                002884E10EFABFFC0083E387 /* SkGlobals_global.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 002884E00EFABFFC0083E387 /* SkGlobals_global.cpp */; };
+               00488AF40F86532E00C08A57 /* SkDebug_stdio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00488AF30F86532E00C08A57 /* SkDebug_stdio.cpp */; };
                007A7BEF0F01427100A2D6EE /* SkFontHost_mac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 007A7BEE0F01427100A2D6EE /* SkFontHost_mac.cpp */; };
                27739F2B0F11407000F233EA /* SkCreateCGImageRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27739F2A0F11407000F233EA /* SkCreateCGImageRef.cpp */; };
                27739F2D0F11408100F233EA /* SkImageDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27739F2C0F11408100F233EA /* SkImageDecoder.cpp */; };
@@ -24,6 +25,7 @@
                002884A30EFAB5DE0083E387 /* SkThread_pthread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkThread_pthread.cpp; path = ../../src/ports/SkThread_pthread.cpp; sourceTree = SOURCE_ROOT; };
                002884A40EFAB5DE0083E387 /* SkTime_Unix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkTime_Unix.cpp; path = ../../src/ports/SkTime_Unix.cpp; sourceTree = SOURCE_ROOT; };
                002884E00EFABFFC0083E387 /* SkGlobals_global.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkGlobals_global.cpp; path = ../../src/ports/SkGlobals_global.cpp; sourceTree = SOURCE_ROOT; };
+               00488AF30F86532E00C08A57 /* SkDebug_stdio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkDebug_stdio.cpp; path = ../../src/ports/SkDebug_stdio.cpp; sourceTree = SOURCE_ROOT; };
                007A7BEE0F01427100A2D6EE /* SkFontHost_mac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkFontHost_mac.cpp; path = ../../src/ports/SkFontHost_mac.cpp; sourceTree = SOURCE_ROOT; };
                27739F2A0F11407000F233EA /* SkCreateCGImageRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkCreateCGImageRef.cpp; path = ../../src/utils/mac/SkCreateCGImageRef.cpp; sourceTree = SOURCE_ROOT; };
                27739F2C0F11408100F233EA /* SkImageDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkImageDecoder.cpp; path = ../../src/images/SkImageDecoder.cpp; sourceTree = SOURCE_ROOT; };
@@ -56,6 +58,7 @@
                08FB7795FE84155DC02AAC07 /* Source */ = {
                        isa = PBXGroup;
                        children = (
+                               00488AF30F86532E00C08A57 /* SkDebug_stdio.cpp */,
                                002884E00EFABFFC0083E387 /* SkGlobals_global.cpp */,
                                002884A20EFAB5DE0083E387 /* SkOSFile_stdio.cpp */,
                                002884A30EFAB5DE0083E387 /* SkThread_pthread.cpp */,
                                27739F2D0F11408100F233EA /* SkImageDecoder.cpp in Sources */,
                                27739F2F0F11409100F233EA /* SkImageDecoder_CG.cpp in Sources */,
                                001EA8910F13F2CE00900BA9 /* SkImageEncoder.cpp in Sources */,
+                               00488AF40F86532E00C08A57 /* SkDebug_stdio.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };