What causes the unique transformation of text by Chrome when displayed over a canvas element?

It appears that when text is placed on top of a canvas element, Chrome enforces hardware-accelerated transforms.

Could someone provide insight into this behavior? My goal is to resize text over a canvas element without it being transformed into a texture.

You can view the issue in action on this fiddle: http://jsfiddle.net/Gb6h4/1/

Below is the code snippet:

// Access the canvas and its context
var $canvas = $("canvas");
var ctx = $canvas[0].getContext('2d');

// Make the canvas fit the entire screen
var width = $(window).width(),
    height = $(window).height();
$canvas.attr({
    width: width,
    height: height
});

// When modifying the canvas context in Chrome,
// it triggers a hardware-accelerated transform on the text.
// (The text is scaled as a texture, causing blurriness.)

// Uncomment the line below to see the difference.
// ctx.fillStyle = "grey";

// Implement a basic zoom animation on our "Hello!" div
var $div = $(".transformed");
var scale = 1;
setInterval(function () {
    scale += 0.005;
    $div.css({
        transform: "translate(0px, 0px) scale("+scale+")"
    });
}, 16);

In the fiddle, the text initially scales correctly (using a non-accelerated CSS transform). However, after interaction with the canvas context, the text scaling changes (as if under an accelerated transform).

Answer №1

This issue stems from the way CSS transforms interact with composited layers in Chrome at present.

When a 2D context is accelerated, a RenderLayer creates its own compositing layer. Additionally, a layer that has a composited sibling with a lower z-index will also generate its own compositing layer.

For more information, visit

Check out the related bug report here: https://code.google.com/p/chromium/issues/detail?id=122083

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

PHP: Incorrect URL formats with or without a variable present

I am currently working on customizing a PHP web application and could use some assistance. The Application is originally set up to operate in the ROOT path of the Webserver. I have made some modifications to make it work in different paths, but I am facing ...

``Why Ionic 3 Popover Sizes Should Adapt to Different Screen

Currently in my Ionic 3 project, I am utilizing a popover with a set height using the following code snippet: editOpty(rw){ let popover = this.editOptyPopup.create(EditOptyPopoverComponent, rw, { cssClass: 'edit-opty-popover'}); popover ...

execute a method encapsulated within a factory from external to AngularJS

Although this question is similar to others posted here, none of the solutions provided have worked for me. My Cordova/AngularJS/Ionic app currently polls a remote server every 10 minutes to retrieve JSON data, and push notifications are working correctly ...

Positioning a colored anchor beneath a menu that remains fixed in place

I am trying to adjust the position of a link anchor on a page with a fixed positioning menu. I found a solution in the discussion titled Fixed position navbar obscures anchors that works for me, but the issue I am facing is that the background color of t ...

How to alter the color of the chosen option in a select option control using ReactJS

Struggling to customize the text and background color of a control using ReactJS. Take a look at my code snippet: import React, { Component } from "react"; import "./Test.css"; class Test extends Component { render = () => { ...

What is the best way to transfer variables from an ng-template defined in the parent component to a child component or directive?

Is there a way to pass an ng-template and generate all its content to include variables used in interpolation? As I am still new to Angular, besides removing the HTML element, do I need to worry about removing anything else? At the end of this ...

Authentication of server through PHP session

I have a question regarding switching the authentication method on my C# server from Login\Password to PHP session. My client side uses PHP, HTML5, and JavaScript, while the server side is based on C# with WebSockets lib. At present, my authorization ...

Using jQuery to Verify Matching Objects Based on a Shared Property in Sets

I am in search of a solution using JavaScript or jQuery to ensure that two sets/arrays of objects share the same value for a particular property. In this case, two items share the same guid value across both sets, but some properties differ between them - ...

Error: Attempting to use hooks outside the scope of a function component in react-native. Hooks can only be called within the body of a

Oops! An error occurred: Invalid hook call. Hooks can only be called inside the body of a function component. There are several reasons why this might have happened: You could have incompatible versions of React and the renderer (e.g., React DOM) Your cod ...

Issue TS2349 occurs when attempting to use a combination of boolean and function types within union typing

In my class, there is a property called "isVisible" which can be either a boolean value or a function that returns a boolean. The code snippet below demonstrates what I am currently using. It works fine and achieves the desired result, but during compilat ...

Vue's TreeView component has been encountering issues with accurately displaying the contents of sub

Currently working on creating a customized TreeView in Vue. Check out my progress in the code here. The issue I'm facing is that the subfolders' content (such as child folder 1) is not displaying correctly. Additionally, collapsing the subfolder ...

Adjust the size of an HTML element when the window is resized

I stumbled upon a question that sparked my interest recently, and I've been attempting to apply some of the suggestions provided. Unfortunately, I have been facing difficulties in implementing them successfully. The issue lies with an ASPx page where ...

Comparing plain objects and class instances for modeling data objects

What is the recommended approach for creating model objects in Angular using TypeScript? Is it advisable to use type annotation with object notation (where objects are plain instances of Object)? For example, let m: MyModel = { name: 'foo' } ...

Tips for determining the actions of a node prior to its inception

Is there a way to automatically run scripts on specific elements after their creation? For example, using a jQuery plugin like autoresize to expand the height of a textarea. If I use $('.textarea').autosize(), only the current textareas will be a ...

Revamping the Jquery Waypoint

Greetings, I am currently delving into the world of Jquery waypoints and facing a bit of challenge getting it to work. My goal is to have an "alert" pop up once an element becomes visible on the screen, but for some reason, the alert doesn't show up w ...

If I include the '=' symbol with the request value, the request params will be null

I am currently working on a node.js project that utilizes the express framework. The main purpose of my application is to handle multiple POST requests. One of these POST requests is as follows: URL POST /processit request params info={"one":"a=5"} n ...

What is the best way to show an empty div in this situation?

I am trying to showcase my array in my application. Here is what I have: JavaScript $scope.array1 = [' ',' ',1,2,3,4,5]; $scope.array2 = [6,7,8,9,10,' ',' ']; $scope.array3 = [12,13,14,15,16,17]; HTML <div n ...

Exploring and listing the key-value pairs from several arrays within an object

My inquiry pertains to the following function: function loadConfigurations(configs){ console.log(configs); } The 'configs' object received by the loadConfigurations function contains two properties --two arrays named "assigned" and "unassign ...

Animating content with Jquery Waypoints for a seamless and elegant user experience

Currently tackling a project that requires some jQuery functions beyond my current skill set. Hoping to find some solutions here! The project in question is a one page scroll site, with existing jquery and waypoints functions implemented. Check out the c ...

How can data be partitioned into individual td elements in Rails after a specific number of records?

Revamped solution: I made some changes to the original answer that guided me in the right direction. Here is my updated code snippet: <table class="fixed"> <tr> ...