#import <UIKit/UIKit.h>
#include "SkApplication.h"
-extern void save_args(int argc, char *argv[]);
+extern bool set_cmd_line_args(int argc, char *argv[], const char* dir);
int main(int argc, char *argv[]) {
signal(SIGPIPE, SIG_IGN);
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
application_init();
- save_args(argc, argv);
- int retVal = UIApplicationMain(argc, argv, nil, nil);
+ // Identify the documents directory
+ NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ NSString *docsDir = [dirPaths objectAtIndex:0];
+ const char *d = [docsDir UTF8String];
+
+ bool ranCommand = set_cmd_line_args(argc, argv, d);
+ int retVal = ranCommand ? 0 : UIApplicationMain(argc, argv, nil, nil);
application_term();
[pool release];
return retVal;
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.google.iOSShell</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>NSMainNibFile</key>
+ <string>MainWindow_iPhone</string>
+ <key>NSMainNibFile~ipad</key>
+ <string>MainWindow_iPad</string>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
--- /dev/null
+#
+{
+ 'conditions' : [
+ [ 'skia_os == "ios"', {
+ 'targets': [
+ {
+ 'target_name': 'iOSShell',
+ 'type': 'executable',
+ 'mac_bundle' : 1,
+ 'includes': [
+ 'tests.gypi',
+ 'pathops_unittest.gypi',
+ ],
+ 'dependencies': [
+ 'tools.gyp:crash_handler',
+ 'views.gyp:views',
+ 'xml.gyp:xml',
+ ],
+ 'sources': [
+ '../tests/skia_test.cpp',
+ '../tools/iOSShell.cpp',
+ '../src/views/mac/SkEventNotifier.mm',
+ '../experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig',
+ '../experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig',
+ '../experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig',
+ '../experimental/iOSShell/iOSShell-Info.plist',
+ '../experimental/iOSSampleApp/Shared/SkUIRootViewController.mm',
+ '../experimental/iOSSampleApp/Shared/SkUIView.mm',
+ '../experimental/iOSSampleApp/Shared/skia_ios.mm',
+
+ # iPad
+ '../experimental/iOSSampleApp/iPad/AppDelegate_iPad.mm',
+ '../experimental/iOSSampleApp/iPad/SkUISplitViewController.mm',
+ '../experimental/iOSSampleApp/iPad/MainWindow_iPad.xib',
+
+ # iPhone
+ '../experimental/iOSSampleApp/iPhone/AppDelegate_iPhone.mm',
+ '../experimental/iOSSampleApp/iPhone/SkUINavigationController.mm',
+ '../experimental/iOSSampleApp/iPhone/MainWindow_iPhone.xib',
+
+ '../src/views/ios/SkOSWindow_iOS.mm',
+ '../src/utils/ios/SkStream_NSData.mm',
+ '../src/utils/mac/SkCreateCGImageRef.cpp',
+ ],
+ 'link_settings': {
+ 'libraries': [
+ '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework',
+ '$(SDKROOT)/System/Library/Frameworks/CoreGraphics.framework',
+ '$(SDKROOT)/System/Library/Frameworks/CoreText.framework',
+ '$(SDKROOT)/System/Library/Frameworks/UIKit.framework',
+ '$(SDKROOT)/System/Library/Frameworks/Foundation.framework',
+ '$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework',
+ '$(SDKROOT)/System/Library/Frameworks/OpenGLES.framework',
+ '$(SDKROOT)/System/Library/Frameworks/ImageIO.framework',
+ '$(SDKROOT)/System/Library/Frameworks/MobileCoreServices.framework',
+ ],
+ },
+ 'include_dirs' : [
+ '../experimental/iOSSampleApp',
+ '../experimental/iOSSampleApp/iPad',
+ '../experimental/iOSSampleApp/iPhone',
+ '../experimental/iOSSampleApp/Shared',
+ '../include/utils/ios',
+ '../src/views/mac',
+ ],
+ 'xcode_settings' : {
+ 'INFOPLIST_FILE' : '../experimental/iOSShell/iOSShell-Info.plist',
+ },
+ 'xcode_config_file': '../experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig',
+ 'mac_bundle_resources' : [
+ '../experimental/iOSSampleApp/iPad/MainWindow_iPad.xib',
+ '../experimental/iOSSampleApp/iPhone/MainWindow_iPhone.xib',
+ ],
+ 'conditions' : [
+ [ 'skia_gpu == 1', {
+ 'dependencies': [
+ 'gputest.gyp:skgputest',
+ ],
+ }],
+ ],
+ },
+ ],
+ }],
+ ]
+}
}],
['skia_os == "ios"', {
'dependencies!': [ 'SampleApp.gyp:SampleApp' ],
+ 'dependencies': ['iOSShell.gyp:iOSShell' ],
}],
['skia_os == "mac" or skia_os == "linux"', {
'dependencies': [ 'nanomsg.gyp:*' ],
DECLARE_ENCODER_CREATOR(KTXImageEncoder);
DECLARE_ENCODER_CREATOR(WEBPImageEncoder);
+#ifdef SK_BUILD_FOR_IOS
+DECLARE_ENCODER_CREATOR(PNGImageEncoder_IOS);
+#endif
+
// Typedef to make registering encoder callback easier
// This has to be defined outside SkImageEncoder. :(
typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_EncodeReg;
value = SkApplySign(value, SkExtractSign(packed));
exp = -exp;
if (exp > 25) { // underflow
+#ifdef SK_DISCARD_DENORMALIZED_FOR_SPEED
+ // The iOS ARM processor discards small denormalized numbers to go faster.
+ // The comparision below empirically causes the result to agree with the
+ // tests in MathTest test_float_floor
+ if (exp > 149) {
+ return 0;
+ }
+#else
exp = 25;
+#endif
}
// int add = 0;
return value >> exp;
value = SkApplySign(value, SkExtractSign(packed));
exp = -exp;
if (exp > 25) { // underflow
+#ifdef SK_DISCARD_DENORMALIZED_FOR_SPEED
+ // The iOS ARM processor discards small denormalized numbers to go faster.
+ // The comparision below empirically causes the result to agree with the
+ // tests in MathTest test_float_ceil
+ if (exp > 149) {
+ return 0;
+ }
+ return 0 < value;
+#else
exp = 25;
+#endif
}
int add = (1 << exp) - 1;
return (value + add) >> exp;
#include "SkMath.h"
+#ifdef SK_BUILD_FOR_IOS
+// The iOS ARM processor discards small denormalized numbers to go faster.
+// Algorithms that rely on denormalized numbers need alternative implementations.
+#define SK_DISCARD_DENORMALIZED_FOR_SPEED
+#endif
+
/** Returns -1 if n < 0, else returns 0
*/
#define SkExtractSign(n) ((int32_t)(n) >> 31)
*/
+#include "SkMathPriv.h"
#include "SkPoint.h"
void SkIPoint::rotateCW(SkIPoint* dst) const {
// divide by inf. and return (0,0) vector.
double xx = x;
double yy = y;
+ #ifdef SK_DISCARD_DENORMALIZED_FOR_SPEED
+ // The iOS ARM processor discards small denormalized numbers to go faster.
+ // Casting this to a float would cause the scale to go to zero. Keeping it
+ // as a double for the multiply keeps the scale non-zero.
+ double dscale = length / sqrt(xx * xx + yy * yy);
+ fX = x * dscale;
+ fY = y * dscale;
+ return true;
+ #else
scale = (float)(length / sqrt(xx * xx + yy * yy));
+ #endif
}
fX = x * scale;
fY = y * scale;
#endif
#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_IOS)
CreatePNGImageDecoder();
+#endif
+#if defined(SK_BUILD_FOR_IOS)
+ CreatePNGImageEncoder_IOS();
#endif
return -1;
}
static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_cg_factory);
+#ifdef SK_BUILD_FOR_IOS
+class SkPNGImageEncoder_IOS : public SkImageEncoder_CG {
+public:
+ SkPNGImageEncoder_IOS()
+ : SkImageEncoder_CG(kPNG_Type) {
+ }
+};
+
+DEFINE_ENCODER_CREATOR(PNGImageEncoder_IOS);
+#endif
+
struct FormatConversion {
CFStringRef fUTType;
SkImageDecoder::Format fFormat;
return NULL;
}
-SkImageEncoder* SkImageEncoder::Create(Type t) {
- return NULL;
-}
void SkTouchGesture::touchMoved(void* owner, float x, float y) {
// GrPrintf("--- %d touchMoved %p %g %g\n", fTouches.count(), owner, x, y);
- SkASSERT(kEmpty_State != fState);
+ if (kEmpty_State == fState) {
+ return;
+ }
int index = this->findRec(owner);
if (index < 0) {
REPORTER_ASSERT(reporter, bm8888.getColor(27, 34) == 0xffffffff);
REPORTER_ASSERT(reporter, bm8888.getColor(71, 18) == 0xff000000);
+#ifdef SK_BUILD_FOR_IOS // the iOS jpeg decoder fills to gray
+ REPORTER_ASSERT(reporter, bm8888.getColor(127, 127) == 0xff808080
+ || bm8888.getColor(127, 127) == SK_ColorWHITE);
+#else
// This is the fill color
REPORTER_ASSERT(reporter, bm8888.getColor(127, 127) == SK_ColorWHITE);
+#endif
#if JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING
// Check to see that the resulting bitmap is nice
static const char* kSkOverwriteLine =
#ifdef SK_BUILD_FOR_WIN32
"\r \r"
+#elif defined(SK_BUILD_FOR_IOS)
+"\r"
#else
"\r\033[K"
#endif
SkString GetResourcePath(const char* resource) {
return SkOSPath::SkPathJoin(FLAGS_resourcePath[0], resource);
}
+
+void SetResourcePath(const char* resource) {
+ FLAGS_resourcePath.set(0, resource);
+}
#include "SkString.h"
SkString GetResourcePath(const char* resource = "");
+void SetResourcePath(const char* );
#endif // Resources_DEFINED
return false;
}
+ void set(int i, const char* str) {
+ fStrings[i].set(str);
+ }
+
private:
void reset() { fStrings.reset(); }
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "iOSShell.h"
+
+#include "Resources.h"
+#include "SkCanvas.h"
+#include "SkCommandLineFlags.h"
+#include "SkGraphics.h"
+#include "SkWindow.h"
+#include "sk_tool_utils.h"
+
+//////////////////////////////////////////////////////////////////////////////
+
+static SkView* curr_view(SkWindow* wind) {
+ SkView::F2BIter iter(wind);
+ return iter.next();
+}
+
+ShellWindow::ShellWindow(void* hwnd, int argc, char** argv)
+ : INHERITED(hwnd) {
+ SkCommandLineFlags::Parse(argc, argv);
+}
+
+ShellWindow::~ShellWindow() {
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+bool ShellWindow::onDispatchClick(int x, int y, Click::State state,
+ void* owner, unsigned modi) {
+ int w = SkScalarRoundToInt(this->width());
+ int h = SkScalarRoundToInt(this->height());
+
+ // check for the resize-box
+ if (w - x < 16 && h - y < 16) {
+ return false; // let the OS handle the click
+ } else {
+ return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
+ }
+}
+
+void ShellWindow::onSizeChange() {
+ this->INHERITED::onSizeChange();
+
+ SkView::F2BIter iter(this);
+ SkView* view = iter.next();
+ view->setSize(this->width(), this->height());
+}
+
+void tool_main(int argc, char *argv[]);
+
+bool set_cmd_line_args(int argc, char *argv[], const char* resourceDir) {
+ for (int index = 0; index < argc; ++index) {
+ if (!strcmp("--test", argv[index])) {
+ SetResourcePath(resourceDir);
+ tool_main(argc - 1, argv);
+ return true;
+ }
+ }
+ return false;
+}
+
+// FIXME: this should be in a header
+SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
+SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
+ return new ShellWindow(hwnd, argc, argv);
+}
+
+// FIXME: this should be in a header
+void get_preferred_size(int* x, int* y, int* width, int* height);
+void get_preferred_size(int* x, int* y, int* width, int* height) {
+ *x = 10;
+ *y = 50;
+ *width = 640;
+ *height = 480;
+}
+
+// FIXME: this should be in a header
+void application_init();
+void application_init() {
+ SkGraphics::Init();
+ SkEvent::Init();
+}
+
+// FIXME: this should be in a header
+void application_term();
+void application_term() {
+ SkEvent::Term();
+ SkGraphics::Term();
+}
--- /dev/null
+/*
+ * Copyright 2014 Skia
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef iOSShell_DEFINED
+#define iOSShell_DEFINED
+
+#include "SkWindow.h"
+
+class SkCanvas;
+class SkEvent;
+class SkViewFactory;
+
+class ShellWindow : public SkOSWindow {
+public:
+ ShellWindow(void* hwnd, int argc, char** argv);
+ virtual ~ShellWindow();
+
+ virtual SkCanvas* createCanvas() SK_OVERRIDE {
+ SkCanvas* canvas = this->INHERITED::createCanvas();
+ return canvas;
+ }
+
+protected:
+ virtual void onSizeChange() SK_OVERRIDE;
+
+ virtual bool onDispatchClick(int x, int y, Click::State, void* owner,
+ unsigned modi) SK_OVERRIDE;
+
+private:
+ typedef SkOSWindow INHERITED;
+};
+
+#endif