aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-18 21:43:03 +0000
committerGravatar scroggo <scroggo@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-18 21:43:03 +0000
commitb66365f5dd8cba718e1657ee3c85b4406e55f17d (patch)
tree60779c569b5bedf5f67170cb9ff8d5d62b16f71a
parent3f0dcf96c332b1b0cb9b63043d16607e8702259b (diff)
Updates to the unix sample app.
Rather than placing pixels, use XPutImage to place the bitmap on screen. Modify the color arrangements for 8888 when building the sample app, so they agree with X. Add a title to simple sample. Include SkTouchGesture. git-svn-id: http://skia.googlecode.com/svn/trunk@963 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--Makefile3
-rw-r--r--include/config/SkUserConfig.h9
-rw-r--r--src/utils/unix/SkOSWindow_Unix.cpp26
-rw-r--r--src/views/views_files.mk3
-rw-r--r--unix_test_app/DrawBlueSample.cpp12
-rw-r--r--unix_test_app/makefile17
6 files changed, 57 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index e482060c62..db04678225 100644
--- a/Makefile
+++ b/Makefile
@@ -106,6 +106,9 @@ else
LINKER_OPTS += -lpng -lfreetype -lGL
DEFINES += -DSK_BUILD_FOR_UNIX -DSK_ENABLE_LIBPNG -DGR_LINUX_BUILD=1
+ ifeq ($(SKIA_SAMPLES_FOR_X),true)
+ DEFINES += -DSK_SAMPLES_FOR_X
+ endif
# needed for freetype support
C_INCLUDES += -I/usr/include/freetype2
SRC_LIST += src/ports/SkFontHost_linux.cpp
diff --git a/include/config/SkUserConfig.h b/include/config/SkUserConfig.h
index 13169cae99..aa2e6cf40b 100644
--- a/include/config/SkUserConfig.h
+++ b/include/config/SkUserConfig.h
@@ -141,5 +141,14 @@
//#define SK_SUPPORT_UNITTEST
#endif
+/* Change the ordering to work in X windows.
+ */
+#ifdef SK_SAMPLES_FOR_X
+ #define SK_R32_SHIFT 16
+ #define SK_G32_SHIFT 8
+ #define SK_B32_SHIFT 0
+ #define SK_A32_SHIFT 24
+#endif
+
#endif
diff --git a/src/utils/unix/SkOSWindow_Unix.cpp b/src/utils/unix/SkOSWindow_Unix.cpp
index 96940f5bef..650ced28b0 100644
--- a/src/utils/unix/SkOSWindow_Unix.cpp
+++ b/src/utils/unix/SkOSWindow_Unix.cpp
@@ -72,14 +72,24 @@ void SkOSWindow::doPaint() {
if (!fUnixWindow.fDisplay) return;
// Draw the bitmap to the screen.
const SkBitmap& bitmap = getBitmap();
- for (int i = 0; i < bitmap.width(); i++) {
- for (int j = 0; j < bitmap.height(); j++) {
- // Get the pixel, put it on the screen.
- SkColor color = bitmap.getColor(i, j);
- XSetForeground(fUnixWindow.fDisplay, fUnixWindow.fGc, color);
- XDrawPoint(fUnixWindow.fDisplay, fUnixWindow.fWin, fUnixWindow.fGc, i, j);
- }
- }
+
+ XImage image;
+ sk_bzero(&image, sizeof(image));
+
+ int bitsPerPixel = bitmap.bytesPerPixel() * 8;
+ image.width = bitmap.width();
+ image.height = bitmap.height();
+ image.format = ZPixmap;
+ image.data = (char*) bitmap.getPixels();
+ image.byte_order = LSBFirst;
+ image.bitmap_unit = bitsPerPixel;
+ image.bitmap_bit_order = LSBFirst;
+ image.bitmap_pad = bitsPerPixel;
+ image.depth = 24;
+ image.bytes_per_line = bitmap.rowBytes() - bitmap.width() * bitmap.bytesPerPixel();
+ image.bits_per_pixel = bitsPerPixel;
+ int status = XInitImage(&image);
+ XPutImage(fUnixWindow.fDisplay, fUnixWindow.fWin, fUnixWindow.fGc, &image, 0, 0, 0, 0, width(), height());
}
bool SkOSWindow::onHandleChar(SkUnichar)
diff --git a/src/views/views_files.mk b/src/views/views_files.mk
index 613c4bda9f..3eee6984a9 100644
--- a/src/views/views_files.mk
+++ b/src/views/views_files.mk
@@ -6,7 +6,8 @@ SOURCE := \
SkTagList.cpp \
SkView.cpp \
SkViewPriv.cpp \
- SkWindow.cpp
+ SkWindow.cpp \
+ SkTouchGesture.cpp
# SkBGViewArtist.cpp \
SkListView.cpp \
SkListWidget.cpp \
diff --git a/unix_test_app/DrawBlueSample.cpp b/unix_test_app/DrawBlueSample.cpp
index 7e58d32b11..61b6607b69 100644
--- a/unix_test_app/DrawBlueSample.cpp
+++ b/unix_test_app/DrawBlueSample.cpp
@@ -1,6 +1,7 @@
+#include "SampleCode.h"
#include "SkCanvas.h"
#include "SkColor.h"
-#include "SampleCode.h"
+#include "SkEvent.h"
#include "SkView.h"
class DrawBlue : public SkView {
@@ -11,6 +12,15 @@ protected:
virtual void onDraw(SkCanvas* canvas) {
canvas->drawColor(SK_ColorBLUE);
}
+ virtual bool onQuery(SkEvent* evt) {
+ if (SampleCode::TitleQ(*evt)) {
+ SampleCode::TitleR(evt, "DrawBlue");
+ return true;
+ }
+ return this->INHERITED::onQuery(evt);
+ }
+private:
+ typedef SkView INHERITED;
};
static SkView* MyFactory() { return new DrawBlue; }
diff --git a/unix_test_app/makefile b/unix_test_app/makefile
index 06904356df..6234679b94 100644
--- a/unix_test_app/makefile
+++ b/unix_test_app/makefile
@@ -12,12 +12,12 @@ C_INCLUDES := -I../include/core \
-I../include/utils/unix \
-I../samplecode
-VPATH = libs:../src/ports:../samplecode:../src/core:../out:../src/utils/unix
+VPATH = libs:../src/ports:../samplecode:../src/core:../src/utils/unix
#generate debugging info
CFLAGS = -g
-SRC_LIST := main.cpp SkOSWindow_Unix.cpp SkXMLParser_empty.cpp SkDebug.cpp keysym2ucs.c
+SRC_LIST := main.cpp SkOSWindow_Unix.cpp SkXMLParser_empty.cpp SkDebug.cpp
#views files
include ../src/views/views_files.mk
@@ -31,6 +31,17 @@ SRC_LIST += $(addprefix ../src/xml/, $(SOURCE))
include ../samplecode/samplecode_files.mk
SRC_LIST += $(addprefix ../samplecode/, $(SOURCE))
-output: $(SRC_LIST) -lX11 -lskia -lpthread -lz -lfreetype -lGL -lpng
+
+out/output: $(SRC_LIST) out/keysym2ucs.o ../out/libskia.a -lX11 -lpthread -lz -lfreetype -lGL -lpng
g++ $(C_INCLUDES) $(CFLAGS) $^ -o $@
+out/keysym2ucs.o: ../src/utils/unix/keysym2ucs.c
+ @mkdir -p $(dir $@)
+ @gcc -c $(C_INCLUDES) $(CFLAGS) $^ -o $@
+
+../out/libskia.a:
+ @$(MAKE) -C ../ SKIA_SAMPLES_FOR_X=true
+
+clean:
+ rm -rf ../out # Copied from ../Makefile
+ rm -rf out