add SDL support
git-svn-id: http://skia.googlecode.com/svn/trunk@182 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkPreConfig.h b/include/core/SkPreConfig.h
index 05f3d43..b66c97e 100644
--- a/include/core/SkPreConfig.h
+++ b/include/core/SkPreConfig.h
@@ -19,7 +19,7 @@
//////////////////////////////////////////////////////////////////////
-#if !defined(SK_BUILD_FOR_PALM) && !defined(SK_BUILD_FOR_WINCE) && !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_SYMBIAN) && !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC)
+#if !defined(SK_BUILD_FOR_PALM) && !defined(SK_BUILD_FOR_WINCE) && !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_SYMBIAN) && !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_SDL)
#if defined(PALMOS_SDK_VERSION)
#define SK_BUILD_FOR_PALM
diff --git a/include/views/SkOSWindow_SDL.h b/include/views/SkOSWindow_SDL.h
new file mode 100644
index 0000000..f2a6b32
--- /dev/null
+++ b/include/views/SkOSWindow_SDL.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 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.
+ */
+
+#ifndef SkOSWindow_SDL_DEFINED
+#define SkOSWindow_SDL_DEFINED
+
+#include "SDL.h"
+#include "SkWindow.h"
+
+class SkOSWindow : public SkWindow {
+public:
+ SkOSWindow(void* surface);
+
+ static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
+
+ void handleSDLEvent(const SDL_Event& event);
+
+protected:
+ // overrides from SkWindow
+ virtual void onHandleInval(const SkIRect&);
+ // overrides from SkView
+ virtual void onAddMenu(const SkOSMenu*);
+ virtual void onSetTitle(const char[]);
+
+private:
+ SDL_Surface* fSurface;
+
+ void doDraw();
+
+ typedef SkWindow INHERITED;
+};
+
+#endif
+
diff --git a/include/views/SkWindow.h b/include/views/SkWindow.h
index da3912e..1c8f9a3 100644
--- a/include/views/SkWindow.h
+++ b/include/views/SkWindow.h
@@ -90,16 +90,16 @@
///////////////////////////////////////////////////////////
-#ifndef SK_USE_WXWIDGETS
-#ifdef SK_BUILD_FOR_MAC
+#ifdef SK_USE_WXWIDGETS
+ #include "SkOSWindow_wxwidgets.h"
+#elif defined(SK_BUILD_FOR_MAC)
#include "SkOSWindow_Mac.h"
#elif defined(SK_BUILD_FOR_WIN)
#include "SkOSWindow_Win.h"
#elif defined(SK_BUILD_FOR_UNIXx)
#include "SkOSWindow_Unix.h"
-#endif
-#else
- #include "SkOSWindow_wxwidgets.h"
+#elif defined(SK_BUILD_FOR_SDL)
+ #include "SkOSWindow_SDL.h"
#endif
#endif
diff --git a/samplecode/SamplePathEffects.cpp b/samplecode/SamplePathEffects.cpp
index 4e964d7..e2b5f5a 100644
--- a/samplecode/SamplePathEffects.cpp
+++ b/samplecode/SamplePathEffects.cpp
@@ -203,7 +203,7 @@
}
gPhase -= SK_Scalar1;
- this->inval(nil);
+ this->inval(NULL);
SkPaint paint;
diff --git a/samplecode/SampleRegion.cpp b/samplecode/SampleRegion.cpp
index 5dc69cb..6259000 100644
--- a/samplecode/SampleRegion.cpp
+++ b/samplecode/SampleRegion.cpp
@@ -226,7 +226,7 @@
// SkShader* shader = SkShader::CreateBitmapShader(bm, false, SkPaint::kBilinear_FilterType, SkShader::kRepeat_TileMode);
SkPoint pts[] = { 0, 0, SkIntToScalar(100), SkIntToScalar(0) };
SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
- SkShader* shader = SkGradientShader::CreateLinear(pts, colors, nil, 2, SkShader::kMirror_TileMode);
+ SkShader* shader = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kMirror_TileMode);
paint.setShader(shader)->unref();
canvas->drawPaint(paint);
@@ -323,14 +323,14 @@
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y)
{
- return fRect.contains(SkScalarRound(x), SkScalarRound(y)) ? new Click(this) : nil;
+ return fRect.contains(SkScalarRound(x), SkScalarRound(y)) ? new Click(this) : NULL;
}
virtual bool onClick(Click* click)
{
fRect.offset(click->fICurr.fX - click->fIPrev.fX,
click->fICurr.fY - click->fIPrev.fY);
- this->inval(nil);
+ this->inval(NULL);
return true;
}
diff --git a/samplecode/SampleText.cpp b/samplecode/SampleText.cpp
index b8abac3..83ff68d 100644
--- a/samplecode/SampleText.cpp
+++ b/samplecode/SampleText.cpp
@@ -96,7 +96,7 @@
SkTypeface* t2 = SkTypeface::CreateFromName("arial", SkTypeface::kNormal);
SkTypeface* t3 = SkTypeface::CreateFromName("helvetica", SkTypeface::kItalic);
-#ifndef SK_BUILD_FOR_MAC
+#ifdef ANDROID
SkASSERT(t0 == t1);
SkASSERT(t0 == t2);
SkASSERT(t0 == t3);
diff --git a/src/utils/SDL/SkOSWindow_SDL.cpp b/src/utils/SDL/SkOSWindow_SDL.cpp
new file mode 100644
index 0000000..13bea72
--- /dev/null
+++ b/src/utils/SDL/SkOSWindow_SDL.cpp
@@ -0,0 +1,175 @@
+#include "SkOSWindow_SDL.h"
+#include "SkCanvas.h"
+#include "SkOSMenu.h"
+#include "SkTime.h"
+
+static void post_SkEvent_event() {
+ SDL_Event evt;
+ evt.type = SDL_USEREVENT;
+ evt.user.type = SDL_USEREVENT;
+ evt.user.code = 0;
+ evt.user.data1 = NULL;
+ evt.user.data2 = NULL;
+ SDL_PushEvent(&evt);
+}
+
+static bool skia_setBitmapFromSurface(SkBitmap* dst, SDL_Surface* src) {
+ SkBitmap::Config config;
+
+ switch (src->format->BytesPerPixel) {
+ case 2:
+ config = SkBitmap::kRGB_565_Config;
+ break;
+ case 4:
+ config = SkBitmap::kARGB_8888_Config;
+ break;
+ default:
+ return false;
+ }
+
+ dst->setConfig(config, src->w, src->h, src->pitch);
+ dst->setPixels(src->pixels);
+ return true;
+}
+
+SkOSWindow::SkOSWindow(void* surface) {
+ fSurface = reinterpret_cast<SDL_Surface*>(surface);
+ this->resize(fSurface->w, fSurface->h);
+}
+
+void SkOSWindow::doDraw() {
+ if ( SDL_MUSTLOCK(fSurface) ) {
+ if ( SDL_LockSurface(fSurface) < 0 ) {
+ return;
+ }
+ }
+
+ SkBitmap bitmap;
+
+ if (skia_setBitmapFromSurface(&bitmap, fSurface)) {
+ SkCanvas canvas(bitmap);
+ this->draw(&canvas);
+ }
+
+ if ( SDL_MUSTLOCK(fSurface) ) {
+ SDL_UnlockSurface(fSurface);
+ }
+ SDL_UpdateRect(fSurface, 0, 0, fSurface->w, fSurface->h);
+}
+
+static SkKey find_skkey(SDLKey src) {
+ // this array must match the enum order in SkKey.h
+ static const SDLKey gKeys[] = {
+ SDLK_UNKNOWN,
+ SDLK_UNKNOWN, // left softkey
+ SDLK_UNKNOWN, // right softkey
+ SDLK_UNKNOWN, // home
+ SDLK_UNKNOWN, // back
+ SDLK_UNKNOWN, // send
+ SDLK_UNKNOWN, // end
+ SDLK_0,
+ SDLK_1,
+ SDLK_2,
+ SDLK_3,
+ SDLK_4,
+ SDLK_5,
+ SDLK_6,
+ SDLK_7,
+ SDLK_8,
+ SDLK_9,
+ SDLK_ASTERISK,
+ SDLK_HASH,
+ SDLK_UP,
+ SDLK_DOWN,
+ SDLK_LEFT,
+ SDLK_RIGHT,
+ SDLK_RETURN, // OK
+ SDLK_UNKNOWN, // volume up
+ SDLK_UNKNOWN, // volume down
+ SDLK_UNKNOWN, // power
+ SDLK_UNKNOWN, // camera
+ };
+
+ const SDLKey* array = gKeys;
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gKeys); i++) {
+ if (array[i] == src) {
+ return static_cast<SkKey>(i);
+ }
+ }
+ return kNONE_SkKey;
+}
+
+void SkOSWindow::handleSDLEvent(const SDL_Event& event) {
+ switch (event.type) {
+ case SDL_VIDEORESIZE:
+ this->resize(event.resize.w, event.resize.h);
+ break;
+ case SDL_VIDEOEXPOSE:
+ this->doDraw();
+ break;
+ case SDL_MOUSEMOTION:
+ if (event.motion.state == SDL_PRESSED) {
+ this->handleClick(event.motion.x, event.motion.y,
+ SkView::Click::kMoved_State);
+ }
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ this->handleClick(event.button.x, event.button.y,
+ event.button.state == SDL_PRESSED ?
+ SkView::Click::kDown_State :
+ SkView::Click::kUp_State);
+ break;
+ case SDL_KEYDOWN: {
+ SkKey sk = find_skkey(event.key.keysym.sym);
+ if (kNONE_SkKey != sk) {
+ if (event.key.state == SDL_PRESSED) {
+ this->handleKey(sk);
+ } else {
+ this->handleKeyUp(sk);
+ }
+ }
+ break;
+ }
+ case SDL_USEREVENT:
+ if (SkEvent::ProcessEvent()) {
+ post_SkEvent_event();
+ }
+ break;
+ }
+}
+
+void SkOSWindow::onHandleInval(const SkIRect& r) {
+ SDL_Event evt;
+ evt.type = SDL_VIDEOEXPOSE;
+ evt.expose.type = SDL_VIDEOEXPOSE;
+ SDL_PushEvent(&evt);
+}
+
+void SkOSWindow::onSetTitle(const char title[]) {
+ SDL_WM_SetCaption(title, NULL);
+}
+
+void SkOSWindow::onAddMenu(const SkOSMenu* sk_menu) {}
+
+///////////////////////////////////////////////////////////////////////////////////////
+
+void SkEvent::SignalNonEmptyQueue() {
+ SkDebugf("-------- signal nonempty\n");
+ post_SkEvent_event();
+}
+
+static Uint32 timer_callback(Uint32 interval) {
+// SkDebugf("-------- timercallback %d\n", interval);
+ SkEvent::ServiceQueueTimer();
+ return 0;
+}
+
+void SkEvent::SignalQueueTimer(SkMSec delay)
+{
+ SDL_SetTimer(0, NULL);
+ if (delay) {
+ SDL_SetTimer(delay, timer_callback);
+ }
+}
+
diff --git a/xcode/core/core.xcodeproj/project.pbxproj b/xcode/core/core.xcodeproj/project.pbxproj
index c4c1630..6a6c8d9 100644
--- a/xcode/core/core.xcodeproj/project.pbxproj
+++ b/xcode/core/core.xcodeproj/project.pbxproj
@@ -125,6 +125,7 @@
005F25E70EF94F7900582A90 /* SkXfermode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F256E0EF94F7900582A90 /* SkXfermode.cpp */; };
005F26960EF955D400582A90 /* SkComposeShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 005F26950EF955D400582A90 /* SkComposeShader.cpp */; };
007C786A0F3B4D5F0004B142 /* SkQuadClipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 007C78690F3B4D5F0004B142 /* SkQuadClipper.cpp */; };
+ 0096586E0FC7205100C3AE15 /* SkShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0096586D0FC7205100C3AE15 /* SkShape.cpp */; };
009CC7920F5DAF4B002185BE /* SkCubicClipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 009CC7910F5DAF4B002185BE /* SkCubicClipper.cpp */; };
/* End PBXBuildFile section */
@@ -247,6 +248,7 @@
005F256E0EF94F7900582A90 /* SkXfermode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkXfermode.cpp; path = ../../src/core/SkXfermode.cpp; sourceTree = SOURCE_ROOT; };
005F26950EF955D400582A90 /* SkComposeShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkComposeShader.cpp; path = ../../src/core/SkComposeShader.cpp; sourceTree = SOURCE_ROOT; };
007C78690F3B4D5F0004B142 /* SkQuadClipper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkQuadClipper.cpp; path = ../../src/core/SkQuadClipper.cpp; sourceTree = SOURCE_ROOT; };
+ 0096586D0FC7205100C3AE15 /* SkShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkShape.cpp; path = ../../src/core/SkShape.cpp; sourceTree = SOURCE_ROOT; };
009CC7910F5DAF4B002185BE /* SkCubicClipper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkCubicClipper.cpp; path = ../../src/core/SkCubicClipper.cpp; sourceTree = SOURCE_ROOT; };
D2AAC046055464E500DB518D /* libcore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcore.a; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@@ -269,9 +271,18 @@
name = opengl;
sourceTree = "<group>";
};
+ 0096586C0FC7203700C3AE15 /* shapes */ = {
+ isa = PBXGroup;
+ children = (
+ 0096586D0FC7205100C3AE15 /* SkShape.cpp */,
+ );
+ name = shapes;
+ sourceTree = "<group>";
+ };
08FB7794FE84155DC02AAC07 /* core */ = {
isa = PBXGroup;
children = (
+ 0096586C0FC7203700C3AE15 /* shapes */,
009490660FB0AC280063C792 /* opengl */,
08FB7795FE84155DC02AAC07 /* src */,
C6A0FF2B0290797F04C91782 /* Documentation */,
@@ -592,6 +603,7 @@
002884D50EFAB8F80083E387 /* SkStream.cpp in Sources */,
007C786A0F3B4D5F0004B142 /* SkQuadClipper.cpp in Sources */,
009CC7920F5DAF4B002185BE /* SkCubicClipper.cpp in Sources */,
+ 0096586E0FC7205100C3AE15 /* SkShape.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj b/xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj
index 0c53fca..9edb16d 100644
--- a/xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj
+++ b/xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj
@@ -28,7 +28,6 @@
00003CA40EFC235F000FF73A /* SkXMLParser_empty.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00003CA30EFC235F000FF73A /* SkXMLParser_empty.cpp */; };
0028847B0EFAB46A0083E387 /* libcore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 002884510EFAA35C0083E387 /* libcore.a */; };
002884BD0EFAB6A30083E387 /* libmaccore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 002884BC0EFAB69F0083E387 /* libmaccore.a */; };
- 0031450E0FB8CDB100B10956 /* SkShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0031450D0FB8CDB100B10956 /* SkShape.cpp */; };
003145200FB99CCE00B10956 /* SkRectShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0031451F0FB99CCE00B10956 /* SkRectShape.cpp */; };
003145320FB9B48F00B10956 /* SampleShapes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 003145310FB9B48F00B10956 /* SampleShapes.cpp */; };
003145370FB9BA4000B10956 /* SkGroupShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 003145360FB9BA4000B10956 /* SkGroupShape.cpp */; };
@@ -149,7 +148,6 @@
00003CA30EFC235F000FF73A /* SkXMLParser_empty.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkXMLParser_empty.cpp; path = ../../src/ports/SkXMLParser_empty.cpp; sourceTree = SOURCE_ROOT; };
002884490EFAA35C0083E387 /* core.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = core.xcodeproj; path = ../core/core.xcodeproj; sourceTree = SOURCE_ROOT; };
002884B40EFAB69F0083E387 /* maccore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = maccore.xcodeproj; path = ../maccore/maccore.xcodeproj; sourceTree = SOURCE_ROOT; };
- 0031450D0FB8CDB100B10956 /* SkShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkShape.cpp; path = ../../src/core/SkShape.cpp; sourceTree = SOURCE_ROOT; };
0031451D0FB99C9700B10956 /* SkRectShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkRectShape.h; path = ../../src/shapes/SkRectShape.h; sourceTree = SOURCE_ROOT; };
0031451F0FB99CCE00B10956 /* SkRectShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkRectShape.cpp; path = ../../src/shapes/SkRectShape.cpp; sourceTree = SOURCE_ROOT; };
003145310FB9B48F00B10956 /* SampleShapes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleShapes.cpp; path = ../../samplecode/SampleShapes.cpp; sourceTree = SOURCE_ROOT; };
@@ -353,7 +351,6 @@
002884B40EFAB69F0083E387 /* maccore.xcodeproj */,
00003C8C0EFC230E000FF73A /* effects.xcodeproj */,
0053528A0F8C4DFF00EE34B6 /* SkFontHost_tables.cpp */,
- 0031450D0FB8CDB100B10956 /* SkShape.cpp */,
0031451D0FB99C9700B10956 /* SkRectShape.h */,
0031451F0FB99CCE00B10956 /* SkRectShape.cpp */,
003145360FB9BA4000B10956 /* SkGroupShape.cpp */,
@@ -548,7 +545,6 @@
00C55DA10F8552DC000CAC09 /* SampleGradients.cpp in Sources */,
009490320FB0A5B90063C792 /* SampleLayerMask.cpp in Sources */,
007A7CB60F01658C00A2D6EE /* SampleRegion.cpp in Sources */,
- 0031450E0FB8CDB100B10956 /* SkShape.cpp in Sources */,
003145200FB99CCE00B10956 /* SkRectShape.cpp in Sources */,
003145320FB9B48F00B10956 /* SampleShapes.cpp in Sources */,
003145370FB9BA4000B10956 /* SkGroupShape.cpp in Sources */,