### Eclipse Workspace Patch 1.0 #P org.eclipse.swt Index: Eclipse SWT PI/win32/library/gdip.cpp =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip.cpp,v retrieving revision 1.49 diff -u -r1.49 gdip.cpp --- Eclipse SWT PI/win32/library/gdip.cpp 1 Jul 2009 14:49:44 -0000 1.49 +++ Eclipse SWT PI/win32/library/gdip.cpp 14 Apr 2010 14:19:01 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,9 +12,195 @@ #include "swt.h" #include "gdip_structs.h" #include "gdip_stats.h" +#include +#include #define Gdip_NATIVE(func) Java_org_eclipse_swt_internal_gdip_Gdip_##func +#ifndef NO_Direct2DRenderTarget_1Rotate +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1Rotate)(JNIEnv *env, jclass that, jintLong m_pDCRT, jfloat angle); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1Rotate) + (JNIEnv *env, jclass that, jintLong m_pDCRT, jfloat angle) +{ + ((ID2D1DCRenderTarget*)m_pDCRT)->SetTransform( + D2D1::Matrix3x2F::Rotation( + angle, + D2D1::Point2F(0, 0)) + ); +} +#endif + +#ifndef NO_Direct2D_RenderTarget_1Scale +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1Scale)(JNIEnv *env, jclass that, jintLong m_pDCRT, jfloat sizeX, jfloat sizeY); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1Scale) + (JNIEnv *env, jclass that, jintLong m_pDCRT, jfloat sizeX, jfloat sizeY) +{ + ((ID2D1DCRenderTarget*)m_pDCRT)->SetTransform( + D2D1::Matrix3x2F::Scale( + D2D1::Size(sizeX, sizeY), + D2D1::Point2F(0, 0)) + ); +} +#endif + +#ifndef NO_Direct2D_RenderTarget_1Screw +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1Screw)(JNIEnv *env, jclass that, jintLong m_pDCRT, jfloat angleX, jfloat angleY); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1Screw) + (JNIEnv *env, jclass that, jintLong m_pDCRT, jfloat angleX, jfloat angleY) +{ + ((ID2D1DCRenderTarget*)m_pDCRT)->SetTransform( + D2D1::Matrix3x2F::Skew( + angleX, + angleY, + D2D1::Point2F(0, 0)) + ); +} +#endif + +#ifndef NO_Direct2D_RenderTarget_1Translation +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1Translation)(JNIEnv *env, jclass that, jintLong m_pDCRT, jfloat moveX, jfloat moveY); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1Translation) + (JNIEnv *env, jclass that, jintLong m_pDCRT, jfloat moveX, jfloat moveY) +{ + ((ID2D1DCRenderTarget*)m_pDCRT)->SetTransform(D2D1::Matrix3x2F::Translation(moveX, moveY)); +} +#endif + +#ifndef NO_Direct2D_1SafeRelease +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2D_1SafeRelease)(JNIEnv *env, jclass that, jintLong ppInterfaceToRelease); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2D_1SafeRelease) + (JNIEnv *env, jclass that, jintLong ppInterfaceToRelease) +{ + if (((IUnknown*)ppInterfaceToRelease) != NULL) + { + ((IUnknown*)ppInterfaceToRelease)->Release(); + ppInterfaceToRelease = NULL; + } +} +#endif + +#ifndef NO_Direct2DStrokeStyle_1new +extern "C" JNIEXPORT jintLong JNICALL Gdip_NATIVE(Direct2DStrokeStyle_1new)(JNIEnv *env, jclass that, jintLong m_pD2DFactory, jintLong strokeStyle, jint startCap, jint endCap, jint dashCap, jint lineJoin, jfloat miterLimit, jint dashStyle, jfloat dashOffset, jfloatArray dashes); +JNIEXPORT jintLong JNICALL Gdip_NATIVE(Direct2DStrokeStyle_1new) + (JNIEnv *env, jclass that, jintLong m_pD2DFactory, jintLong strokeStyle, jint startCap, jint endCap, jint dashCap, jint lineJoin, jfloat miterLimit, jint dashStyle, jfloat dashOffset, jfloatArray dashes) +{ + jfloat *lparg1=NULL; + ID2D1StrokeStyle* m_strokeStyle; + lparg1 = env->GetFloatArrayElements(dashes, NULL); + //if (dashes) if ((lparg1 = env->GetFloatArrayElements(dashes, NULL)) == NULL) goto fail; + ((ID2D1Factory*)m_pD2DFactory)->CreateStrokeStyle( + D2D1::StrokeStyleProperties( + (D2D1_CAP_STYLE)startCap, + (D2D1_CAP_STYLE)endCap, + (D2D1_CAP_STYLE)dashCap, + (D2D1_LINE_JOIN)lineJoin, + miterLimit, + (D2D1_DASH_STYLE)dashStyle, + dashOffset), + 0, + 0, + &m_strokeStyle + ); + + if (dashes && lparg1) env->ReleaseFloatArrayElements(dashes, lparg1, 0); + return (jintLong)m_strokeStyle; +} +#endif + +#ifndef NO_Direct2D_1CreateFactory +extern "C" JNIEXPORT jintLong JNICALL Gdip_NATIVE(Direct2D_1CreateFactory)(JNIEnv *env, jclass that); +JNIEXPORT jintLong JNICALL Gdip_NATIVE(Direct2D_1CreateFactory) + (JNIEnv *env, jclass that) +{ + ID2D1Factory* m_pD2DFactory; + D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory); + return (jintLong)m_pD2DFactory; +} +#endif + +#ifndef NO_Direct2DFactory_1CreateDCRenderTarget +extern "C" JNIEXPORT jintLong JNICALL Gdip_NATIVE(Direct2DFactory_1CreateDCRenderTarget)(JNIEnv *env, jclass that, jintLong m_pD2DFactory); +JNIEXPORT jintLong JNICALL Gdip_NATIVE(Direct2DFactory_1CreateDCRenderTarget) + (JNIEnv *env, jclass that, jintLong m_pD2DFactory) +{ + D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties( + D2D1_RENDER_TARGET_TYPE_DEFAULT, + D2D1::PixelFormat( + DXGI_FORMAT_B8G8R8A8_UNORM, + D2D1_ALPHA_MODE_IGNORE), + 0, + 0, + D2D1_RENDER_TARGET_USAGE_NONE, + D2D1_FEATURE_LEVEL_DEFAULT + ); + + ID2D1DCRenderTarget* m_pDCRT; + ((ID2D1Factory*)m_pD2DFactory)->CreateDCRenderTarget(&props, &m_pDCRT); + return (jintLong)m_pDCRT; +} +#endif + +#ifndef NO_Direct2DRenderTarget_1BindDC +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1BindDC)(JNIEnv *env, jclass that, jintLong m_pDCRT, jintLong hdc, jint width, jint height); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1BindDC) + (JNIEnv *env, jclass that, jintLong m_pDCRT, jintLong hdc, jint width, jint height) +{ + RECT rect; + rect.top = 0; + rect.bottom = (int)height; + rect.left = 0; + rect.right = (int)width; + ((ID2D1DCRenderTarget*)m_pDCRT)->BindDC((HDC)hdc, &rect); +} +#endif + +#ifndef NO_Direct2DRenderTarget_1BeginDraw +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1BeginDraw)(JNIEnv *env, jclass that, jintLong m_pDCRT); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1BeginDraw) + (JNIEnv *env, jclass that, jintLong m_pDCRT) +{ + ((ID2D1DCRenderTarget*)m_pDCRT)->BeginDraw(); +} +#endif + +#ifndef NO_Direct2DRenderTarget_1SolidBrush +extern "C" JNIEXPORT jintLong JNICALL Gdip_NATIVE(Direct2DRenderTarget_1SolidBrush)(JNIEnv *env, jclass that, jintLong m_pDCRT, jint color); +JNIEXPORT jintLong JNICALL Gdip_NATIVE(Direct2DRenderTarget_1SolidBrush) + (JNIEnv *env, jclass that, jintLong m_pDCRT, jint color) +{ + ID2D1SolidColorBrush* brush; + ((ID2D1DCRenderTarget*)m_pDCRT)->CreateSolidColorBrush(D2D1::ColorF(color), &brush); + return (jintLong)brush; +} +#endif + +#ifndef NO_Direct2DRenderTarget_1DrawLine +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1DrawLine)(JNIEnv *env, jclass that, jintLong m_pDCRT, jintLong brush, jfloat x0, jfloat y0, jfloat x1, jfloat y1, jfloat lineWidth); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1DrawLine) + (JNIEnv *env, jclass that, jintLong m_pDCRT, jintLong brush, jfloat x0, jfloat y0, jfloat x1, jfloat y1, jfloat lineWidth) +{ + ((ID2D1DCRenderTarget*)m_pDCRT)->DrawLine(D2D1::Point2F(x0, y0), D2D1::Point2F(x1, y1), (ID2D1SolidColorBrush*)brush, lineWidth); +} +#endif + +#ifndef NO_Direct2DRenderTarget_1DrawLineStroke +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1DrawLineStroke)(JNIEnv *env, jclass that, jintLong m_pDCRT, jintLong brush, jfloat x0, jfloat y0, jfloat x1, jfloat y1, jfloat lineWidth, jintLong stroke); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1DrawLineStroke) + (JNIEnv *env, jclass that, jintLong m_pDCRT, jintLong brush, jfloat x0, jfloat y0, jfloat x1, jfloat y1, jfloat lineWidth, jintLong stroke) +{ + ((ID2D1DCRenderTarget*)m_pDCRT)->DrawLine(D2D1::Point2F(x0, y0), D2D1::Point2F(x1, y1), (ID2D1SolidColorBrush*)brush, lineWidth, (ID2D1StrokeStyle*)stroke); +} +#endif + +#ifndef NO_Direct2DRenderTarget_1EndDraw +extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1EndDraw)(JNIEnv *env, jclass that, jintLong m_pDCRT); +JNIEXPORT void JNICALL Gdip_NATIVE(Direct2DRenderTarget_1EndDraw) + (JNIEnv *env, jclass that, jintLong m_pDCRT) +{ + ((ID2D1DCRenderTarget*)m_pDCRT)->EndDraw(); +} +#endif + #ifndef NO_BitmapData_1delete extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(BitmapData_1delete)(JNIEnv *env, jclass that, jintLong arg0); JNIEXPORT void JNICALL Gdip_NATIVE(BitmapData_1delete) Index: Eclipse SWT PI/win32/library/gdip_stats.cpp =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.cpp,v retrieving revision 1.47 diff -u -r1.47 gdip_stats.cpp --- Eclipse SWT PI/win32/library/gdip_stats.cpp 1 Jul 2009 14:49:45 -0000 1.47 +++ Eclipse SWT PI/win32/library/gdip_stats.cpp 14 Apr 2010 14:19:01 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,8 +14,8 @@ #ifdef NATIVE_STATS -int Gdip_nativeFunctionCount = 186; -int Gdip_nativeFunctionCallCount[186]; +int Gdip_nativeFunctionCount = 200; +int Gdip_nativeFunctionCallCount[200]; char * Gdip_nativeFunctionNames[] = { "BitmapData_1delete", "BitmapData_1new", @@ -45,6 +45,20 @@ "ColorPalette_1sizeof", "Color_1delete", "Color_1new", + "Direct2DFactory_1CreateDCRenderTarget", + "Direct2DRenderTarget_1BeginDraw", + "Direct2DRenderTarget_1BindDC", + "Direct2DRenderTarget_1DrawLine", + "Direct2DRenderTarget_1DrawLineStroke", + "Direct2DRenderTarget_1EndDraw", + "Direct2DRenderTarget_1Rotate", + "Direct2DRenderTarget_1Scale", + "Direct2DRenderTarget_1Screw", + "Direct2DRenderTarget_1SolidBrush", + "Direct2DRenderTarget_1Translation", + "Direct2DStrokeStyle_1new", + "Direct2D_1CreateFactory", + "Direct2D_1SafeRelease", "FontFamily_1GetFamilyName", "FontFamily_1IsAvailable", "FontFamily_1delete", Index: Eclipse SWT PI/win32/library/gdip_stats.h =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.h,v retrieving revision 1.48 diff -u -r1.48 gdip_stats.h --- Eclipse SWT PI/win32/library/gdip_stats.h 1 Jul 2009 14:49:45 -0000 1.48 +++ Eclipse SWT PI/win32/library/gdip_stats.h 14 Apr 2010 14:19:01 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -53,6 +53,20 @@ ColorPalette_1sizeof_FUNC, Color_1delete_FUNC, Color_1new_FUNC, + Direct2DFactory_1CreateDCRenderTarget_FUNC, + Direct2DRenderTarget_1BeginDraw_FUNC, + Direct2DRenderTarget_1BindDC_FUNC, + Direct2DRenderTarget_1DrawLine_FUNC, + Direct2DRenderTarget_1DrawLineStroke_FUNC, + Direct2DRenderTarget_1EndDraw_FUNC, + Direct2DRenderTarget_1Rotate_FUNC, + Direct2DRenderTarget_1Scale_FUNC, + Direct2DRenderTarget_1Screw_FUNC, + Direct2DRenderTarget_1SolidBrush_FUNC, + Direct2DRenderTarget_1Translation_FUNC, + Direct2DStrokeStyle_1new_FUNC, + Direct2D_1CreateFactory_FUNC, + Direct2D_1SafeRelease_FUNC, FontFamily_1GetFamilyName_FUNC, FontFamily_1IsAvailable_FUNC, FontFamily_1delete_FUNC, Index: Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java,v retrieving revision 1.51 diff -u -r1.51 Gdip.java --- Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java 1 Jul 2009 14:50:46 -0000 1.51 +++ Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java 14 Apr 2010 14:19:02 -0000 @@ -36,6 +36,7 @@ public static final int FillModeAlternate = 0; public static final int FillModeWinding = 1; public static final int DashCapFlat = 0; + public static final int DashCapSquare = 1; public static final int DashCapRound = 2; public static final int DashCapTriangle = 3; public static final int DashStyleSolid = 0; @@ -161,6 +162,93 @@ * @param hicon cast=(HICON) */ public static final native int /*long*/ Bitmap_new(int /*long*/ hicon); + +/** + * @method flags=cpp no_gen + */ +public static final native int Direct2D_CreateFactory(); + +/** + * @method flags=cpp no_gen + * @param m_pD2DFactory cast=(ID2D1Factory) + */ +public static final native int Direct2DFactory_CreateDCRenderTarget(int /*long*/ m_pD2DFactory); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + * @param hdc cast=(HDC) + */ +public static final native void Direct2DRenderTarget_BindDC(int /*long*/ m_pDCRT, int /*long*/ hdc, int width, int height); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native void Direct2DRenderTarget_BeginDraw(int /*long*/ m_pDCRT); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native int Direct2DRenderTarget_SolidBrush(int /*long*/ m_pDCRT, int color); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native void Direct2DRenderTarget_Rotate(int /*long*/ m_pDCRT, float angle); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native void Direct2DRenderTarget_Scale(int /*long*/ m_pDCRT, float sizeX, float sizeY); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native void Direct2DRenderTarget_Screw(int /*long*/ m_pDCRT, float angleX, float angleY); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native void Direct2DRenderTarget_Translation(int /*long*/ m_pDCRT, float moveX, float moveY); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native int Direct2DStrokeStyle_new(int /*long*/ factory, int /*long*/ strokeStyle, int direct2D_startCap, int endCap, int dashCap, int lineJoin, float miterLimit, int dashStyle, float dashOffset, float[] dashes); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native void Direct2D_SafeRelease(int /*long*/ ppInterfaceToRelease); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + * @param brush cast=(ID2D1SolidColorBrush) + */ +public static final native void Direct2DRenderTarget_DrawLine(int /*long*/ m_pDCRT, int /*long*/ brush, float x0, float y0, float x1, float y1, float width); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + * @param brush cast=(ID2D1SolidColorBrush) + */ +public static final native void Direct2DRenderTarget_DrawLineStroke(int /*long*/ m_pDCRT, int /*long*/ brush, float x0, float y0, float x1, float y1, float width, int /*long*/ stroke); + +/** + * @method flags=cpp no_gen + * @param m_pDCRT cast=(ID2D1DCRenderTarget) + */ +public static final native void Direct2DRenderTarget_EndDraw(int /*long*/ m_pDCRT); + /** * @method flags=new * @param format cast=(PixelFormat) Index: Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java,v retrieving revision 1.438 diff -u -r1.438 OS.java --- Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java 31 Mar 2010 13:15:33 -0000 1.438 +++ Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java 14 Apr 2010 14:19:05 -0000 @@ -25,6 +25,7 @@ public static final boolean IsWin95; public static final boolean IsWinNT; public static final boolean IsWinCE; + public static final boolean IsWin7; public static final boolean IsPPC; public static final boolean IsHPC; public static final boolean IsSP; @@ -89,6 +90,9 @@ WIN32_MINOR = info.dwMinorVersion; WIN32_VERSION = VERSION (WIN32_MAJOR, WIN32_MINOR); IsUnicode = !IsWin32s && !IsWin95; + + /* Check if it is Windows 7 to provide Direct2D support */ + IsWin7 = OS.WIN32_VERSION >= OS.VERSION (6, 1) ? true : false; /* Load the manifest to force the XP Theme */ if (System.getProperty (NO_MANIFEST) == null) { Index: Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java,v retrieving revision 1.264 diff -u -r1.264 GC.java --- Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java 13 Apr 2010 19:08:34 -0000 1.264 +++ Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java 14 Apr 2010 14:19:07 -0000 @@ -72,7 +72,10 @@ * @noreference This field is not intended to be referenced by clients. */ public int /*long*/ handle; - + + // Field to check if BeginDraw method was called in direct2d + private boolean isDrawing = false; + Drawable drawable; GCData data; @@ -179,10 +182,108 @@ void checkGC(int mask) { int state = data.state; + beginDrawDirect2D(); if ((state & mask) == mask) return; state = (state ^ mask) & mask; data.state |= mask; int /*long*/ gdipGraphics = data.gdipGraphics; + int /*long*/ renderTarget = data.direct2DRenderTarget; + if (OS.IsWin7 && renderTarget != 0) { + float width = data.lineWidth; + if ((state & FOREGROUND) != 0 || (state & (LINE_WIDTH | LINE_STYLE | LINE_MITERLIMIT | LINE_JOIN | LINE_CAP)) != 0) { + // create direct2d solid color brush + if (data.direct2DBrush != 0) Gdip.Direct2D_SafeRelease(data.direct2DBrush); + data.direct2DBrush = 0; + int brush; + // use solid brush + int foreground = data.foreground; + //int rgb = ((foreground >> 16) & 0xFF) | (foreground & 0xFF00) | ((foreground & 0xFF) << 16); + //brush = Gdip.Direct2D_SolidBrush_new(rgb); + brush = Gdip.Direct2DRenderTarget_SolidBrush(data.direct2DRenderTarget, foreground); + if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES); + data.direct2DBrush = brush; + } + if ((state & LINE_STYLE) != 0) { + float[] dashes = null; + float dashOffset = 0; + int dashStyle = Gdip.DashStyleSolid; + switch (data.lineStyle) { + case SWT.LINE_SOLID: break; + case SWT.LINE_DOT: dashStyle = Gdip.DashStyleDot; if (width == 0) dashes = LINE_DOT_ZERO; break; + case SWT.LINE_DASH: dashStyle = Gdip.DashStyleDash; if (width == 0) dashes = LINE_DASH_ZERO; break; + case SWT.LINE_DASHDOT: dashStyle = Gdip.DashStyleDashDot; if (width == 0) dashes = LINE_DASHDOT_ZERO; break; + case SWT.LINE_DASHDOTDOT: dashStyle = Gdip.DashStyleDashDotDot; if (width == 0) dashes = LINE_DASHDOTDOT_ZERO; break; + case SWT.LINE_CUSTOM: { + if (data.lineDashes != null) { + dashStyle = 5; // custom style + dashOffset = data.direct2DDashOffset = data.lineDashesOffset / Math.max (1, width); + dashes = new float[data.lineDashes.length * 2]; + for (int i = 0; i < data.lineDashes.length; i++) { + float dash = data.lineDashes[i] / Math.max (1, width); + dashes[i] = dash; + dashes[i + data.lineDashes.length] = dash; + } + data.direct2DDashes = dashes; + } + } + } + data.direct2DDashStyle = dashStyle; + data.direct2DDashOffset = dashOffset; + + } + if ((state & LINE_MITERLIMIT) != 0) { + data.direct2DMiterLimit = data.lineMiterLimit; + } + if ((state & LINE_JOIN) != 0) { + int joinStyle = 0; + switch (data.lineJoin) { + case SWT.JOIN_MITER: joinStyle = Gdip.LineJoinMiter; break; + case SWT.JOIN_BEVEL: joinStyle = Gdip.LineJoinBevel; break; + case SWT.JOIN_ROUND: joinStyle = Gdip.LineJoinRound; break; + } + data.direct2DLineJoin = joinStyle; + } + if ((state & LINE_CAP) != 0) { + int dashCap = Gdip.DashCapFlat, capStyle = 0; + switch (data.lineCap) { + case SWT.CAP_FLAT: capStyle = Gdip.LineCapFlat; dashCap = Gdip.DashCapSquare; break; + case SWT.CAP_ROUND: capStyle = Gdip.LineCapRound; dashCap = Gdip.DashCapRound; break; + case SWT.CAP_SQUARE: capStyle = Gdip.LineCapSquare; dashCap = Gdip.DashCapSquare; break; + } + data.direct2DDashCap = dashCap; + data.direct2DEndCap = capStyle; + data.direct2DStartCap = capStyle; + } + data.direct2DStrokeStyle = Gdip.Direct2DStrokeStyle_new( + data.direct2DFactory, + data.direct2DStrokeStyle, + data.direct2DStartCap, + data.direct2DEndCap, data.direct2DDashCap, + data.direct2DLineJoin, data.direct2DMiterLimit, + data.direct2DDashStyle, data.direct2DDashOffset, + data.direct2DDashes); + if ((state & DRAW_OFFSET) != 0) { + data.gdipXOffset = data.gdipYOffset = 0; + int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); + PointF point = new PointF(); + point.X = point.Y = 1; + Gdip.Graphics_GetTransform(gdipGraphics, matrix); + Gdip.Matrix_TransformVectors(matrix, point, 1); + Gdip.Matrix_delete(matrix); + float scaling = point.X; + if (scaling < 0) scaling = -scaling; + float penWidth = data.lineWidth * scaling; + if (penWidth == 0 || ((int)penWidth % 2) == 1) { + data.gdipXOffset = 0.5f / scaling; + } + scaling = point.Y; + if (scaling < 0) scaling = -scaling; + penWidth = data.lineWidth * scaling; + if (penWidth == 0 || ((int)penWidth % 2) == 1) { + data.gdipYOffset = 0.5f / scaling; + } + } + } if (gdipGraphics != 0) { int /*long*/ pen = data.gdipPen; float width = data.lineWidth; @@ -644,6 +745,7 @@ */ void destroy() { boolean gdip = data.gdipGraphics != 0; + disposeDirect2D(); disposeGdip(); if (gdip && (data.style & SWT.MIRRORED) != 0) { OS.SetLayout(handle, OS.GetLayout(handle) | OS.LAYOUT_RTL); @@ -696,6 +798,20 @@ data.gdipFont = data.gdipPen = data.hGDIFont = 0; } +void disposeDirect2D() { + endDrawDirect2D(); + if (data.direct2DBrush != 0) Gdip.Direct2D_SafeRelease(data.direct2DBrush); + if (data.direct2DStrokeStyle != 0) Gdip.Direct2D_SafeRelease(data.direct2DStrokeStyle); + if (data.direct2DRenderTarget != 0) Gdip.Direct2D_SafeRelease(data.direct2DRenderTarget); + if (data.direct2DFactory != 0) Gdip.Direct2D_SafeRelease(data.direct2DFactory); + data.direct2DBrush = data.direct2DStrokeStyle = data.direct2DRenderTarget = + data.direct2DFactory = data.direct2DStartCap = data.direct2DEndCap = + data.direct2DDashCap = data.direct2DLineJoin = data.direct2DDashStyle = 0; + data.direct2DMiterLimit = 10.0f; + data.direct2DDashOffset = 0.0f; + data.direct2DDashes = new float[0]; +} + /** * Draws the outline of a circular or elliptical arc * within the specified rectangular area. @@ -728,6 +844,7 @@ public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); + endDrawDirect2D(); if (width < 0) { x = x + width; width = -width; @@ -826,6 +943,7 @@ public void drawFocus (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if ((data.uiState & OS.UISF_HIDEFOCUS) != 0) return; + endDrawDirect2D(); data.focusDrawn = true; int /*long*/ hdc = handle; int state = 0; @@ -944,6 +1062,11 @@ } void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { + // TODO solve problem with drawing on GC created locally (no event.gc) + if (srcImage.memGC.data.direct2DRenderTarget != 0) { + srcImage.memGC.endDrawDirect2D(); + } + endDrawDirect2D(); if (data.gdipGraphics != 0) { //TODO - cache bitmap int /*long*/ [] gdipImage = srcImage.createGdipImage(); @@ -1658,6 +1781,47 @@ OS.DeleteDC(srcHdc); } +void initDirect2D() { + if (!OS.IsWin7 || data.direct2DRenderTarget != 0) return; + data.direct2DFactory = Gdip.Direct2D_CreateFactory(); + data.direct2DRenderTarget = Gdip.Direct2DFactory_CreateDCRenderTarget(data.direct2DFactory); + int width = 0; + int height = 0; + int /*long*/ hwnd = OS.IsWinCE ? data.hwnd : OS.WindowFromDC(handle); + if (hwnd != 0) { + RECT rect = new RECT(); + OS.GetClientRect(hwnd, rect); + width = rect.right - rect.left; + height = rect.bottom - rect.top; + } else { + int /*long*/ hBitmap = OS.GetCurrentObject(handle, OS.OBJ_BITMAP); + BITMAP bm = new BITMAP(); + OS.GetObject(hBitmap, BITMAP.sizeof, bm); + width = bm.bmWidth; + } + Gdip.Direct2DRenderTarget_BindDC(data.direct2DRenderTarget, handle, width, height); + if (data.direct2DBrush == 0) { + int brush; + brush = Gdip.Direct2DRenderTarget_SolidBrush(data.direct2DRenderTarget, 0); + if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES); + data.direct2DBrush = brush; + } +} + +void beginDrawDirect2D() { + if (isDrawing || !OS.IsWin7) return; + if (data.direct2DRenderTarget == 0) return; + Gdip.Direct2DRenderTarget_BeginDraw(data.direct2DRenderTarget); + isDrawing = true; +} + +void endDrawDirect2D() { + if (!isDrawing || !OS.IsWin7) return; + if (data.direct2DRenderTarget == 0) return; + Gdip.Direct2DRenderTarget_EndDraw(data.direct2DRenderTarget); + isDrawing = false; +} + /** * Draws a line, using the foreground color, between the points * (x1, y1) and (x2, y2). @@ -1675,7 +1839,16 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); int /*long*/ gdipGraphics = data.gdipGraphics; + int /*long*/ direct2dRenderTarget = data.direct2DRenderTarget; if (gdipGraphics != 0) { + if (OS.IsWin7 && direct2dRenderTarget != 0) { + if (data.direct2DStrokeStyle != 0) { + Gdip.Direct2DRenderTarget_DrawLineStroke(direct2dRenderTarget, data.direct2DBrush, x1, y1, x2, y2, data.direct2DlineWidth, data.direct2DStrokeStyle); + } else { + Gdip.Direct2DRenderTarget_DrawLine(direct2dRenderTarget, data.direct2DBrush, x1, y1, x2, y2, data.direct2DlineWidth); + } + return; + } Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawLine(gdipGraphics, data.gdipPen, x1, y1, x2, y2); Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); @@ -1723,6 +1896,7 @@ public void drawOval (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); + endDrawDirect2D(); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); @@ -1765,6 +1939,7 @@ if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); initGdip(); checkGC(DRAW); + endDrawDirect2D(); int /*long*/ gdipGraphics = data.gdipGraphics; Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawPath(gdipGraphics, data.gdipPen, path.handle); @@ -1792,6 +1967,7 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (data.gdipGraphics != 0) { checkGC(DRAW); + endDrawDirect2D(); Gdip.Graphics_FillRectangle(data.gdipGraphics, getFgBrush(), x, y, 1, 1); return; } @@ -1819,6 +1995,7 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkGC(DRAW); + endDrawDirect2D(); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); @@ -1864,6 +2041,7 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkGC(DRAW); + endDrawDirect2D(); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); @@ -1912,6 +2090,7 @@ public void drawRectangle (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); + endDrawDirect2D(); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { if (width < 0) { @@ -1988,6 +2167,7 @@ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); + endDrawDirect2D(); if (data.gdipGraphics != 0) { drawRoundRectangleGdip(data.gdipGraphics, data.gdipPen, x, y, width, height, arcWidth, arcHeight); return; @@ -2143,6 +2323,7 @@ int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { checkGC(FONT | FOREGROUND | (isTransparent ? 0 : BACKGROUND)); + endDrawDirect2D(); drawText(gdipGraphics, string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0, null); return; } @@ -2154,6 +2335,7 @@ rop2 = OS.GetROP2(handle); } checkGC(FONT | FOREGROUND_TEXT | BACKGROUND_TEXT); + endDrawDirect2D(); int oldBkMode = OS.SetBkMode(handle, isTransparent ? OS.TRANSPARENT : OS.OPAQUE); RECT rect = null; SIZE size = null; @@ -2293,6 +2475,7 @@ int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { checkGC(FONT | FOREGROUND | ((flags & SWT.DRAW_TRANSPARENT) != 0 ? 0 : BACKGROUND)); + endDrawDirect2D(); drawText(gdipGraphics, string, x, y, flags, null); return; } @@ -2642,7 +2825,7 @@ * @see #hashCode */ public boolean equals (Object object) { - return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle)); + return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle) && (data.direct2DRenderTarget == ((GC)object).data.direct2DRenderTarget)); } /** @@ -2680,6 +2863,7 @@ public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); + endDrawDirect2D(); if (width < 0) { x = x + width; width = -width; @@ -2809,6 +2993,7 @@ } if (data.gdipGraphics != 0) { initGdip(); + endDrawDirect2D(); PointF p1= new PointF(), p2 = new PointF(); p1.X = x; p1.Y = y; @@ -2907,6 +3092,7 @@ public void fillOval (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); + endDrawDirect2D(); if (data.gdipGraphics != 0) { Gdip.Graphics_FillEllipse(data.gdipGraphics, data.gdipBrush, x, y, width, height); return; @@ -2944,6 +3130,7 @@ if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); initGdip(); checkGC(FILL); + endDrawDirect2D(); int mode = OS.GetPolyFillMode(handle) == OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; Gdip.GraphicsPath_SetFillMode(path.handle, mode); Gdip.Graphics_FillPath(data.gdipGraphics, data.gdipBrush, path.handle); @@ -2972,6 +3159,7 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkGC(FILL); + endDrawDirect2D(); if (data.gdipGraphics != 0) { int mode = OS.GetPolyFillMode(handle) == OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, pointArray, pointArray.length / 2, mode); @@ -3008,6 +3196,7 @@ public void fillRectangle (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); + endDrawDirect2D(); if (data.gdipGraphics != 0) { if (width < 0) { x = x + width; @@ -3071,6 +3260,7 @@ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); + endDrawDirect2D(); if (data.gdipGraphics != 0) { fillRoundRectangleGdip(data.gdipGraphics, data.gdipBrush, x, y, width, height, arcWidth, arcHeight); return; @@ -3160,6 +3350,7 @@ public int getAdvanceWidth(char ch) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FONT); + if (OS.IsWinCE) { SIZE size = new SIZE(); OS.GetTextExtentPoint32W(handle, new char[]{ch}, 1, size); @@ -4075,6 +4266,7 @@ if (advanced && data.gdipGraphics != 0) return; if (advanced) { try { + initDirect2D(); initGdip(); } catch (SWTException e) {} } else { @@ -4134,6 +4326,7 @@ default: SWT.error(SWT.ERROR_INVALID_ARGUMENT); } + if (OS.IsWin7) initDirect2D(); initGdip(); Gdip.Graphics_SetSmoothingMode(data.gdipGraphics, mode); } @@ -4618,6 +4811,18 @@ data.lineDashesOffset = dashOffset; data.lineMiterLimit = miterLimit; data.state &= ~mask; + + initDirect2D(); + if (OS.IsWin7 && data.direct2DRenderTarget != 0) { + data.direct2DStartCap = cap; + data.direct2DEndCap = cap; + data.direct2DDashCap = cap; + data.direct2DLineJoin = join; + if (dashes != null) data.direct2DDashes = dashes; + data.direct2DDashOffset = dashOffset; + data.direct2DMiterLimit = miterLimit; + data.direct2DlineWidth = lineWidth; + } } /** @@ -4780,6 +4985,7 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (data.lineWidth == lineWidth) return; data.lineWidth = lineWidth; + data.direct2DlineWidth = lineWidth; data.state &= ~(LINE_WIDTH | DRAW_OFFSET); } @@ -4927,6 +5133,7 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); checkGC(FONT); + endDrawDirect2D(); int length = string.length(); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { @@ -5006,6 +5213,7 @@ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); checkGC(FONT); + endDrawDirect2D(); int /*long*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { Point size = new Point(0, 0); Index: Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java,v retrieving revision 1.31 diff -u -r1.31 GCData.java --- Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java 1 Jul 2009 14:50:13 -0000 1.31 +++ Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java 14 Apr 2010 14:19:07 -0000 @@ -61,4 +61,18 @@ public float gdipXOffset, gdipYOffset; public int uiState = 0; public boolean focusDrawn; + + public int /*long*/ direct2DRenderTarget; + int /*long*/ direct2DBrush; + int /*long*/ direct2DStrokeStyle; + int /*long*/ direct2DFactory; + float direct2DlineWidth = 1; + int direct2DStartCap = 0; + int direct2DEndCap = 0; + int direct2DDashCap = 0; + int direct2DLineJoin = 0; + float direct2DMiterLimit = 10.0f; + int direct2DDashStyle = 0; + float direct2DDashOffset = 0.0f; + float[] direct2DDashes = new float[0]; }