harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r584197 - in /harmony/enhanced/classlib/trunk/modules/awt/src/main: java/windows/org/apache/harmony/awt/gl/windows/ native/gl/windows/ native/gl/windows/include/
Date Fri, 12 Oct 2007 16:38:47 GMT
Author: ayza
Date: Fri Oct 12 09:38:29 2007
New Revision: 584197

URL: http://svn.apache.org/viewvc?rev=584197&view=rev
Log:
Applying patch from HARMONY-4902 ([classlib][awt] GraphicsConfiguration.getColorModel(int
transparency) returns wrong ColorModel)

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGDIPGraphics2D.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsConfiguration.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinVolatileImage.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/WinGraphicsEnvironment.cpp
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/include/org_apache_harmony_awt_gl_windows_WinGraphicsEnvironment.h

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGDIPGraphics2D.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGDIPGraphics2D.java?rev=584197&r1=584196&r2=584197&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGDIPGraphics2D.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGDIPGraphics2D.java
Fri Oct 12 09:38:29 2007
@@ -186,7 +186,12 @@
             if (img == null) {
                 config = new WinGraphicsConfiguration(nw.getId(), getDC());
             } else {
-                config = new WinGraphicsConfiguration(getDC());
+                long hwnd = img.getHWND();
+                if(hwnd != 0){
+                    config = new WinGraphicsConfiguration(hwnd, getDC());
+                }else{
+                    config = img.getGraphicsConfiguration();
+                }
             }
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsConfiguration.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsConfiguration.java?rev=584197&r1=584196&r2=584197&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsConfiguration.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinGraphicsConfiguration.java
Fri Oct 12 09:38:29 2007
@@ -23,6 +23,7 @@
 import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsDevice;
 import java.awt.Rectangle;
+import java.awt.Transparency;
 import java.awt.geom.AffineTransform;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
@@ -68,12 +69,7 @@
     }
 
     public WinGraphicsConfiguration(long hwnd, long hdc) {
-        this(hdc);
         this.device = new WinGraphicsDevice(hwnd);
-    }
-
-    public WinGraphicsConfiguration(long hdc) {
-        this.device = null;
         this.index = -1;
 
         int dci = win32.GetPixelFormat(hdc);
@@ -93,34 +89,34 @@
     private void init(Win32.PIXELFORMATDESCRIPTOR pfd) {
         flags = pfd.get_dwFlags();
         pixelType = pfd.get_iPixelType();
-        if ((pixelType & WindowsDefs.PFD_TYPE_COLORINDEX) == WindowsDefs.PFD_TYPE_COLORINDEX)
{
-            cm = null;
-            return;
-        }
-
         bits = pfd.get_cColorBits();
+
         if (bits == 0) { 
-            cm = null; 
             return; 
         }
-        
-        redBits = pfd.get_cRedBits();
-        redShift = pfd.get_cRedShift();
-        rmask = (int)(Math.pow(2,redBits)-1) << redShift;
-
-        greenBits = pfd.get_cGreenBits();
-        greenShift = pfd.get_cGreenShift();
-        gmask = (int)(Math.pow(2,greenBits)-1) << greenShift;
-
-        blueBits = pfd.get_cBlueBits();
-        blueShift = pfd.get_cBlueShift();
-        bmask = (int)(Math.pow(2,blueBits)-1) << blueShift;
-
-        alphaBits = pfd.get_cAlphaBits();
-        alphaShift = pfd.get_cAlphaShift();
-        amask = (int)(Math.pow(2,alphaBits)-1) << alphaShift;
 
-        cm = new DirectColorModel(bits, rmask, gmask, bmask, amask);
+        if ((pixelType & WindowsDefs.PFD_TYPE_COLORINDEX) != WindowsDefs.PFD_TYPE_COLORINDEX)
{
+            redBits = pfd.get_cRedBits();
+            redShift = pfd.get_cRedShift();
+            rmask = (int)(Math.pow(2,redBits)-1) << redShift;
+
+            greenBits = pfd.get_cGreenBits();
+            greenShift = pfd.get_cGreenShift();
+            gmask = (int)(Math.pow(2,greenBits)-1) << greenShift;
+
+            blueBits = pfd.get_cBlueBits();
+            blueShift = pfd.get_cBlueShift();
+            bmask = (int)(Math.pow(2,blueBits)-1) << blueShift;
+
+            alphaBits = pfd.get_cAlphaBits();
+            alphaShift = pfd.get_cAlphaShift();
+            amask = (int)(Math.pow(2,alphaBits)-1) << alphaShift;
+        }
+
+        long hdc = win32.CreateDCW(null, device.getIDstring(), null, null);
+        cm = createColorModel(hdc);
+        win32.DeleteDC(hdc);
+
     }
 
     @Override
@@ -166,7 +162,14 @@
 
     @Override
     public ColorModel getColorModel(int transparency) {
-        return cm;
+        switch(transparency){
+        case Transparency.BITMASK:
+            return new DirectColorModel(25, 0xFF0000, 0xFF00, 0xFF, 0x1000000);
+        case Transparency.TRANSLUCENT:
+            return ColorModel.getRGBdefault();
+        default:
+            return cm;
+        }
     }
 
     @Override
@@ -242,4 +245,6 @@
     public int getIndex() {
         return index;
     }
+    
+    private native ColorModel createColorModel(long hdc);
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinVolatileImage.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinVolatileImage.java?rev=584197&r1=584196&r2=584197&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinVolatileImage.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/WinVolatileImage.java
Fri Oct 12 09:38:29 2007
@@ -158,4 +158,12 @@
         }
         super.flush();
     }
+    
+    long getHWND(){
+        return hwnd;
+    }
+    
+    WinGraphicsConfiguration getGraphicsConfiguration(){
+        return gc;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/WinGraphicsEnvironment.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/WinGraphicsEnvironment.cpp?rev=584197&r1=584196&r2=584197&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/WinGraphicsEnvironment.cpp
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/WinGraphicsEnvironment.cpp
Fri Oct 12 09:38:29 2007
@@ -22,6 +22,7 @@
 
 #include <windows.h>
 #include "org_apache_harmony_awt_gl_windows_WinGraphicsEnvironment.h"
+#include "gl_GDIPlus.h"
 
 #define MAX_MONITOR_NUMBER 256
 
@@ -77,4 +78,151 @@
         env->SetObjectArrayElement(array, i, monitors.monitors[i]); 
     
     return array;
+}
+
+#define PF_32RGB888    1
+#define PF_16RGB565    2
+#define PF_16RGB555    3
+#define PF_24BGR888    4
+#define PF_8BPP        5
+#define PF_4BPP        6
+#define PF_2BPP        7
+#define PF_1BPP        8
+#define PF_UNKNOWN     0
+
+/*
+ * Class:     org_apache_harmony_awt_gl_windows_WinGraphicsConfiguration
+ * Method:    createColorModel
+ * Signature: (J)Ljava/awt/ColorModel;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_harmony_awt_gl_windows_WinGraphicsConfiguration_createColorModel
+  (JNIEnv *env, jobject obj, jlong hdc)
+{
+    jclass cmClass;
+    jmethodID cmInit;
+    jobject colorModel;
+
+    GLBITMAPINFO bmpInfo;
+    HBITMAP bmp;
+
+    int pfType;
+    int bits;
+
+    DWORD *mask;
+
+    HDC dc = (HDC)hdc;
+    bmp = CreateCompatibleBitmap(dc, 1, 1);
+
+    memset(&bmpInfo, 0, sizeof(GLBITMAPINFO));
+
+    bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+    GetDIBits(dc, bmp, 0, 1, NULL, (BITMAPINFO *)&bmpInfo, DIB_RGB_COLORS);
+    GetDIBits(dc, bmp, 0, 1, NULL, (BITMAPINFO *)&bmpInfo, DIB_RGB_COLORS);
+
+    DeleteObject(bmp);
+
+    bits = bmpInfo.bmiHeader.biBitCount;
+
+    if(bmpInfo.bmiHeader.biCompression == BI_BITFIELDS){
+        mask = (DWORD *)bmpInfo.bmiColors;
+
+        if(mask[0] == 0x7c00 && mask[1] == 0x03e0 && mask[2] == 0x1f){
+
+             pfType = PF_16RGB555;
+
+        }else if(mask[0] == 0xf800 && mask[1] == 0x07e0 && mask[2] == 0x1f){
+
+             pfType = PF_16RGB565;
+
+        }else if(mask[0] == 0xff0000 && mask[1] == 0xff00 && mask[2] == 0xff){
+
+             pfType = PF_32RGB888;
+
+        }else{
+
+             pfType = PF_UNKNOWN;
+
+        }
+    }else{
+        switch(bits){
+        
+        case 1:
+            pfType = PF_1BPP;
+            break;
+        case 2:
+            pfType = PF_2BPP;
+            break;
+        case 4:
+            pfType = PF_4BPP;
+            break;
+        case 8:
+            pfType = PF_8BPP;
+            break;
+        case 16:
+            pfType = PF_16RGB555;
+            break;
+        case 24:
+            pfType = PF_24BGR888;
+            break;
+        case 32:
+            pfType = PF_32RGB888;
+            break;
+        default:
+            pfType = PF_UNKNOWN;
+        }
+    }
+
+    switch(pfType){
+    
+    case PF_1BPP:
+    case PF_2BPP:
+    case PF_4BPP:
+    case PF_8BPP:
+        {
+            int cmapSize = 1 << bits;
+            int cmapByteSize = cmapSize << 2;
+            jbyteArray cmap = env->NewByteArray(cmapByteSize);
+            void *cmapPtr = env->GetPrimitiveArrayCritical(cmap, 0);
+            memcpy(cmapPtr, bmpInfo.bmiColors, cmapByteSize);
+            env->ReleasePrimitiveArrayCritical(cmap, cmapPtr, 0);
+            cmClass = env->FindClass("java/awt/image/IndexColorModel");
+            cmInit = env->GetMethodID(cmClass, "<init>", "(II[BIZ)V"); 
+            colorModel = env->NewObject(cmClass, cmInit, bits, cmapSize, cmap, 0, 0);
+        }
+        break;
+
+    case PF_16RGB555:
+    case PF_16RGB565:
+        cmClass = env->FindClass("java/awt/image/DirectColorModel");
+        cmInit = env->GetMethodID(cmClass, "<init>", "(IIII)V"); 
+        colorModel = env->NewObject(cmClass, cmInit, bits, mask[0], mask[1], mask[2]);
+        break;
+
+    case PF_32RGB888:
+        cmClass = env->FindClass("java/awt/image/DirectColorModel");
+        cmInit = env->GetMethodID(cmClass, "<init>", "(IIII)V"); 
+        colorModel = env->NewObject(cmClass, cmInit, 24, mask[0], mask[1], mask[2]);
+        break;
+
+    case PF_24BGR888:
+        {
+            cmClass = env->FindClass("java/awt/image/ComponentColorModel");
+            cmInit = env->GetMethodID(cmClass, "<init>", "(Ljava/awt/color/ColorSpace;ZZII)V");
+
+            jclass csClass = env->FindClass("java/awt/color/ColorSpace");
+            jmethodID csInit = env->GetStaticMethodID(csClass, "getInstance", "(I)Ljava/awt/color/ColorSpace");
+            jfieldID csFiled = env->GetStaticFieldID(csClass, "CS_sRGB", "I");
+            jint csType = env->GetStaticIntField(csClass, csFiled);
+
+            jobject cs = env->CallStaticObjectMethod(csClass, csInit, csType);
+            colorModel = env->NewObject(cmClass, cmInit, cs, 0, 0, 1, 0);
+        }
+        break;
+
+    default:
+        cmClass = env->FindClass("java/lang/RuntimeException");
+        env->ThrowNew(cmClass, "Unknown Graphics Device Pixel Format");
+
+    }
+    return colorModel;
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/include/org_apache_harmony_awt_gl_windows_WinGraphicsEnvironment.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/include/org_apache_harmony_awt_gl_windows_WinGraphicsEnvironment.h?rev=584197&r1=584196&r2=584197&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/include/org_apache_harmony_awt_gl_windows_WinGraphicsEnvironment.h
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/include/org_apache_harmony_awt_gl_windows_WinGraphicsEnvironment.h
Fri Oct 12 09:38:29 2007
@@ -45,6 +45,11 @@
 JNIEXPORT jobjectArray JNICALL
 Java_org_apache_harmony_awt_gl_windows_WinGraphicsEnvironment_enumerateDisplayDevices(JNIEnv
*, jobject);
 
+/*
+ * Method: org.apache.harmony.awt.gl.windows.WinGraphicsConfiguration.createColorModel(J)Ljava/awt/ColorModel;
+ */
+JNIEXPORT jobject JNICALL
+Java_org_apache_harmony_awt_gl_windows_WinGraphicsConfiguration_createColorModel(JNIEnv *,
jobject, jlong);
 
 #ifdef __cplusplus
 }



Mime
View raw message