< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp

Print this page




  34  * call one of the static methods of this class with the index of
  35  * the device in question.  Those methods will then lock the devices
  36  * array and forward the request to the current device at that
  37  * array index.
  38  */
  39 
  40 #include <awt.h>
  41 #include <sun_awt_Win32GraphicsDevice.h>
  42 #include "awt_Canvas.h"
  43 #include "awt_Win32GraphicsDevice.h"
  44 #include "awt_Window.h"
  45 #include "java_awt_Transparency.h"
  46 #include "java_awt_color_ColorSpace.h"
  47 #include "sun_awt_Win32GraphicsDevice.h"
  48 #include "java_awt_image_DataBuffer.h"
  49 #include "dither.h"
  50 #include "img_util_md.h"
  51 #include "Devices.h"
  52 #include <d2d1.h>
  53 #pragma comment(lib, "d2d1")
  54 
  55 #ifndef MDT_Effective_DPI
  56 #define MDT_Effective_DPI 0
  57 #endif
  58 
  59 uns_ordered_dither_array img_oda_alpha;
  60 
  61 jclass      AwtWin32GraphicsDevice::indexCMClass;
  62 jclass      AwtWin32GraphicsDevice::wToolkitClass;
  63 jfieldID    AwtWin32GraphicsDevice::dynamicColorModelID;
  64 jfieldID    AwtWin32GraphicsDevice::indexCMrgbID;
  65 jfieldID    AwtWin32GraphicsDevice::indexCMcacheID;
  66 jmethodID   AwtWin32GraphicsDevice::paletteChangedMID;
  67 BOOL        AwtWin32GraphicsDevice::primaryPalettized;
  68 int         AwtWin32GraphicsDevice::primaryIndex = 0;
  69 
  70 
  71 /**
  72  * Construct this device.  Store the screen (index into the devices
  73  * array of this object), the array (used in static references via
  74  * particular device indices), the monitor/pMonitorInfo (which other
  75  * classes will inquire of this device), the bits per pixel of this
  76  * device, and information on whether the primary device is palettized.
  77  */


 638     return (int)ceil(x * scaleX);
 639 }
 640 
 641 int AwtWin32GraphicsDevice::ScaleUpY(int y)
 642 {
 643     return (int)ceil(y * scaleY);
 644 }
 645 
 646 int AwtWin32GraphicsDevice::ScaleDownX(int x)
 647 {
 648     return (int)ceil(x / scaleX);
 649 }
 650 
 651 int AwtWin32GraphicsDevice::ScaleDownY(int y)
 652 {
 653     return (int)ceil(y / scaleY);
 654 }
 655 
 656 void AwtWin32GraphicsDevice::InitDesktopScales()
 657 {
 658     unsigned x = 0;
 659     unsigned y = 0;
 660     float dpiX = -1.0f;
 661     float dpiY = -1.0f;
 662 
 663     // for debug purposes
 664     static float scale = -2.0f;
 665     if (scale == -2) {
 666         scale = -1;
 667         char *uiScale = getenv("J2D_UISCALE");
 668         if (uiScale != NULL) {
 669             scale = (float)strtod(uiScale, NULL);
 670             if (errno == ERANGE || scale <= 0) {
 671                 scale = -1;
 672             }
 673         }
 674     }
 675 
 676     if (scale > 0) {
 677         SetScale(scale, scale);
 678         return;
 679     }
 680 
 681     typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*);
 682     static HMODULE hLibSHCoreDll = NULL;
 683     static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL;
 684 
 685     if (hLibSHCoreDll == NULL) {
 686         hLibSHCoreDll = JDK_LoadSystemLibrary("shcore.dll");
 687         if (hLibSHCoreDll != NULL) {
 688             lpGetDpiForMonitor = (GetDpiForMonitorFunc*)GetProcAddress(
 689                 hLibSHCoreDll, "GetDpiForMonitor");
 690         }
 691     }
 692 
 693     if (lpGetDpiForMonitor != NULL) {
 694         HRESULT hResult = lpGetDpiForMonitor(GetMonitor(),
 695                                              MDT_Effective_DPI, &x, &y);
 696         if (hResult == S_OK) {
 697             dpiX = static_cast<float>(x);
 698             dpiY = static_cast<float>(y);
 699         }
 700     } else {
 701         ID2D1Factory* m_pDirect2dFactory;
 702         HRESULT res = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,
 703                                         &m_pDirect2dFactory);
 704         if (res == S_OK) {
 705             m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY);
 706             m_pDirect2dFactory->Release();
 707         }
 708     }
 709 
 710     if (dpiX > 0 && dpiY > 0) {
 711         SetScale(dpiX / 96, dpiY / 96);
 712     }
 713 }
 714 
 715 float AwtWin32GraphicsDevice::GetScaleX()
 716 {
 717     return scaleX;
 718 }
 719 
 720 float AwtWin32GraphicsDevice::GetScaleY()
 721 {
 722     return scaleY;
 723 }
 724 
 725 /**
 726  * Disables offscreen acceleration for this device.  This
 727  * sets a flag in the java object that is used to determine
 728  * whether offscreen surfaces can be created on the device.
 729  */




  34  * call one of the static methods of this class with the index of
  35  * the device in question.  Those methods will then lock the devices
  36  * array and forward the request to the current device at that
  37  * array index.
  38  */
  39 
  40 #include <awt.h>
  41 #include <sun_awt_Win32GraphicsDevice.h>
  42 #include "awt_Canvas.h"
  43 #include "awt_Win32GraphicsDevice.h"
  44 #include "awt_Window.h"
  45 #include "java_awt_Transparency.h"
  46 #include "java_awt_color_ColorSpace.h"
  47 #include "sun_awt_Win32GraphicsDevice.h"
  48 #include "java_awt_image_DataBuffer.h"
  49 #include "dither.h"
  50 #include "img_util_md.h"
  51 #include "Devices.h"
  52 #include <d2d1.h>
  53 #pragma comment(lib, "d2d1")
  54 #include "systemScale.h"



  55 
  56 uns_ordered_dither_array img_oda_alpha;
  57 
  58 jclass      AwtWin32GraphicsDevice::indexCMClass;
  59 jclass      AwtWin32GraphicsDevice::wToolkitClass;
  60 jfieldID    AwtWin32GraphicsDevice::dynamicColorModelID;
  61 jfieldID    AwtWin32GraphicsDevice::indexCMrgbID;
  62 jfieldID    AwtWin32GraphicsDevice::indexCMcacheID;
  63 jmethodID   AwtWin32GraphicsDevice::paletteChangedMID;
  64 BOOL        AwtWin32GraphicsDevice::primaryPalettized;
  65 int         AwtWin32GraphicsDevice::primaryIndex = 0;
  66 
  67 
  68 /**
  69  * Construct this device.  Store the screen (index into the devices
  70  * array of this object), the array (used in static references via
  71  * particular device indices), the monitor/pMonitorInfo (which other
  72  * classes will inquire of this device), the bits per pixel of this
  73  * device, and information on whether the primary device is palettized.
  74  */


 635     return (int)ceil(x * scaleX);
 636 }
 637 
 638 int AwtWin32GraphicsDevice::ScaleUpY(int y)
 639 {
 640     return (int)ceil(y * scaleY);
 641 }
 642 
 643 int AwtWin32GraphicsDevice::ScaleDownX(int x)
 644 {
 645     return (int)ceil(x / scaleX);
 646 }
 647 
 648 int AwtWin32GraphicsDevice::ScaleDownY(int y)
 649 {
 650     return (int)ceil(y / scaleY);
 651 }
 652 
 653 void AwtWin32GraphicsDevice::InitDesktopScales()
 654 {


 655     float dpiX = -1.0f;
 656     float dpiY = -1.0f;
 657     GetScreenDpi(GetMonitor(), &dpiX, &dpiY);















































 658     if (dpiX > 0 && dpiY > 0) {
 659         SetScale(dpiX / 96, dpiY / 96);
 660     }
 661 }
 662 
 663 float AwtWin32GraphicsDevice::GetScaleX()
 664 {
 665     return scaleX;
 666 }
 667 
 668 float AwtWin32GraphicsDevice::GetScaleY()
 669 {
 670     return scaleY;
 671 }
 672 
 673 /**
 674  * Disables offscreen acceleration for this device.  This
 675  * sets a flag in the java object that is used to determine
 676  * whether offscreen surfaces can be created on the device.
 677  */


< prev index next >