Check for WebGL support in Dart - webgl

I'm playing with WebGL and Dart and I can't figure out how to check if some object has certain method. For example in JavaScript I would check if WebGL is available with window.WebGLRenderingContext but is there a way to the same in Dart?

IIRC one of the goals of Dart was to normalize the inconsistencies of which browser defines what. As such, WebGL will always be "available" in that the interfaces for it will always exist in Dart wether or not the browser you are running on has them defined natively.
Wether or not WebGL is supported is probably best checked the same way you do in Javascript:
WebGLRenderingContext gl = canvas.getContext("experimental-webgl");
If gl is null then WebGL is not supported. Otherwise it is!
(BTW: just because window.WebGLRenderingContext exists in Javascript does NOT mean that WebGL is supported! That only tells you that the browser is capable of dispatching WebGL commands. The system that you are running on may not accept them. It's still best to try creating a context and detect when it fails.)

EDIT: By the way, there is a Dart way of initializing WebGL context:
RenderingContext gl = canvas.getContext3d();
if (gl == null) {
print("WebGL: initialization failure");
}
OLD ANSWER:
WebGLRenderingContext gl = canvas.getContext("experimental-webgl");
if (gl == null) {
print("WebGL is not supported");
return;
}
This code prints "WebGL is not supported" on Chrome JavaScript Console, when I turn on "Disable WebGL" under chrome://flags/.
However, with WebGL disabled under Firefox (about:config -> webgl.disabled;true), it yields error on Web Console:
NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLCanvasElement.getContext]
EDIT: This is the fixed bug for Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=645792

Related

How can you get information about other apps running or in focus?

My motivation: I'm writing an app to help with some quantified self / time tracking type things. I'd like to use electron to record information about which app I am currently using.
Is there a way to get information about other apps in Electron? Can you at least pull information about another app that currently has focus? For instance, if the user is browsing a webpage in Chrome, it would be great to know that A) they're using chrome and B) the title of the webpage they're viewing.
During my research I found this question:
Which app has the focus when a global shortcut is triggered
It looks like the author there is using the nodObjc library to get this information on OSX. In addition to any approaches others are using to solve this problem, I'm particularly curious if electron itself has any way of exposing this information without resorting to outside libraries.
In a limited way, yes, you can get some of this information using the electron's desktopCapturer.getSources() method.
This will not get every program running on the machine. This will only get whatever chromium deems to be a video capturable source. This generally equates to anything that is an active program that has a GUI window (e.g., on the task bar on windows).
desktopCapturer.getSources({
types: ['window', 'screen']
}, (error, sources) => {
if (error) throw error
for (let i = 0; i < sources.length; ++i) {
log(sources[i]);
}
});
No, Electron doesn't provide an API to obtain information about other apps. You'll need to access the native platform APIs directly to obtain that information. For example Tockler seems to do so via shell scripts, though personally I prefer accessing native APIs directly via native Node addons/modules or node-ffi-napi.
2022 answer
Andy Baird's answer is definitely the better native Electron approach though that syntax is outdated or incomplete. Here's a complete working code snippet, assumes running from the renderer using the remote module in a recent Electron version (13+):
require('#electron/remote').desktopCapturer.getSources({
types: ['window', 'screen']
}).then(sources => {
for (const thisSource of sources) {
console.log(thisSource.name);
}
});
The other answers here are for the rendering side - it might be helpful to do this in the main process:
const { desktopCapturer } = require('electron')
desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => {
for (const source of sources) {
console.log("Window: ", source.id, source.name);
}
})

document.getElementById("id").valid not working in higher versions of firefox

I am working on a firefox plugin that uses firebreath framework. The plugin checks whether the firebreath dll is registered using the following code.
if(document.getElementByID("dllID").valid)
{
alert("Dll registered");
}
else
{
alert("Condition failed");
}
The code works fine for firefox upto version 28.
For higher versions the condition always fails. Can anyone help me in this??
I've never heard of the valid attribute. What are you trying to accomplish exactly? If it is for form validation, you probably need to deal with validation objects https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation#The_HTML5_constraint_validation_API
if (document.getElementbyID("dllID").validity.valid){
...
} else {
....
}
Whats more, is this api seems to be present in FF29+ so it probably deprecated the plain valid attribute you are used to
Try .hasAttribute, .getAttribute, and .setAttribute
document.getElementByID("dllID").hasAttribute('valid')
Without these, is usually for XBL properties but things like id work too.

PROCCESING-Pixel operations are not supported on this device

