Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: Source/devtools/front_end/timeline/Layers3DView.js

Issue 333073005: DevTools: Draw multiple textures for layers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 this._canvasElement = this.element.createChild("canvas"); 40 this._canvasElement = this.element.createChild("canvas");
41 this._transformController = new WebInspector.TransformController(this._canva sElement); 41 this._transformController = new WebInspector.TransformController(this._canva sElement);
42 this._transformController.addEventListener(WebInspector.TransformController. Events.TransformChanged, this._update, this); 42 this._transformController.addEventListener(WebInspector.TransformController. Events.TransformChanged, this._update, this);
43 this._canvasElement.addEventListener("dblclick", this._onDoubleClick.bind(th is), false); 43 this._canvasElement.addEventListener("dblclick", this._onDoubleClick.bind(th is), false);
44 this._canvasElement.addEventListener("mousedown", this._onMouseDown.bind(thi s), false); 44 this._canvasElement.addEventListener("mousedown", this._onMouseDown.bind(thi s), false);
45 this._canvasElement.addEventListener("mouseup", this._onMouseUp.bind(this), false); 45 this._canvasElement.addEventListener("mouseup", this._onMouseUp.bind(this), false);
46 this._canvasElement.addEventListener("mouseout", this._onMouseMove.bind(this ), false); 46 this._canvasElement.addEventListener("mouseout", this._onMouseMove.bind(this ), false);
47 this._canvasElement.addEventListener("mousemove", this._onMouseMove.bind(thi s), false); 47 this._canvasElement.addEventListener("mousemove", this._onMouseMove.bind(thi s), false);
48 this._canvasElement.addEventListener("contextmenu", this._onContextMenu.bind (this), false); 48 this._canvasElement.addEventListener("contextmenu", this._onContextMenu.bind (this), false);
49 this._lastActiveObject = {}; 49 this._lastActiveObject = {};
50 this._textureForLayer = {}; 50 this._tilesForLayer = {};
caseq 2014/06/18 12:16:39 Technically, these are pictures, not tiles.
malch 2014/06/18 12:48:18 Done.
51 this._scrollRectQuadsForLayer = {}; 51 this._scrollRectQuadsForLayer = {};
52 this._isVisible = {}; 52 this._isVisible = {};
53 this._layerTree = null; 53 this._layerTree = null;
54 WebInspector.settings.showPaintRects.addChangeListener(this._update, this); 54 WebInspector.settings.showPaintRects.addChangeListener(this._update, this);
55 } 55 }
56 56
57 /** @typedef {{layer: !WebInspector.Layer, scrollRectIndex: number}|{layer: !Web Inspector.Layer}} */ 57 /** @typedef {{layer: !WebInspector.Layer, scrollRectIndex: number}|{layer: !Web Inspector.Layer}} */
58 WebInspector.Layers3DView.ActiveObject; 58 WebInspector.Layers3DView.ActiveObject;
59 59
60 /** 60 /**
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void main(void)\ 103 void main(void)\
104 {\ 104 {\
105 gl_Position = uPMatrix * vec4(aVertexPosition, 1.0);\ 105 gl_Position = uPMatrix * vec4(aVertexPosition, 1.0);\
106 vColor = aVertexColor;\ 106 vColor = aVertexColor;\
107 vTextureCoord = aTextureCoord;\ 107 vTextureCoord = aTextureCoord;\
108 }"; 108 }";
109 109
110 WebInspector.Layers3DView.SelectedBackgroundColor = [20, 40, 110, 0.66]; 110 WebInspector.Layers3DView.SelectedBackgroundColor = [20, 40, 110, 0.66];
111 WebInspector.Layers3DView.BackgroundColor = [0, 0, 0, 0]; 111 WebInspector.Layers3DView.BackgroundColor = [0, 0, 0, 0];
112 WebInspector.Layers3DView.HoveredBorderColor = [0, 0, 255, 1]; 112 WebInspector.Layers3DView.HoveredBorderColor = [0, 0, 255, 1];
113 WebInspector.Layers3DView.SelectedBorderColor = [0, 255, 0, 1];
113 WebInspector.Layers3DView.BorderColor = [0, 0, 0, 1]; 114 WebInspector.Layers3DView.BorderColor = [0, 0, 0, 1];
114 WebInspector.Layers3DView.ScrollRectBackgroundColor = [178, 0, 0, 0.4]; 115 WebInspector.Layers3DView.ScrollRectBackgroundColor = [178, 0, 0, 0.4];
115 WebInspector.Layers3DView.SelectedScrollRectBackgroundColor = [178, 0, 0, 0.6]; 116 WebInspector.Layers3DView.SelectedScrollRectBackgroundColor = [178, 0, 0, 0.6];
116 WebInspector.Layers3DView.ScrollRectBorderColor = [178, 0, 0, 1]; 117 WebInspector.Layers3DView.ScrollRectBorderColor = [178, 0, 0, 1];
118 WebInspector.Layers3DView.BorderWidth = 1;
119 WebInspector.Layers3DView.SelectedBorderWidth = 2;
117 120
118 WebInspector.Layers3DView.LayerSpacing = 20; 121 WebInspector.Layers3DView.LayerSpacing = 20;
119 WebInspector.Layers3DView.ScrollRectSpacing = 4; 122 WebInspector.Layers3DView.ScrollRectSpacing = 4;
120 123
121 WebInspector.Layers3DView.prototype = { 124 WebInspector.Layers3DView.prototype = {
122 /** 125 /**
123 * @param {function(!Array.<!WebInspector.KeyboardShortcut.Descriptor>, func tion(?Event=))} registerShortcutDelegate 126 * @param {function(!Array.<!WebInspector.KeyboardShortcut.Descriptor>, func tion(?Event=))} registerShortcutDelegate
124 */ 127 */
125 registerShortcuts: function(registerShortcutDelegate) 128 registerShortcuts: function(registerShortcutDelegate)
126 { 129 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 this._setOutline(WebInspector.Layers3DView.OutlineType.Hovered, null); 171 this._setOutline(WebInspector.Layers3DView.OutlineType.Hovered, null);
169 this._setOutline(WebInspector.Layers3DView.OutlineType.Selected, activeO bject); 172 this._setOutline(WebInspector.Layers3DView.OutlineType.Selected, activeO bject);
170 }, 173 },
171 174
172 /** 175 /**
173 * @param {!WebInspector.Layer} layer 176 * @param {!WebInspector.Layer} layer
174 * @param {string=} imageURL 177 * @param {string=} imageURL
175 */ 178 */
176 showImageForLayer: function(layer, imageURL) 179 showImageForLayer: function(layer, imageURL)
177 { 180 {
178 var texture = this._gl.createTexture(); 181 this.setTiles([{layerId: layer.id(), rect: [0, 0, layer.width(), layer.h eight()], imageURL: imageURL}])
179 texture.image = new Image();
180 texture.image.addEventListener("load", this._handleLoadedTexture.bind(th is, texture, layer.id()), false);
181 texture.image.src = imageURL;
182 }, 182 },
183 183
184 /** 184 /**
185 * @param {!Array.<!Object>} tiles
186 */
187 setTiles: function(tiles)
188 {
189 this._tilesForLayer = {};
190 tiles.forEach(this._setTile, this);
191 },
192
193 /**
194 * @param {!Object} tile
195 */
196 _setTile: function(tile)
197 {
198 var texture = this._gl.createTexture();
199 texture.image = new Image();
200 texture.image.addEventListener("load", this._handleLoadedTexture.bind(th is, texture, tile.layerId, tile.rect), false);
201 texture.image.src = tile.imageURL;
202 },
203
204 /**
185 * @param {!Element} canvas 205 * @param {!Element} canvas
186 * @return {!Object} 206 * @return {!Object}
187 */ 207 */
188 _initGL: function(canvas) 208 _initGL: function(canvas)
189 { 209 {
190 var gl = canvas.getContext("webgl"); 210 var gl = canvas.getContext("webgl");
191 gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); 211 gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
192 gl.enable(gl.BLEND); 212 gl.enable(gl.BLEND);
193 gl.clearColor(0.0, 0.0, 0.0, 0.0); 213 gl.clearColor(0.0, 0.0, 0.0, 0.0);
194 gl.enable(gl.DEPTH_TEST); 214 gl.enable(gl.DEPTH_TEST);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 _initProjectionMatrix: function() 290 _initProjectionMatrix: function()
271 { 291 {
272 this._pMatrix = new WebKitCSSMatrix().scale(1, -1, -1).translate(-1, -1, 0) 292 this._pMatrix = new WebKitCSSMatrix().scale(1, -1, -1).translate(-1, -1, 0)
273 .scale(2 / this._canvasElement.width, 2 / this._canvasElement.height , 1 / 1000000).multiply(this._calculateProjectionMatrix()); 293 .scale(2 / this._canvasElement.width, 2 / this._canvasElement.height , 1 / 1000000).multiply(this._calculateProjectionMatrix());
274 this._gl.uniformMatrix4fv(this._shaderProgram.pMatrixUniform, false, thi s._arrayFromMatrix(this._pMatrix)); 294 this._gl.uniformMatrix4fv(this._shaderProgram.pMatrixUniform, false, thi s._arrayFromMatrix(this._pMatrix));
275 }, 295 },
276 296
277 /** 297 /**
278 * @param {!Object} texture 298 * @param {!Object} texture
279 * @param {string} layerId 299 * @param {string} layerId
300 * @param {!Array.<number>} rect
280 */ 301 */
281 _handleLoadedTexture: function(texture, layerId) 302 _handleLoadedTexture: function(texture, layerId, rect)
282 { 303 {
283 this._gl.bindTexture(this._gl.TEXTURE_2D, texture); 304 this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
284 this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, true); 305 this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, true);
285 this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA , this._gl.UNSIGNED_BYTE, texture.image); 306 this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA , this._gl.UNSIGNED_BYTE, texture.image);
286 this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.LINEAR); 307 this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.LINEAR);
287 this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.LINEAR); 308 this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.LINEAR);
288 this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, thi s._gl.CLAMP_TO_EDGE); 309 this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, thi s._gl.CLAMP_TO_EDGE);
289 this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, thi s._gl.CLAMP_TO_EDGE); 310 this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, thi s._gl.CLAMP_TO_EDGE);
290 this._gl.bindTexture(this._gl.TEXTURE_2D, null); 311 this._gl.bindTexture(this._gl.TEXTURE_2D, null);
291 this._textureForLayer = {}; 312 if (!this._tilesForLayer[layerId])
292 this._textureForLayer[layerId] = texture; 313 this._tilesForLayer[layerId] = [];
314 this._tilesForLayer[layerId].push({texture: texture, rect: rect});
293 this._update(); 315 this._update();
294 }, 316 },
295 317
296 _initWhiteTexture: function() 318 _initWhiteTexture: function()
297 { 319 {
298 this._whiteTexture = this._gl.createTexture(); 320 this._whiteTexture = this._gl.createTexture();
299 this._gl.bindTexture(this._gl.TEXTURE_2D, this._whiteTexture); 321 this._gl.bindTexture(this._gl.TEXTURE_2D, this._whiteTexture);
300 var whitePixel = new Uint8Array([255, 255, 255, 255]); 322 var whitePixel = new Uint8Array([255, 255, 255, 255]);
301 this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, 1, 1, 0, this ._gl.RGBA, this._gl.UNSIGNED_BYTE, whitePixel); 323 this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, 1, 1, 0, this ._gl.RGBA, this._gl.UNSIGNED_BYTE, whitePixel);
302 }, 324 },
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 * @param {number=} scrollRectIndex 402 * @param {number=} scrollRectIndex
381 */ 403 */
382 _isObjectActive: function(type, layer, scrollRectIndex) 404 _isObjectActive: function(type, layer, scrollRectIndex)
383 { 405 {
384 var activeObject = this._lastActiveObject[type]; 406 var activeObject = this._lastActiveObject[type];
385 return activeObject && activeObject.layer && activeObject.layer.id() === layer.id() && (typeof scrollRectIndex !== "number" || activeObject.scrollRectIn dex === scrollRectIndex); 407 return activeObject && activeObject.layer && activeObject.layer.id() === layer.id() && (typeof scrollRectIndex !== "number" || activeObject.scrollRectIn dex === scrollRectIndex);
386 }, 408 },
387 409
388 /** 410 /**
389 * @param {!WebInspector.Layer} layer 411 * @param {!WebInspector.Layer} layer
390 * @return {!{color: !Array.<number>, borderColor: !Array.<number>}} 412 * @return {!{color: !Array.<number>, borderColor: !Array.<number>}}
caseq 2014/06/18 12:16:39 Now that it grows bigger, let's extract into a cla
malch 2014/06/18 12:48:18 Done.
391 */ 413 */
392 _colorsForLayer: function(layer) 414 _styleForLayer: function(layer)
393 { 415 {
394 var isSelected = this._isObjectActive(WebInspector.Layers3DView.OutlineT ype.Selected, layer); 416 var isSelected = this._isObjectActive(WebInspector.Layers3DView.OutlineT ype.Selected, layer);
395 var isHovered = this._isObjectActive(WebInspector.Layers3DView.OutlineTy pe.Hovered, layer); 417 var isHovered = this._isObjectActive(WebInspector.Layers3DView.OutlineTy pe.Hovered, layer);
396 var color = isSelected ? WebInspector.Layers3DView.SelectedBackgroundCol or : WebInspector.Layers3DView.BackgroundColor; 418 var color = isSelected ? WebInspector.Layers3DView.SelectedBackgroundCol or : WebInspector.Layers3DView.BackgroundColor;
397 var borderColor = isHovered ? WebInspector.Layers3DView.HoveredBorderCol or : WebInspector.Layers3DView.BorderColor; 419 var borderColor;
398 return {color: color, borderColor: borderColor}; 420 if (isSelected)
421 borderColor = WebInspector.Layers3DView.SelectedBorderColor;
422 else if (isHovered)
423 borderColor = WebInspector.Layers3DView.HoveredBorderColor;
424 else
425 borderColor = WebInspector.Layers3DView.BorderColor;
426 var width = isSelected ? WebInspector.Layers3DView.SelectedBorderWidth : WebInspector.Layers3DView.BorderWidth;
427 return {color: color, borderColor: borderColor, width: width};
caseq 2014/06/18 12:16:39 s/width/borderWidth/?
malch 2014/06/18 12:48:18 Done.
399 }, 428 },
400 429
401 /** 430 /**
402 * @param {!Array.<number>} quad 431 * @param {!Array.<number>} quad
403 * @param {number} z 432 * @param {number} z
404 * @return {!Array.<number>} 433 * @return {!Array.<number>}
405 */ 434 */
406 _calculateVerticesForQuad: function(quad, z) 435 _calculateVerticesForQuad: function(quad, z)
407 { 436 {
408 return [quad[0], quad[1], z, quad[2], quad[3], z, quad[4], quad[5], z, q uad[6], quad[7], z]; 437 return [quad[0], quad[1], z, quad[2], quad[3], z, quad[4], quad[5], z, q uad[6], quad[7], z];
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return this._depthByLayerId[layer.id()] * WebInspector.Layers3DView.Laye rSpacing + index * WebInspector.Layers3DView.ScrollRectSpacing + 1; 504 return this._depthByLayerId[layer.id()] * WebInspector.Layers3DView.Laye rSpacing + index * WebInspector.Layers3DView.ScrollRectSpacing + 1;
476 }, 505 },
477 506
478 /** 507 /**
479 * @param {!WebInspector.Layer} layer 508 * @param {!WebInspector.Layer} layer
480 */ 509 */
481 _drawLayer: function(layer) 510 _drawLayer: function(layer)
482 { 511 {
483 var gl = this._gl; 512 var gl = this._gl;
484 var vertices; 513 var vertices;
514 var style = this._styleForLayer(layer);
485 if (this._isVisible[layer.id()]) { 515 if (this._isVisible[layer.id()]) {
486 vertices = this._calculateVerticesForQuad(layer.quad(), this._depthB yLayerId[layer.id()] * WebInspector.Layers3DView.LayerSpacing); 516 vertices = this._calculateVerticesForQuad(layer.quad(), this._depthB yLayerId[layer.id()] * WebInspector.Layers3DView.LayerSpacing);
487 var colors = this._colorsForLayer(layer); 517 gl.lineWidth(style.width);
488 this._drawRectangle(vertices, colors.color, gl.TRIANGLE_FAN, this._t extureForLayer[layer.id()]); 518 this._drawRectangle(vertices, style.borderColor, gl.LINE_LOOP);
489 this._drawRectangle(vertices, colors.borderColor, gl.LINE_LOOP); 519 gl.lineWidth(1);
490 } 520 }
491 this._scrollRectQuadsForLayer[layer.id()] = this._calculateScrollRectQua dsForLayer(layer); 521 this._scrollRectQuadsForLayer[layer.id()] = this._calculateScrollRectQua dsForLayer(layer);
492 var scrollRectQuads = this._scrollRectQuadsForLayer[layer.id()]; 522 var scrollRectQuads = this._scrollRectQuadsForLayer[layer.id()];
493 for (var i = 0; i < scrollRectQuads.length; ++i) { 523 for (var i = 0; i < scrollRectQuads.length; ++i) {
494 vertices = this._calculateVerticesForQuad(scrollRectQuads[i], this._ calculateScrollRectDepth(layer, i)); 524 vertices = this._calculateVerticesForQuad(scrollRectQuads[i], this._ calculateScrollRectDepth(layer, i));
495 var isSelected = this._isObjectActive(WebInspector.Layers3DView.Outl ineType.Selected, layer, i); 525 var isSelected = this._isObjectActive(WebInspector.Layers3DView.Outl ineType.Selected, layer, i);
496 var color = isSelected ? WebInspector.Layers3DView.SelectedScrollRec tBackgroundColor : WebInspector.Layers3DView.ScrollRectBackgroundColor; 526 var color = isSelected ? WebInspector.Layers3DView.SelectedScrollRec tBackgroundColor : WebInspector.Layers3DView.ScrollRectBackgroundColor;
497 this._drawRectangle(vertices, color, gl.TRIANGLE_FAN); 527 this._drawRectangle(vertices, color, gl.TRIANGLE_FAN);
498 this._drawRectangle(vertices, WebInspector.Layers3DView.ScrollRectBo rderColor, gl.LINE_LOOP); 528 this._drawRectangle(vertices, WebInspector.Layers3DView.ScrollRectBo rderColor, gl.LINE_LOOP);
499 } 529 }
530 var tiles = this._tilesForLayer[layer.id()] || [];
531 for (var i = 0; i < tiles.length; ++i) {
532 var tile = tiles[i];
533 var quad = this._calculateRectQuad(layer, {x: tile.rect[0], y: tile. rect[1], width: tile.rect[2] - tile.rect[0], height: tile.rect[3] - tile.rect[1] });
534 vertices = this._calculateVerticesForQuad(quad, this._depthByLayerId [layer.id()] * WebInspector.Layers3DView.LayerSpacing);
caseq 2014/06/18 12:16:39 let's extract depth into a var and reuse it in oth
malch 2014/06/18 12:48:19 Done.
535 this._drawRectangle(vertices, style.color, gl.TRIANGLE_FAN, tile.tex ture);
536 }
500 }, 537 },
501 538
502 _drawViewport: function() 539 _drawViewport: function()
503 { 540 {
504 var viewport = this._layerTree.viewportSize(); 541 var viewport = this._layerTree.viewportSize();
505 var vertices = [0, 0, 0, viewport.width, 0, 0, viewport.width, viewport. height, 0, 0, viewport.height, 0]; 542 var vertices = [0, 0, 0, viewport.width, 0, 0, viewport.width, viewport. height, 0, 0, viewport.height, 0];
506 var color = [0, 0, 0, 1]; 543 var color = [0, 0, 0, 1];
507 this._gl.lineWidth(3.0); 544 this._gl.lineWidth(3.0);
508 this._drawRectangle(vertices, color, this._gl.LINE_LOOP); 545 this._drawRectangle(vertices, color, this._gl.LINE_LOOP);
509 this._gl.lineWidth(1.0); 546 this._gl.lineWidth(1.0);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 _onDoubleClick: function(event) 734 _onDoubleClick: function(event)
698 { 735 {
699 var object = this._activeObjectFromEventPoint(event); 736 var object = this._activeObjectFromEventPoint(event);
700 if (object && object.layer) 737 if (object && object.layer)
701 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, object.layer); 738 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, object.layer);
702 event.stopPropagation(); 739 event.stopPropagation();
703 }, 740 },
704 741
705 __proto__: WebInspector.VBox.prototype 742 __proto__: WebInspector.VBox.prototype
706 } 743 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698