1 /*
   2  * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef AWT_WIN32GRAPHICSDEVICE_H
  27 #define AWT_WIN32GRAPHICSDEVICE_H
  28 
  29 #include "awt.h"
  30 extern "C" {
  31     #include "img_globals.h"
  32 } // extern "C"
  33 #include "colordata.h"
  34 #include "awt_Palette.h"
  35 #include "Devices.h"
  36 
  37 class AwtPalette;
  38 class Devices;
  39 
  40 class AwtWin32GraphicsDevice {
  41 public:
  42                             AwtWin32GraphicsDevice(int screen, HMONITOR mhnd, Devices *arr);
  43                             ~AwtWin32GraphicsDevice();
  44     void                    UpdateDeviceColorState();
  45     void                    SetGrayness(int grayValue);
  46     int                     GetGrayness() { return colorData->grayscale; }
  47     HDC                     GetDC();
  48     void                    ReleaseDC(HDC hDC);
  49     jobject                 GetColorModel(JNIEnv *env,
  50                                           jboolean useDeviceSettings);
  51     void                    Initialize();
  52     void                    UpdateDynamicColorModel();
  53     BOOL                    UpdateSystemPalette();
  54     unsigned int            *GetSystemPaletteEntries();
  55     unsigned char           *GetSystemInverseLUT();
  56     void                    SetJavaDevice(JNIEnv *env, jobject objPtr);
  57     HPALETTE                SelectPalette(HDC hDC);
  58     void                    RealizePalette(HDC hDC);
  59     HPALETTE                GetPalette();
  60     ColorData               *GetColorData() { return cData; }
  61     int                     GetBitDepth() { return colorData->bitsperpixel; }
  62     HMONITOR                GetMonitor() { return monitor; }
  63     LPMONITORINFO           GetMonitorInfo() { return pMonitorInfo; }
  64     jobject                 GetJavaDevice() { return javaDevice; }
  65     int                     GetDeviceIndex() { return screen; }
  66     void                    Release();
  67     void                    DisableOffscreenAcceleration();
  68     void                    Invalidate(JNIEnv *env);
  69 
  70     static int              DeviceIndexForWindow(HWND hWnd);
  71     static jobject          GetColorModel(JNIEnv *env, jboolean dynamic,
  72                                           int deviceIndex);
  73     static HPALETTE         SelectPalette(HDC hDC, int deviceIndex);
  74     static void             RealizePalette(HDC hDC, int deviceIndex);
  75     static ColorData        *GetColorData(int deviceIndex);
  76     static int              GetGrayness(int deviceIndex);
  77     static void             UpdateDynamicColorModel(int deviceIndex);
  78     static BOOL             UpdateSystemPalette(int deviceIndex);
  79     static HPALETTE         GetPalette(int deviceIndex);
  80     static HMONITOR         GetMonitor(int deviceIndex);
  81     static LPMONITORINFO    GetMonitorInfo(int deviceIndex);
  82     static void             ResetAllMonitorInfo();
  83     static BOOL             IsPrimaryPalettized() { return primaryPalettized; }
  84     static int              GetDefaultDeviceIndex() { return primaryIndex; }
  85     static void             DisableOffscreenAccelerationForDevice(HMONITOR hMonitor);
  86     static HDC              GetDCFromScreen(int screen);
  87     static int              GetScreenFromHMONITOR(HMONITOR mon);
  88 
  89     static int              primaryIndex;
  90     static BOOL             primaryPalettized;
  91     static jclass           indexCMClass;
  92     static jclass           wToolkitClass;
  93     static jfieldID         dynamicColorModelID;
  94     static jfieldID         indexCMrgbID;
  95     static jfieldID         indexCMcacheID;
  96     static jmethodID        paletteChangedMID;
  97 
  98 private:
  99     static BOOL             AreSameMonitors(HMONITOR mon1, HMONITOR mon2);
 100     ImgColorData            *colorData;
 101     AwtPalette              *palette;
 102     ColorData               *cData;     // Could be static, but may sometime
 103                                         // have per-device info in this structure
 104     BITMAPINFO              *gpBitmapInfo;
 105     int                     screen;
 106     HMONITOR                monitor;
 107     LPMONITORINFO           pMonitorInfo;
 108     jobject                 javaDevice;
 109     Devices                 *devicesArray;
 110 
 111     static HDC              MakeDCFromMonitor(HMONITOR);
 112 };
 113 
 114 #endif AWT_WIN32GRAPHICSDEVICE_H