3261N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A // REMIND: handle error when creation fails 0N/A " current batch limit for for thread 0x%x is %d",
0N/A // Fix for bug 4374079 0N/A // the hDC is NULL for offscreen surfaces - we don't store it 0N/A // in TLS as it must be created new every time. 0N/A // Init graphics state, either because this is our first time 0N/A // using it in this thread or because this thread is now 0N/A // dealing with a different window than it was last time. 3174N/A //(info->wsdoTimeStamp != wsdo->timeStamp). 3174N/A //Checking memory addresses (info->wsdo != wsdo) will not detect 3174N/A //that wsdo points to a newly allocated structure in case 3174N/A //that structure just got allocated at a "recycled" memory location 3174N/A //which previously was pointed by info->wsdo 0N/A // Release cached DC. We use deferred DC releasing mechanism because 0N/A // the DC is associated with cached wsdo and component peer, 0N/A // which may've been disposed by this time, and we have 0N/A // no means of checking against it. 0N/A // This is a window surface 0N/A // First, init the HDC object 0N/A // Note that on NT4 we don't need to do a realize here: the 0N/A // palette-sharing takes care of color issues for us. But 0N/A // on win98 if we don't realize a DC's palette, that 0N/A // palette does not appear to have correct access to the 0N/A // logical->system mapping. 0N/A // Second, init the rest of the graphics state 0N/A // Make window-relative from client-relative 0N/A //Likewise, translate GDI calls from client-relative to window-relative 0N/A // Finally, set these new values in the info for this thread 0N/A // cached brush and pen are not associated with any DC, and can be 0N/A // reused, but have to set type to 0 to indicate that no pen/brush 0N/A // were set to the new hdc 3174N/A //store the address and time stamp of newly allocated GDIWinSDOps structure 0N/A * Releases native data stored in Thread local storage. 0N/A * Called by the Disposer when the associated thread dies. 0N/A // move the DC from the active dcs list to 0N/A // the passive dc list to be released later 0N/A * Returns current Thread object. 0N/A}
/* JNI_GetCurrentThread() */ 0N/A * Return the data associated with this thread. 0N/A * NOTE: This function assumes that the SetupThreadGraphicsInfo() 0N/A * function has already been called for this situation (thread, 0N/A * window, etc.), so we can assume that the thread info contains 430N/A * a valid hDC. This should usually be the case since GDIWinSD_Setup 0N/A * is called as part of the GetOps() process. 0N/A * This source file contains support code for loops using the 0N/A * SurfaceData interface to talk to a Win32 drawable from native 430N/A * Utility function to make sure that native and java-level 430N/A * surface depths are matched. They can be mismatched when display-depths 430N/A * change, either between the creation of the Java surfaceData structure 430N/A * and the native ddraw surface, or later when a surface is automatically 430N/A * adjusted to be the new display depth (even if it was created in a different 430N/A case 0:
// Error condition: something is wrong with the surface 430N/A // Java and native surface depths should match exactly for 430N/A // Java surfaceData should be 15 or 16 bits 430N/A // Could have this native depth for either 24- or 32-bit 430N/A // should not get here, but if we do something is odd, so 430N/A // just register a failure 430N/A * Class: sun_java2d_windows_GDIWindowSurfaceData 430N/A * Class: sun_java2d_windows_GDIWindowSurfaceData 0N/A // Init the DIB pixelStride and pixel masks according to 0N/A // the pixel depth. In the 8-bit case, there are no 0N/A // masks as a palette DIB is used instead. Likewise 0N/A // in the 24-bit case, Windows doesn't expect the masks 430N/A // GDIWindowSurfaceData_GetWindow will throw NullPointerException 0N/A // if wsdo->window is NULL 430N/A "GDIWindowSurfaceData_initOps: Surface depth mismatch: "\
0N/A "wsdo->depth=%d device depth=%d. Surface invalidated.",
430N/A "GDIWindowSurfaceData_initOps: Incorrect "\
0N/A "screen number (screen=%d). Surface invalidated.",
0N/A // REMIND: There was originally a condition check here to make sure 430N/A // that we were really dealing with a GDIWindowSurfaceData object, but 0N/A // it did not allow for the existence of other win32-accelerated 0N/A // surface data objects (e.g., Win32OffScreenSurfaceData). I've 0N/A // removed the check for now, but we should replace it with another, 0N/A // more general check against Win32-related surfaces. 0N/A // use the 'no setup' version of GetOps 430N/A "GDIWindowSurfaceData_GetComp: Null pData? pData=0x%x",
430N/A "GDIWindowSurfaceData: bounds changed");
430N/A "GDIWindowSurfaceData_GetWindow: null component");
430N/A "GDIWindowSurfaceData_GetWindow: disposed component");
0N/A " complex clipping region");
0N/A // check to see if the view itself has a complex clip. 0N/A // ::GetClipBox is only API which returns overlapped window status 0N/A // so we set the rView as our clip, and then see if resulting 0N/A // Only other way to figure this out would be to walk the 0N/A // overlapping windows (no API to get the actual visible clip 0N/A // list). Then we'd still have to merge that info with the 0N/A // clip region for the dc (if it exists). 0N/A // REMIND: we can cache the CreateRectRgnIndirect result, 0N/A // and only override with ::SetRectRgn 0N/A // First, create a region handle (need existing HRGN for 0N/A // the following call). 430N/A "GDIWinSD_SimpleClip: failed due to clip status");
0N/A // Now, test the new clip box. If it's still not a 0N/A // SIMPLE region, then our bounds must intersect part of 0N/A // the clipping article 430N/A "GDIWinSD_SimpleClip: failed due to complexity");
0N/A // NOTE: No break here - we want to fall through into the 0N/A // SIMPLE case, adjust our bounds by the new rClip rect 0N/A // and make sure that our locking bounds are not empty. 0N/A // Constrain the bounds to the given clip box 0N/A // If the bounds are 0 or negative, then the bounds have 0N/A // been obscured by the clip box, so return FALSE 0N/A // REMIND: We should probably do something different here 0N/A // instead of simply returning FALSE. Since the bounds are 0N/A // empty we won't end up drawing anything, so why spend the 0N/A // effort of returning false and having GDI do a LOCK_BY_DIB? 0N/A // Perhaps we need a new lock code that will indicate that we 0N/A // shouldn't bother drawing? 430N/A "GDIWinSD_SimpleClip: failed due to empty bounds");
430N/A "GDIWinSD_SimpleClip: failed due to incorrect complexity=%d",
0N/A /* This surfaceLock replaces an earlier implementation which used a 0N/A monitor associated with the peer. That implementation was prone 0N/A to deadlock problems, so it was replaced by a lock that does not 0N/A have dependencies outside of this thread or object. 0N/A However, this lock doesn't necessarily do all that we want. 0N/A For example, a user may issue a call which results in a DIB lock 0N/A and another call which results in a DDraw Blt. We can't guarantee 0N/A what order these operations happen in (they are driver and 0N/A video-card dependent), so locking around the issue of either of 0N/A those calls won't necessarily guarantee a particular result. 0N/A The real solution might be to move away from mixing our 0N/A rendering API's. That is, if we only used DDraw, then we could 0N/A guarantee that all rendering operations would happen in a given 0N/A order. Similarly for GDI. But by mixing them, we leave our 0N/A code at the mercy of driver bugs.*/ 430N/A "GDIWindowSurfaceData: bounds changed");
0N/A // Do an initial clip to the client region of the window 0N/A // Translate to window coords 430N/A "GDIWinSD_Lock: error locking by DIB");
0N/A /* They didn't lock for anything - we won't give them anything */ 0N/A // do not subtract insets from x,y as we take care of it in SD_GetDC 0N/A // Need to create bitmap if we don't have one already or 0N/A // if the existing one is not large enough for this operation 0N/A // or if we are in 8 bpp display mode (because we need to 0N/A // make sure that the latest palette info gets loaded into 0N/A // REMIND: we should find some way to dynamically force bitmap 0N/A // recreation only when the palette changes 0N/A // delete old objects 430N/A "GDIWinSD_GetRasInfo: recreating GDI bitmap");
0N/A // 1,3 byte use BI_RGB, 2,4 byte use BI_BITFIELD... 0N/A // we can use systemEntries here because 0N/A // RGBQUAD is xRGB and systemEntries are stored as xRGB 0N/A // For non-index cases, init the masks for the pixel depth 0N/A for (
int i = 0; i <
3; i++) {
0N/A // REMIND: This would be better if moved to the Lock function 0N/A // so that errors could be dealt with. 0N/A // scanStride is cached along with reuseable bitmap 0N/A // Round up to the next DWORD boundary 0N/A // If the user writes to the bitmap then we should 0N/A // copy the bitmap to the screen during Unlock 0N/A /* They didn't lock for anything - we won't give them anything */ 0N/A // Call SetupTGI to ensure that this thread already has a DC that is 0N/A // compatible with this window. This means that we won't be calling 0N/A // ::SendMessage(GETDC) in the middle of a lock procedure, which creates 0N/A // a potential deadlock situation. 0N/A // Note that calling SetupTGI here means that anybody needing a DC 0N/A // later in this rendering process need only call GetTGI, which 0N/A "Unmatched unlock on Win32 SurfaceData");
430N/A "GDIWinSD_Unlock: do Blt of the bitmap");
0N/A // Don't bother copying to screen if our window has gone away 0N/A // or if the bitmap was not actually written to during this 0N/A * REMIND: This mechanism is just a prototype of a way to manage a 0N/A * small cache of DC objects. It is incomplete in the following ways: 0N/A * - It is not thread-safe! It needs appropriate locking and release calls 0N/A * (perhaps the AutoDC mechanisms from Kestrel) 0N/A * - It does hardly any error checking (What if GetDCEx returns NULL?) 0N/A * - It cannot handle printer DCs and their resolution 0N/A * - It should probably "live" in the native SurfaceData object to allow 0N/A * alternate implementations for printing and embedding 0N/A * - It doesn't handle XOR 0N/A * - It caches the client bounds to determine if clipping is really needed 0N/A * (no way to invalidate the cached bounds and there is probably a better 0N/A * way to manage clip validation in any case) 0N/A int g = (
77 *(c &
0xFF) +
0N/A 150*((c >>
8) &
0xFF) +
0N/A 29 *((c >>
16) &
0xFF) +
128) /
256;
0N/A c = g | (g <<
8) | (g <<
16);
0N/A // return; // REMIND: What to do here? 0N/A // Make the window-relative rect a client-relative 0N/A // init brush and pen 0N/A // Don't actually do anything here: every thread holds its own 0N/A // wsdo-specific DC until the thread goes away or the wsdo 430N/A * Method: GDIWinSD_Dispose 0N/A // ops is assumed non-null as it is checked in SurfaceData_DisposeOps 0N/A // delete old objects 430N/A * Class: sun_java2d_windows_GDIWindowSurfaceData 0N/A * Method: invalidateSD