Skip navigation.

Log in | Sign up

Opera Core Concerns

Official blog for Core developers at Opera

avatar

Graphics demos

My name is Tim Johansson, I am a core technology developer at Opera. I work in the core graphics team which is responsible for all the rendering (of web pages, SVG and <canvas>) and image decoding in Opera.

In the middle of December Opera had an engineering seminar outside Oslo in Norway. At the seminar there were a few presentations. I gave a presentation about graphics in Opera and showed a few demos. In this post I will write about two of the demos, and link to videos of them.

Opera Flashlight

One of the first assignments I had at Opera was to work on a technology for platform independent graphics, which is now used in some of Operas products including the Opera SDK.
When working on it I quickly realized that this technology would make it easy to upload Opera to a texture in a 3d application.
Since I had been working on a 3d engine for fun in my spare time I spent a late evening integrating Opera into my 3d engine. The place I thought sounded most fun to add it was as the projective texture used for the flashlight in the 3d engine.

This video demonstrates the result of that late night hack more than 3 years ago.

Hardware acceleration

One of the things I have been working on lately is hardware acceleration of the vector graphics library used for SVG and <canvas> in Opera using 3d hardware (through OpenGL and Direct3D).

In order to get the most performance from rendering SVG/<canvas> in hardware it is good to avoid reading the rendered image back from the graphics card to system memory since that is a slow operation.
This can be solved by rendering all of Opera (including UI and web pages) in hardware. Rendering Opera in hardware also makes it possible to add visual effects without any additional CPU cost.

This video shows a demo of Opera running fully hardware accelerated. The demo build used in this video is an interal Opera core technology reference build with hardware acceleration enabled. Hardware acceleration is still experimental and is not in any released or soon to be released products.

avatar

Selectors API

, ,

The Selectors API specification, currently being worked on within the WebAPI working group at the W3C, defines DOM APIs designed to make it possible to select elements within the document using Selectors. This simple, yet powerful API has the potential to make working with the DOM faster and easier. If you’re familiar with CSS, you will be familiar with Selectors and these APIs should be easy to learn.

For example, to select all the em and strong elements within the document, you can use this.

document.querySelectorAll("em, strong");

To see how much easier this is compared with traditional APIs, consider this example HTML fragment:

<ul id="fruits">
  <li><input type="checkbox" name="fruit" value="apples"> Apples</li>
  <li><input type="checkbox" name="fruit" value="oranges"> Oranges</li>
  <li><input type="checkbox" name="fruit" value="bananas"> Bananas</li>
  <li><input type="checkbox" name="fruit" value="grapes"> Grapes</li>
</ul>

After the user has filled out the form containing those check boxes, suppose you want to get the list of all the checked items. Using traditional APIs, this would require obtaining a list of all the input elements and iteratively checking which ones were checked.

var fruits = document.getElementById("fruits");
var checkboxes = fruits.getElementsByTagName("input");
var list = [];
for (var i = 0; i < checkboxes.length; i++) {
  if (checkboxes[i].checked) {
    list.push(checkboxes[i]);
  }
}

Using these new APIs, the operation can be reduced to a single line of code!

var list = document.querySelectorAll("#fruits input:checked");

This returns a node list containing all the input elements that were checked by the user. Your script can then perform any operation you like with them.

We have been working on an implementation of these APIs recently and support has been included within the recently released Acid 3 build.

There are two new methods introduced: querySelector() and querySelectorAll(). The former returns the first matching element within the tree, and the latter returns a collection of all matching elements as a NodeList. The current editor’s draft specification defines that the methods are available on the Document, Element and DocumentFragment nodes. However, our implementation currently only supports it on the Document and Elements nodes.

The querySelector() method is useful for situations where only the first matching element is needed, and is designed to be more efficient than the alternative querySelectorAll() method in such cases.

For example, the following form control and javascript function could be used to validate an email address. For simplicity, this uses the validity APIs from Web Forms 2.0. If support for legacy user agents is required, a more appropriate validity check could be written. The querySelector() method is used to obtain the correct element for outputting the appropriate error message, or clearing it when it is valid.

The JavaScript:

function validateEmail(evt) {
  var ctrl = event.target;
  var parent = ctrl.parentNode;
  var errMsg = parent.querySelector(".error");

  // Validate form control value
  if (!ctrl.validity.valid) {
    errMsg.innerHTML = "Invalid email address."
  } else {
    errMsg.innerHTML = "";
  }
}

The HTML fragment:

<p><input type="email" name="email" onchange="validateEmail();">
   <strong class="error"></strong></p>

Our implementation also partially supports the namespace resolver features, allowing you to work with mixed namespace documents and select elements based on their namespace. Consult the specification for more information on the NSResolver object.

You can try out these examples for yourself in the recently released Acid 3 Gogi Build which is available for Windows and Linux.

avatar

Welcome to Core Concerns!

Welcome to the Core Concerns blog. My name is Lars Erik Bolstad and I'm in charge of the Core Technology department at Opera Software. We have set up this blog as a place for our Core developers and others involved in technology development at Opera to tell you about interesting stuff related to our technology and products.

What we call "Core" at Opera refers to the platform-independent internal components of our browser. Opera delivers web browsers on more than a dozen different operating systems and platforms, on devices ranging from state of the art desktop computers via game consoles and TVs down to handheld devices with fairly limited processing power. The same Core code base is used across the entire product range. This enables us to deliver the same feature set and level of standards support regardless of the target device, but at the same time puts some constraints on the code we produce and the way we implement features.

If you are interested in web browser technology and would like to stay informed about what's going on at Opera, make sure to visit this blog regularly or subscribe to our feed.