mirror of
https://github.com/danbulant/node-x11
synced 2026-05-19 12:28:58 +00:00
more XRender requests
This commit is contained in:
parent
5c37ae5bbb
commit
b46876bdc3
3 changed files with 333 additions and 26 deletions
|
|
@ -65,30 +65,31 @@ module.exports = function( display, host, cb )
|
|||
} else {
|
||||
XAuthorityFile = process.env.HOME + '/.Xauthority';
|
||||
}
|
||||
fs.readFile(XAuthorityFile, function (err, data) {
|
||||
}
|
||||
|
||||
if (err)
|
||||
{
|
||||
if (err.code == 'ENOENT')
|
||||
{
|
||||
cb('','');
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
fs.readFile(XAuthorityFile, function (err, data) {
|
||||
|
||||
var auth = parseXauth(data);
|
||||
for (cookieNum in auth)
|
||||
if (err)
|
||||
{
|
||||
if (err.code == 'ENOENT')
|
||||
{
|
||||
var cookie = auth[cookieNum];
|
||||
if (cookie.display == display && cookie.address == host)
|
||||
{
|
||||
cb( cookie.authName, cookie.authData );
|
||||
return;
|
||||
}
|
||||
cb('','');
|
||||
return;
|
||||
}
|
||||
// throw 'No auth cookie matching display=' + display + ' and host=' + host;
|
||||
cb( '', '' );
|
||||
});
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
var auth = parseXauth(data);
|
||||
for (cookieNum in auth)
|
||||
{
|
||||
var cookie = auth[cookieNum];
|
||||
if (cookie.display == display && cookie.address == host)
|
||||
{
|
||||
cb( cookie.authName, cookie.authData );
|
||||
return;
|
||||
}
|
||||
}
|
||||
// throw 'No auth cookie matching display=' + display + ' and host=' + host;
|
||||
cb( '', '' );
|
||||
});
|
||||
}
|
||||
173
test/render.h
Normal file
173
test/render.h
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* $XFree86: xc/include/extensions/render.h,v 1.11 2002/11/23 02:34:45 keithp Exp $
|
||||
*
|
||||
* Copyright © 2000 SuSE, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of SuSE not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. SuSE makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
|
||||
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Author: Keith Packard, SuSE, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _RENDER_H_
|
||||
#define _RENDER_H_
|
||||
|
||||
typedef unsigned long Glyph;
|
||||
typedef unsigned long GlyphSet;
|
||||
typedef unsigned long Picture;
|
||||
typedef unsigned long PictFormat;
|
||||
|
||||
#define RENDER_NAME "RENDER"
|
||||
#define RENDER_MAJOR 0
|
||||
#define RENDER_MINOR 8
|
||||
|
||||
#define X_RenderQueryVersion 0
|
||||
#define X_RenderQueryPictFormats 1
|
||||
#define X_RenderQueryPictIndexValues 2 /* 0.7 */
|
||||
#define X_RenderQueryDithers 3
|
||||
#define X_RenderCreatePicture 4
|
||||
#define X_RenderChangePicture 5
|
||||
#define X_RenderSetPictureClipRectangles 6
|
||||
#define X_RenderFreePicture 7
|
||||
#define X_RenderComposite 8
|
||||
#define X_RenderScale 9
|
||||
#define X_RenderTrapezoids 10
|
||||
#define X_RenderTriangles 11
|
||||
#define X_RenderTriStrip 12
|
||||
#define X_RenderTriFan 13
|
||||
#define X_RenderColorTrapezoids 14
|
||||
#define X_RenderColorTriangles 15
|
||||
/* #define X_RenderTransform 16 */
|
||||
#define X_RenderCreateGlyphSet 17
|
||||
#define X_RenderReferenceGlyphSet 18
|
||||
#define X_RenderFreeGlyphSet 19
|
||||
#define X_RenderAddGlyphs 20
|
||||
#define X_RenderAddGlyphsFromPicture 21
|
||||
#define X_RenderFreeGlyphs 22
|
||||
#define X_RenderCompositeGlyphs8 23
|
||||
#define X_RenderCompositeGlyphs16 24
|
||||
#define X_RenderCompositeGlyphs32 25
|
||||
#define X_RenderFillRectangles 26
|
||||
/* 0.5 */
|
||||
#define X_RenderCreateCursor 27
|
||||
/* 0.6 */
|
||||
#define X_RenderSetPictureTransform 28
|
||||
#define X_RenderQueryFilters 29
|
||||
#define X_RenderSetPictureFilter 30
|
||||
#define X_RenderCreateAnimCursor 31
|
||||
#define RenderNumberRequests (X_RenderCreateAnimCursor+1)
|
||||
|
||||
#define BadPictFormat 0
|
||||
#define BadPicture 1
|
||||
#define BadPictOp 2
|
||||
#define BadGlyphSet 3
|
||||
#define BadGlyph 4
|
||||
#define RenderNumberErrors (BadGlyph+1)
|
||||
|
||||
#define PictTypeIndexed 0
|
||||
#define PictTypeDirect 1
|
||||
|
||||
#define PictOpMinimum 0
|
||||
#define PictOpClear 0
|
||||
#define PictOpSrc 1
|
||||
#define PictOpDst 2
|
||||
#define PictOpOver 3
|
||||
#define PictOpOverReverse 4
|
||||
#define PictOpIn 5
|
||||
#define PictOpInReverse 6
|
||||
#define PictOpOut 7
|
||||
#define PictOpOutReverse 8
|
||||
#define PictOpAtop 9
|
||||
#define PictOpAtopReverse 10
|
||||
#define PictOpXor 11
|
||||
#define PictOpAdd 12
|
||||
#define PictOpSaturate 13
|
||||
#define PictOpMaximum 13
|
||||
|
||||
/*
|
||||
* Operators only available in version 0.2
|
||||
*/
|
||||
#define PictOpDisjointMinimum 0x10
|
||||
#define PictOpDisjointClear 0x10
|
||||
#define PictOpDisjointSrc 0x11
|
||||
#define PictOpDisjointDst 0x12
|
||||
#define PictOpDisjointOver 0x13
|
||||
#define PictOpDisjointOverReverse 0x14
|
||||
#define PictOpDisjointIn 0x15
|
||||
#define PictOpDisjointInReverse 0x16
|
||||
#define PictOpDisjointOut 0x17
|
||||
#define PictOpDisjointOutReverse 0x18
|
||||
#define PictOpDisjointAtop 0x19
|
||||
#define PictOpDisjointAtopReverse 0x1a
|
||||
#define PictOpDisjointXor 0x1b
|
||||
#define PictOpDisjointMaximum 0x1b
|
||||
|
||||
#define PictOpConjointMinimum 0x20
|
||||
#define PictOpConjointClear 0x20
|
||||
#define PictOpConjointSrc 0x21
|
||||
#define PictOpConjointDst 0x22
|
||||
#define PictOpConjointOver 0x23
|
||||
#define PictOpConjointOverReverse 0x24
|
||||
#define PictOpConjointIn 0x25
|
||||
#define PictOpConjointInReverse 0x26
|
||||
#define PictOpConjointOut 0x27
|
||||
#define PictOpConjointOutReverse 0x28
|
||||
#define PictOpConjointAtop 0x29
|
||||
#define PictOpConjointAtopReverse 0x2a
|
||||
#define PictOpConjointXor 0x2b
|
||||
#define PictOpConjointMaximum 0x2b
|
||||
|
||||
#define PolyEdgeSharp 0
|
||||
#define PolyEdgeSmooth 1
|
||||
|
||||
#define PolyModePrecise 0
|
||||
#define PolyModeImprecise 1
|
||||
|
||||
#define CPRepeat (1 << 0)
|
||||
#define CPAlphaMap (1 << 1)
|
||||
#define CPAlphaXOrigin (1 << 2)
|
||||
#define CPAlphaYOrigin (1 << 3)
|
||||
#define CPClipXOrigin (1 << 4)
|
||||
#define CPClipYOrigin (1 << 5)
|
||||
#define CPClipMask (1 << 6)
|
||||
#define CPGraphicsExposure (1 << 7)
|
||||
#define CPSubwindowMode (1 << 8)
|
||||
#define CPPolyEdge (1 << 9)
|
||||
#define CPPolyMode (1 << 10)
|
||||
#define CPDither (1 << 11)
|
||||
#define CPComponentAlpha (1 << 12)
|
||||
#define CPLastBit 11
|
||||
|
||||
/* Filters included in 0.6 */
|
||||
#define FilterNearest "nearest"
|
||||
#define FilterBilinear "bilinear"
|
||||
|
||||
#define FilterFast "fast"
|
||||
#define FilterGood "good"
|
||||
#define FilterBest "best"
|
||||
|
||||
#define FilterAliasNone -1
|
||||
|
||||
/* Subpixel orders included in 0.6 */
|
||||
#define SubPixelUnknown 0
|
||||
#define SubPixelHorizontalRGB 1
|
||||
#define SubPixelHorizontalBGR 2
|
||||
#define SubPixelVerticalRGB 3
|
||||
#define SubPixelVerticalBGR 4
|
||||
#define SubPixelNone 5
|
||||
|
||||
#endif /* _RENDER_H_ */
|
||||
|
|
@ -8,7 +8,6 @@ x11.createClient(
|
|||
function(display) {
|
||||
var X = display.client;
|
||||
X.QueryExtension('RENDER', function(ext) {
|
||||
|
||||
function RenderQueryVersion(clientMaj, clientMin, callback)
|
||||
{
|
||||
X.seq_num++;
|
||||
|
|
@ -54,10 +53,144 @@ x11.createClient(
|
|||
];
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
var valueList = [
|
||||
['repeat', 'C'],
|
||||
['alphaMap', 'L'],
|
||||
['alphaXOrigin', 's'],
|
||||
['alphaYOrigin', 's'],
|
||||
['clipMask', 'L'],
|
||||
['graphicsExposures', 'C'],
|
||||
['subwindowMode', 'C'],
|
||||
['polyEdge', 'C'],
|
||||
['polyMode', 'C'],
|
||||
['dither', 'L'],
|
||||
['componentAlpha', 'C']
|
||||
];
|
||||
|
||||
RenderQueryVersion(0,9, function(serverVersion) { console.log(serverVersion); });
|
||||
RenderQueryFilters(function(resp) { console.log(resp); });
|
||||
|
||||
var argumentLength = {
|
||||
C: 1,
|
||||
S: 2,
|
||||
s: 2,
|
||||
L: 4,
|
||||
x: 1
|
||||
};
|
||||
|
||||
function RenderCreatePicture(pid, drawable, pictformat, values)
|
||||
{
|
||||
X.seq_num++;
|
||||
var mask = 0;
|
||||
var reqLen = 5; // + (values + pad)/4
|
||||
var format = 'CCSLLLL';
|
||||
var params = [ext.majorOpcode, 4, reqLen, pid, drawable, pictformat, mask];
|
||||
|
||||
if (values)
|
||||
{
|
||||
var valuesLength = 0;
|
||||
for (var i=0; i < valueList.length; ++i)
|
||||
{
|
||||
var val = values[valueList[i][0]];
|
||||
if (val) {
|
||||
mask |= (1 << i);
|
||||
params.push(val);
|
||||
var valueFormat = valueList[i][1];
|
||||
format += valueFormat;
|
||||
valuesLength += argumentLength[valueFormat];
|
||||
}
|
||||
}
|
||||
var pad4 = (valuesLength + 3) >> 2;
|
||||
var toPad = (pad4 << 2) - valuesLength;
|
||||
for (var i=0; i < toPad; ++i)
|
||||
format += 'x';
|
||||
reqLen += pad4;
|
||||
params[2] = reqLen;
|
||||
params[6] = mask;
|
||||
}
|
||||
console.log([format, params]);
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
function floatToFix(f)
|
||||
{
|
||||
return parseInt(f*(1<<16));
|
||||
}
|
||||
|
||||
function RenderLinearGradient(pid, p1, p2, stops)
|
||||
{
|
||||
X.seq_num++;
|
||||
var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLLLLLL';
|
||||
var params = [ext.majorOpcode, 34, reqLen, pid];
|
||||
params.push(floatToFix(p1[0])); // L
|
||||
params.push(floatToFix(p1[1]));
|
||||
params.push(floatToFix(p2[0]));
|
||||
params.push(floatToFix(p2[1])); // L
|
||||
|
||||
params.push(stops.length);
|
||||
|
||||
// [ [float stopDist, [float r, g, b, a] ], ...]
|
||||
// stop distances
|
||||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
format += 'L';
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
params.push(floatToFix(stops[i][0]))
|
||||
}
|
||||
// colors
|
||||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
format += 'SSSS';
|
||||
for (var j=0; j < 4; ++j)
|
||||
params.push(stops[i][1][j]);
|
||||
}
|
||||
console.log([format, params]);
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
function RenderFillRectangles(op, pid, color, rects)
|
||||
{
|
||||
X.seq_num++;
|
||||
var reqLen = 5+rects.length*2;
|
||||
var format = 'CCSCxxxLSSSS';
|
||||
var params = [ext.majorOpcode, 26, reqLen, op, pid];
|
||||
for (var j=0; j < 4; ++j)
|
||||
params.push(color[j]);
|
||||
for (var i=0; i < rects.length; i+=4)
|
||||
{
|
||||
format += 'ssSS';
|
||||
params.push(rects[i*4]);
|
||||
params.push(rects[i*4 + 1]);
|
||||
params.push(rects[i*4 + 2]);
|
||||
params.push(rects[i*4 + 3]);
|
||||
}
|
||||
console.log([format, params]);
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
//RenderQueryVersion(0,9, function(serverVersion) { console.log(serverVersion); });
|
||||
//RenderQueryFilters(function(resp) { console.log(resp); });
|
||||
|
||||
var root = display.screen[0].root;
|
||||
var wid = X.AllocID();
|
||||
var white = display.screen[0].white_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: x11.eventMask.Exposure });
|
||||
var pid = X.AllocID();
|
||||
RenderCreatePicture(pid, wid, 71, { repeat: 1} );
|
||||
var pidGrad = X.AllocID();
|
||||
|
||||
//RenderLinearGradient(pidGrad, [0,0], [100,100], [ [0, [0,0,0,0xffff]], [100, [0xffff, 0xffff, 0xffff, 0xffff]]]);
|
||||
|
||||
X.MapWindow(wid);
|
||||
|
||||
X.on('event', function(ev) {
|
||||
console.log(ev);
|
||||
//RenderFillRectangles(1, pid, [0, 0, 0, 0x8000], [0, 0, 400, 500]);
|
||||
RenderFillRectangles(1, pid, [0, 0x8000, 0, 0xffff], [100, 200, 400, 500]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue