1 /*
   2  * Copyright (c) 2001, 2020, 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                    DisableScaleAutoRefresh();
  69     void                    Invalidate(JNIEnv *env);
  70     void                    InitDesktopScales();
  71     void                    SetScale(float scaleX, float scaleY);
  72     float                   GetScaleX();
  73     float                   GetScaleY();
  74     int                     ScaleUpX(int x);
  75     int                     ScaleUpAbsX(int x);
  76     int                     ScaleUpY(int y);
  77     int                     ScaleUpAbsY(int x);
  78     int                     ScaleDownX(int x);
  79     int                     ScaleDownAbsX(int x);
  80     int                     ScaleDownY(int y);
  81     int                     ScaleDownAbsY(int y);
  82 
  83     static int              DeviceIndexForWindow(HWND hWnd);
  84     static jobject          GetColorModel(JNIEnv *env, jboolean dynamic,
  85                                           int deviceIndex);
  86     static HPALETTE         SelectPalette(HDC hDC, int deviceIndex);
  87     static void             RealizePalette(HDC hDC, int deviceIndex);
  88     static ColorData        *GetColorData(int deviceIndex);
  89     static int              GetGrayness(int deviceIndex);
  90     static void             UpdateDynamicColorModel(int deviceIndex);
  91     static BOOL             UpdateSystemPalette(int deviceIndex);
  92     static HPALETTE         GetPalette(int deviceIndex);
  93     static HMONITOR         GetMonitor(int deviceIndex);
  94     static LPMONITORINFO    GetMonitorInfo(int deviceIndex);
  95     static void             ResetAllMonitorInfo();
  96     static void             ResetAllDesktopScales();
  97     static BOOL             IsPrimaryPalettized() { return primaryPalettized; }
  98     static int              GetDefaultDeviceIndex() { return primaryIndex; }
  99     static void             DisableOffscreenAccelerationForDevice(HMONITOR hMonitor);
 100     static HDC              GetDCFromScreen(int screen);
 101     static int              GetScreenFromHMONITOR(HMONITOR mon);
 102 
 103     static int              primaryIndex;
 104     static BOOL             primaryPalettized;
 105     static jclass           indexCMClass;
 106     static jclass           wToolkitClass;
 107     static jfieldID         dynamicColorModelID;
 108     static jfieldID         indexCMrgbID;
 109     static jfieldID         indexCMcacheID;
 110     static jmethodID        paletteChangedMID;
 111 
 112 private:
 113     static BOOL             AreSameMonitors(HMONITOR mon1, HMONITOR mon2);
 114     ImgColorData            *colorData;
 115     AwtPalette              *palette;
 116     ColorData               *cData;     // Could be static, but may sometime
 117                                         // have per-device info in this structure
 118     BITMAPINFO              *gpBitmapInfo;
 119     int                     screen;
 120     HMONITOR                monitor;
 121     LPMONITORINFO           pMonitorInfo;
 122     jobject                 javaDevice;
 123     Devices                 *devicesArray;
 124     float                   scaleX;
 125     float                   scaleY;
 126     BOOL                    disableScaleAutoRefresh;
 127 
 128     static HDC              MakeDCFromMonitor(HMONITOR);
 129     static int              ClipRound(double value);
 130 };
 131 
 132 #endif AWT_WIN32GRAPHICSDEVICE_H