Any code I write that requires save(), saveFrame() or functions like loadpixels() I can't use, what's stopping me from saving edited pitcures.
Error it says its: Pixel operations are not supported on this device.
About my computer:
Windows7 ultimate Service pack 1, 64-bit
AMD A10-5800K APU with Radeon(tm) HD Graphics 3.80 GHZ
UPDATE
It works on any other computer just not mine, even some basic codes like this one for example
size(640,480);
background(255);
fill(44);
beginShape();
vertex(50,20);
vertex(600,160);
vertex(190,400);
endShape(CLOSE);
saveFrame("izlaz1.jpg");
I suppose that your Windows' color depth setting is set too low.
Processing assumes that system exposes color depth as 32-bit (RGB + alpha = 4*8bit).
This is fragment from PGraphicsJava2D class:
protected WritableRaster getRaster() {
...
if (raster.getTransferType() != DataBuffer.TYPE_INT) {
System.err.println("See https://github.com/processing/processing/issues/2010");
throw new RuntimeException("Pixel operations are not supported on this device.");
}
return raster;
}
So "Pixel operations are not supported" exception is raised when your system exposes to low color depth.
Try to change your Windows' setting.
Some helper links below:
https://github.com/processing/processing/issues/2010
http://helpx.adobe.com/x-productkb/global/change-color-depth-resolution-windows.html

why main() return value does not set exitcode in dart?

Dart is suppose to be pragmatic, intuitive, etc.
I wonder Why top-level main() does not set exitcode if int is returned?
I know, you can set it via dart:io.exitCode= or use dart:io.exit().
The question is why language designers decided to drop such popular convention?
#!/path/to/dart --checked
int main() {
int myExitCode = 5;
return myExitCode;
}
It returns 0 (as described in documentation), but in command-line world it's just silly.
It does not even warn you (compiler checked mode, dartanalyzer). Script just silently return 0. Is there any rationale behind it?
UPDATE:
proposal bug: https://code.google.com/p/dart/issues/detail?id=21639
The main() method in Dart always returns void, even if you specify otherwise. See The main() function As mentioned in the answer from John Evans, you must use the exit function if you want to return a value. This is because the Dart VM runs in both CLI and in a browser. It makes no sense in terms of the browser to provide a return value from main(). Thus the functionality is limited to the dart:io library which will only run in the CLI version of the dart VM.
My understanding for this is that while main() may finish executing, you might have other asynchronous work going on that hasn't completed yet. You can use exit from the dart:io lib to return a exit code immediately.
import 'dart:io';
main(){
exit(42);
}
More info from the API docs about exit: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:io#id_exit
Possible answer would be that returning value from main() will not make sense in browser (as Matt B pointed out, +1), so dart does not let it at all.
But this is incoherent, since getting list of commandline arguments main(List<String> args) does not make sense in a browser environment either, and dart languages supports main(List<String> args).
On the other hand, support for main-return-sets-exitCode feature would tight heart of dart
(how top-level main() is treated) to dart:io which is not available in browsers.
However, I personally don't think it wouldn't be that bad as having such wired and unexpected behavior as shown in the question's code.

DirectX Firefox Plugin rendering artifacts

QUICK ANSWER: For those of you who reach this page via Google looking for
a solution to the same problem, try
this quick fix (suggested by Goz) -
Add D3DCREATE_FPU_PRESERVE to the
behavior flags on your CreateDevice()
call. That cleared it up for me!
I'm creating a DirectX 9-based NPAPI plugin. It seems to be working well in Chrome and Opera, but in Firefox I get strange rendering artifacts. Upon initializing DirectX (no rendering needs to be done for the artifact to appear) all or parts of the Firefox UI will turn black. Resizing the window (IE: Initiating a repaint) clears up the artifacts and the plugin seems to work properly at that point, but this is obviously not a desirable "feature". I have found that several others online have mentioned this issue, most claiming that it began with Firefox 3. Only one post mentions any solution being found, but the author doesn't seem to keen on divulging how.
Is anyone familiar with this issue and a possible solution? From the linked post it would seem to be related to the way DX is initialized, but I've yet to find a combination that prevents the issue.
This is the DX Initialization code I'm using (Error Handling removed for clarity):
RECT rc;
GetClientRect(pluginHwnd, &rc);
D3DPRESENT_PARAMETERS d3d9PresentParams;
ZeroMemory(&d3d9PresentParams, sizeof(D3DPRESENT_PARAMETERS));
d3d9PresentParams.hDeviceWindow = pluginHwnd;
d3d9PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3d9PresentParams.Flags = D3DPRESENTFLAG_DEVICECLIP; // Failed attempt to solve FF issue
d3d9PresentParams.EnableAutoDepthStencil = FALSE; // No depth testing
d3d9PresentParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Use Vsync
d3d9PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; // Don't care about Multisampling
d3d9PresentParams.MultiSampleQuality = 0;
d3d9PresentParams.BackBufferCount = 1;
d3d9PresentParams.BackBufferWidth = rc.right - rc.left;
d3d9PresentParams.BackBufferHeight = rc.bottom - rc.top;
d3d9PresentParams.BackBufferFormat = D3DFMT_UNKNOWN; // Use the same color format as windows
d3d9PresentParams.Windowed = TRUE; // Explicitly windowed
d3d9PresentParams.FullScreen_RefreshRateInHz = 0;
d3d9->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pluginHwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3d9PresentParams, &d3d9Device );
The only thing I can think of off the top of my head is setting the "D3DCREATE_NOWINDOWCHANGES" behaviour flag on device creation.
Edit1:
You could try setting backbufferwidth and height to 0 and let it inherit the info from the window.
Might also be worth trying setting the D3DCREATE_FPU_PRESERVE flag and D3DCREATE_MULTITHREADED.

Resources