Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/java2d/d3d/D3DGlyphCache.cpp
32288 views
1
/*
2
* Copyright (c) 2007, 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
#include "D3DGlyphCache.h"
27
#include "D3DTextRenderer.h"
28
#include "D3DRenderQueue.h"
29
30
void D3DGlyphCache_FlushGlyphVertexCache();
31
32
// static
33
HRESULT
34
D3DGlyphCache::CreateInstance(D3DContext *pCtx, GlyphCacheType gcType,
35
D3DGlyphCache **ppGlyphCache)
36
{
37
HRESULT res;
38
39
J2dTraceLn(J2D_TRACE_INFO, "D3DGlyphCache::CreateInstance");
40
41
*ppGlyphCache = new D3DGlyphCache(gcType);
42
if (FAILED(res = (*ppGlyphCache)->Init(pCtx))) {
43
delete *ppGlyphCache;
44
*ppGlyphCache = NULL;
45
}
46
return res;
47
}
48
49
D3DGlyphCache::D3DGlyphCache(GlyphCacheType type)
50
{
51
J2dTraceLn1(J2D_TRACE_INFO, "D3DGlyphCache::D3DGlyphCache gcType=%d", type);
52
53
pCtx = NULL;
54
gcType = type;
55
pGlyphCacheRes = NULL;
56
pGlyphCache = NULL;
57
tileFormat = (gcType == CACHE_GRAY) ? TILEFMT_1BYTE_ALPHA : TILEFMT_UNKNOWN;
58
lastRGBOrder = JNI_FALSE;
59
}
60
61
D3DGlyphCache::~D3DGlyphCache()
62
{
63
J2dTraceLn(J2D_TRACE_INFO, "D3DGlyphCache::~D3DGlyphCache");
64
65
ReleaseDefPoolResources();
66
67
pCtx = NULL;
68
if (pGlyphCache != NULL) {
69
AccelGlyphCache_Free(pGlyphCache);
70
pGlyphCache = NULL;
71
}
72
}
73
74
void
75
D3DGlyphCache::ReleaseDefPoolResources()
76
{
77
J2dTraceLn(J2D_TRACE_INFO, "D3DGlyphCache::ReleaseDefPoolResources");
78
79
AccelGlyphCache_Invalidate(pGlyphCache);
80
// REMIND: the glyph cache texture is not in the default pool, so
81
// this can be optimized not to release the texture
82
pCtx->GetResourceManager()->ReleaseResource(pGlyphCacheRes);
83
pGlyphCacheRes = NULL;
84
}
85
86
HRESULT
87
D3DGlyphCache::Init(D3DContext *pCtx)
88
{
89
D3DFORMAT format;
90
91
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
92
93
J2dTraceLn1(J2D_TRACE_INFO, "D3DGlyphCache::Init pCtx=%x", pCtx);
94
95
this->pCtx = pCtx;
96
97
if (pGlyphCache == NULL) {
98
// init glyph cache data structure
99
pGlyphCache = AccelGlyphCache_Init(D3DTR_CACHE_WIDTH,
100
D3DTR_CACHE_HEIGHT,
101
D3DTR_CACHE_CELL_WIDTH,
102
D3DTR_CACHE_CELL_HEIGHT,
103
D3DGlyphCache_FlushGlyphVertexCache);
104
if (pGlyphCache == NULL) {
105
J2dRlsTraceLn(J2D_TRACE_ERROR,
106
"D3DGlyphCache::Init: "\
107
"could not init D3D glyph cache");
108
return E_FAIL;
109
}
110
}
111
112
if (gcType == CACHE_GRAY) {
113
format = pCtx->IsTextureFormatSupported(D3DFMT_A8) ?
114
D3DFMT_A8 : D3DFMT_A8R8G8B8;
115
} else { // gcType == CACHE_LCD
116
format = pCtx->IsTextureFormatSupported(D3DFMT_R8G8B8) ?
117
D3DFMT_R8G8B8 : D3DFMT_A8R8G8B8;
118
}
119
120
HRESULT res = pCtx->GetResourceManager()->
121
CreateTexture(D3DTR_CACHE_WIDTH, D3DTR_CACHE_HEIGHT,
122
FALSE/*isRTT*/, FALSE/*isOpaque*/, &format, 0/*usage*/,
123
&pGlyphCacheRes);
124
if (FAILED(res)) {
125
J2dRlsTraceLn(J2D_TRACE_ERROR,
126
"D3DGlyphCache::Init: "\
127
"could not create glyph cache texture");
128
}
129
130
return res;
131
}
132
133
HRESULT
134
D3DGlyphCache::AddGlyph(GlyphInfo *glyph)
135
{
136
HRESULT res = S_OK;
137
138
RETURN_STATUS_IF_NULL(pGlyphCacheRes, E_FAIL);
139
140
CacheCellInfo *cellInfo = AccelGlyphCache_AddGlyph(pGlyphCache, glyph);
141
if (cellInfo != NULL) {
142
jint pixelsTouchedL = 0, pixelsTouchedR = 0;
143
// store glyph image in texture cell
144
res = pCtx->UploadTileToTexture(pGlyphCacheRes,
145
glyph->image,
146
cellInfo->x, cellInfo->y,
147
0, 0,
148
glyph->width, glyph->height,
149
glyph->rowBytes, tileFormat,
150
&pixelsTouchedL,
151
&pixelsTouchedR);
152
// LCD text rendering optimization: if the number of pixels touched on
153
// the first or last column of the glyph image is less than 1/3 of the
154
// height of the glyph we do not consider them touched.
155
// See D3DTextRenderer.cpp:UpdateCachedDestination for more information.
156
// The leftOff/rightOff are only used in LCD cache case.
157
if (gcType == CACHE_LCD) {
158
jint threshold = glyph->height/3;
159
160
cellInfo->leftOff = pixelsTouchedL < threshold ? 1 : 0;
161
cellInfo->rightOff = pixelsTouchedR < threshold ? -1 : 0;
162
} else {
163
cellInfo->leftOff = 0;
164
cellInfo->rightOff = 0;
165
}
166
}
167
168
return res;
169
}
170
171
HRESULT
172
D3DGlyphCache::CheckGlyphCacheByteOrder(jboolean rgbOrder)
173
{
174
J2dTraceLn(J2D_TRACE_INFO, "D3DGlyphCache::CheckGlyphCacheByteOrder");
175
176
if (gcType != CACHE_LCD) {
177
J2dTraceLn(J2D_TRACE_ERROR, "D3DGlyphCache::CheckGlyphCacheByteOrder"\
178
" invoked on CACHE_GRAY cache type instance!");
179
return E_FAIL;
180
}
181
182
if (rgbOrder != lastRGBOrder) {
183
// need to invalidate the cache in this case; see comments
184
// for lastRGBOrder
185
AccelGlyphCache_Invalidate(pGlyphCache);
186
lastRGBOrder = rgbOrder;
187
}
188
tileFormat = rgbOrder ? TILEFMT_3BYTE_RGB : TILEFMT_3BYTE_BGR;
189
190
return S_OK;
191
}
192
193
/**
194
* This method is invoked in the (relatively rare) case where one or
195
* more glyphs is about to be kicked out of the glyph cache texture.
196
* Here we simply flush the vertex queue of the current context in case
197
* any pending vertices are dependent upon the current glyph cache layout.
198
*/
199
static void
200
D3DGlyphCache_FlushGlyphVertexCache()
201
{
202
D3DContext *d3dc = D3DRQ_GetCurrentContext();
203
if (d3dc != NULL) {
204
J2dTraceLn(J2D_TRACE_INFO, "D3DGlyphCache_FlushGlyphVertexCache");
205
d3dc->FlushVertexQueue();
206
}
207
}
208
209