tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gluPixelTransfer.js (2073B)


      1 /*-------------------------------------------------------------------------
      2 * drawElements Quality Program OpenGL ES Utilities
      3 * ------------------------------------------------
      4 *
      5 * Copyright 2014 The Android Open Source Project
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *      http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 *
     19 */
     20 
     21 'use strict';
     22 goog.provide('framework.opengl.gluPixelTransfer');
     23 goog.require('framework.common.tcuTexture');
     24 goog.require('framework.delibs.debase.deMath');
     25 goog.require('framework.opengl.gluTextureUtil');
     26 
     27 goog.scope(function() {
     28 
     29 var gluPixelTransfer = framework.opengl.gluPixelTransfer;
     30 var tcuTexture = framework.common.tcuTexture;
     31 var deMath = framework.delibs.debase.deMath;
     32 var gluTextureUtil = framework.opengl.gluTextureUtil;
     33 
     34 gluPixelTransfer.getTransferAlignment = function(format) {
     35    var pixelSize = format.getPixelSize();
     36    if (deMath.deIsPowerOfTwo32(pixelSize))
     37        return Math.min(pixelSize, 8);
     38    else
     39        return 1;
     40 };
     41 
     42 gluPixelTransfer.readPixels = function(ctx, x, y, format, dst) {
     43    var width = dst.getWidth();
     44    var height = dst.getHeight();
     45    var arrayType = tcuTexture.getTypedArray(format.type);
     46    var transferFormat = gluTextureUtil.getTransferFormat(format);
     47    ctx.pixelStorei(ctx.PACK_ALIGNMENT, gluPixelTransfer.getTransferAlignment(format));
     48    var resultPixel = dst.getAccess().getDataPtr();
     49    resultPixel = new arrayType(dst.getAccess().getBuffer());
     50    ctx.readPixels(x, y, width, height, transferFormat.format, transferFormat.dataType, resultPixel);
     51 };
     52 
     53 /* TODO: implement other functions in C++ file */
     54 
     55 });