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

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: Fixes. 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._picturesForLayer = {};
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 /** @typedef {{color: !Array.<number>, borderColor: !Array.<number>, borderWidth : number}} */
61 WebInspector.Layers3DView.LayerStyle;
62
60 /** 63 /**
61 * @enum {string} 64 * @enum {string}
62 */ 65 */
63 WebInspector.Layers3DView.OutlineType = { 66 WebInspector.Layers3DView.OutlineType = {
64 Hovered: "hovered", 67 Hovered: "hovered",
65 Selected: "selected" 68 Selected: "selected"
66 } 69 }
67 70
68 /** 71 /**
69 * @enum {string} 72 * @enum {string}
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void main(void)\ 106 void main(void)\
104 {\ 107 {\
105 gl_Position = uPMatrix * vec4(aVertexPosition, 1.0);\ 108 gl_Position = uPMatrix * vec4(aVertexPosition, 1.0);\
106 vColor = aVertexColor;\ 109 vColor = aVertexColor;\
107 vTextureCoord = aTextureCoord;\ 110 vTextureCoord = aTextureCoord;\
108 }"; 111 }";
109 112
110 WebInspector.Layers3DView.SelectedBackgroundColor = [20, 40, 110, 0.66]; 113 WebInspector.Layers3DView.SelectedBackgroundColor = [20, 40, 110, 0.66];
111 WebInspector.Layers3DView.BackgroundColor = [0, 0, 0, 0]; 114 WebInspector.Layers3DView.BackgroundColor = [0, 0, 0, 0];
112 WebInspector.Layers3DView.HoveredBorderColor = [0, 0, 255, 1]; 115 WebInspector.Layers3DView.HoveredBorderColor = [0, 0, 255, 1];
116 WebInspector.Layers3DView.SelectedBorderColor = [0, 255, 0, 1];
113 WebInspector.Layers3DView.BorderColor = [0, 0, 0, 1]; 117 WebInspector.Layers3DView.BorderColor = [0, 0, 0, 1];
114 WebInspector.Layers3DView.ScrollRectBackgroundColor = [178, 0, 0, 0.4]; 118 WebInspector.Layers3DView.ScrollRectBackgroundColor = [178, 0, 0, 0.4];
115 WebInspector.Layers3DView.SelectedScrollRectBackgroundColor = [178, 0, 0, 0.6]; 119 WebInspector.Layers3DView.SelectedScrollRectBackgroundColor = [178, 0, 0, 0.6];
116 WebInspector.Layers3DView.ScrollRectBorderColor = [178, 0, 0, 1]; 120 WebInspector.Layers3DView.ScrollRectBorderColor = [178, 0, 0, 1];
121 WebInspector.Layers3DView.BorderWidth = 1;
122 WebInspector.Layers3DView.SelectedBorderWidth = 2;
117 123
118 WebInspector.Layers3DView.LayerSpacing = 20; 124 WebInspector.Layers3DView.LayerSpacing = 20;
119 WebInspector.Layers3DView.ScrollRectSpacing = 4; 125 WebInspector.Layers3DView.ScrollRectSpacing = 4;
120 126
121 WebInspector.Layers3DView.prototype = { 127 WebInspector.Layers3DView.prototype = {
122 /** 128 /**
123 * @param {function(!Array.<!WebInspector.KeyboardShortcut.Descriptor>, func tion(?Event=))} registerShortcutDelegate 129 * @param {function(!Array.<!WebInspector.KeyboardShortcut.Descriptor>, func tion(?Event=))} registerShortcutDelegate
124 */ 130 */
125 registerShortcuts: function(registerShortcutDelegate) 131 registerShortcuts: function(registerShortcutDelegate)
126 { 132 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 this._setOutline(WebInspector.Layers3DView.OutlineType.Hovered, null); 174 this._setOutline(WebInspector.Layers3DView.OutlineType.Hovered, null);
169 this._setOutline(WebInspector.Layers3DView.OutlineType.Selected, activeO bject); 175 this._setOutline(WebInspector.Layers3DView.OutlineType.Selected, activeO bject);
170 }, 176 },
171 177
172 /** 178 /**
173 * @param {!WebInspector.Layer} layer 179 * @param {!WebInspector.Layer} layer
174 * @param {string=} imageURL 180 * @param {string=} imageURL
175 */ 181 */
176 showImageForLayer: function(layer, imageURL) 182 showImageForLayer: function(layer, imageURL)
177 { 183 {
178 var texture = this._gl.createTexture(); 184 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 }, 185 },
183 186
184 /** 187 /**
188 * @param {!Array.<!Object>} tiles
caseq 2014/06/18 12:56:19 Can we be more specific than just object?
malch 2014/06/18 13:08:54 Done.
189 */
190 setTiles: function(tiles)
191 {
192 this._picturesForLayer = {};
193 tiles.forEach(this._setTile, this);
194 },
195
196 /**
197 * @param {!Object} tile
caseq 2014/06/18 12:56:19 ditto.
malch 2014/06/18 13:08:54 Done.
198 */
199 _setTile: function(tile)
200 {
201 var texture = this._gl.createTexture();
202 texture.image = new Image();
203 texture.image.addEventListener("load", this._handleLoadedTexture.bind(th is, texture, tile.layerId, tile.rect), false);
204 texture.image.src = tile.imageURL;
205 },
206
207 /**
185 * @param {!Element} canvas 208 * @param {!Element} canvas
186 * @return {!Object} 209 * @return {!Object}
187 */ 210 */
188 _initGL: function(canvas) 211 _initGL: function(canvas)
189 { 212 {
190 var gl = canvas.getContext("webgl"); 213 var gl = canvas.getContext("webgl");
191 gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); 214 gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
192 gl.enable(gl.BLEND); 215 gl.enable(gl.BLEND);
193 gl.clearColor(0.0, 0.0, 0.0, 0.0); 216 gl.clearColor(0.0, 0.0, 0.0, 0.0);
194 gl.enable(gl.DEPTH_TEST); 217 gl.enable(gl.DEPTH_TEST);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 _initProjectionMatrix: function() 293 _initProjectionMatrix: function()
271 { 294 {
272 this._pMatrix = new WebKitCSSMatrix().scale(1, -1, -1).translate(-1, -1, 0) 295 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()); 296 .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)); 297 this._gl.uniformMatrix4fv(this._shaderProgram.pMatrixUniform, false, thi s._arrayFromMatrix(this._pMatrix));
275 }, 298 },
276 299
277 /** 300 /**
278 * @param {!Object} texture 301 * @param {!Object} texture
279 * @param {string} layerId 302 * @param {string} layerId
303 * @param {!Array.<number>} rect
280 */ 304 */
281 _handleLoadedTexture: function(texture, layerId) 305 _handleLoadedTexture: function(texture, layerId, rect)
282 { 306 {
283 this._gl.bindTexture(this._gl.TEXTURE_2D, texture); 307 this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
284 this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, true); 308 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); 309 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); 310 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); 311 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); 312 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); 313 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); 314 this._gl.bindTexture(this._gl.TEXTURE_2D, null);
291 this._textureForLayer = {}; 315 if (!this._picturesForLayer[layerId])
292 this._textureForLayer[layerId] = texture; 316 this._picturesForLayer[layerId] = [];
317 this._picturesForLayer[layerId].push({texture: texture, rect: rect});
293 this._update(); 318 this._update();
294 }, 319 },
295 320
296 _initWhiteTexture: function() 321 _initWhiteTexture: function()
297 { 322 {
298 this._whiteTexture = this._gl.createTexture(); 323 this._whiteTexture = this._gl.createTexture();
299 this._gl.bindTexture(this._gl.TEXTURE_2D, this._whiteTexture); 324 this._gl.bindTexture(this._gl.TEXTURE_2D, this._whiteTexture);
300 var whitePixel = new Uint8Array([255, 255, 255, 255]); 325 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); 326 this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, 1, 1, 0, this ._gl.RGBA, this._gl.UNSIGNED_BYTE, whitePixel);
302 }, 327 },
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 * @param {number=} scrollRectIndex 405 * @param {number=} scrollRectIndex
381 */ 406 */
382 _isObjectActive: function(type, layer, scrollRectIndex) 407 _isObjectActive: function(type, layer, scrollRectIndex)
383 { 408 {
384 var activeObject = this._lastActiveObject[type]; 409 var activeObject = this._lastActiveObject[type];
385 return activeObject && activeObject.layer && activeObject.layer.id() === layer.id() && (typeof scrollRectIndex !== "number" || activeObject.scrollRectIn dex === scrollRectIndex); 410 return activeObject && activeObject.layer && activeObject.layer.id() === layer.id() && (typeof scrollRectIndex !== "number" || activeObject.scrollRectIn dex === scrollRectIndex);
386 }, 411 },
387 412
388 /** 413 /**
389 * @param {!WebInspector.Layer} layer 414 * @param {!WebInspector.Layer} layer
390 * @return {!{color: !Array.<number>, borderColor: !Array.<number>}} 415 * @return {!WebInspector.Layers3DView.LayerStyle}
391 */ 416 */
392 _colorsForLayer: function(layer) 417 _styleForLayer: function(layer)
393 { 418 {
394 var isSelected = this._isObjectActive(WebInspector.Layers3DView.OutlineT ype.Selected, layer); 419 var isSelected = this._isObjectActive(WebInspector.Layers3DView.OutlineT ype.Selected, layer);
395 var isHovered = this._isObjectActive(WebInspector.Layers3DView.OutlineTy pe.Hovered, layer); 420 var isHovered = this._isObjectActive(WebInspector.Layers3DView.OutlineTy pe.Hovered, layer);
396 var color = isSelected ? WebInspector.Layers3DView.SelectedBackgroundCol or : WebInspector.Layers3DView.BackgroundColor; 421 var color = isSelected ? WebInspector.Layers3DView.SelectedBackgroundCol or : WebInspector.Layers3DView.BackgroundColor;
397 var borderColor = isHovered ? WebInspector.Layers3DView.HoveredBorderCol or : WebInspector.Layers3DView.BorderColor; 422 var borderColor;
398 return {color: color, borderColor: borderColor}; 423 if (isSelected)
424 borderColor = WebInspector.Layers3DView.SelectedBorderColor;
425 else if (isHovered)
426 borderColor = WebInspector.Layers3DView.HoveredBorderColor;
427 else
428 borderColor = WebInspector.Layers3DView.BorderColor;
429 var borderWidth = isSelected ? WebInspector.Layers3DView.SelectedBorderW idth : WebInspector.Layers3DView.BorderWidth;
430 return {color: color, borderColor: borderColor, borderWidth: borderWidth };
399 }, 431 },
400 432
401 /** 433 /**
402 * @param {!Array.<number>} quad 434 * @param {!Array.<number>} quad
403 * @param {number} z 435 * @param {number} z
404 * @return {!Array.<number>} 436 * @return {!Array.<number>}
405 */ 437 */
406 _calculateVerticesForQuad: function(quad, z) 438 _calculateVerticesForQuad: function(quad, z)
407 { 439 {
408 return [quad[0], quad[1], z, quad[2], quad[3], z, quad[4], quad[5], z, q uad[6], quad[7], z]; 440 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; 507 return this._depthByLayerId[layer.id()] * WebInspector.Layers3DView.Laye rSpacing + index * WebInspector.Layers3DView.ScrollRectSpacing + 1;
476 }, 508 },
477 509
478 /** 510 /**
479 * @param {!WebInspector.Layer} layer 511 * @param {!WebInspector.Layer} layer
480 */ 512 */
481 _drawLayer: function(layer) 513 _drawLayer: function(layer)
482 { 514 {
483 var gl = this._gl; 515 var gl = this._gl;
484 var vertices; 516 var vertices;
517 var style = this._styleForLayer(layer);
518 var layerDepth = this._depthByLayerId[layer.id()] * WebInspector.Layers3 DView.LayerSpacing;
485 if (this._isVisible[layer.id()]) { 519 if (this._isVisible[layer.id()]) {
486 vertices = this._calculateVerticesForQuad(layer.quad(), this._depthB yLayerId[layer.id()] * WebInspector.Layers3DView.LayerSpacing); 520 vertices = this._calculateVerticesForQuad(layer.quad(), layerDepth);
487 var colors = this._colorsForLayer(layer); 521 gl.lineWidth(style.borderWidth);
488 this._drawRectangle(vertices, colors.color, gl.TRIANGLE_FAN, this._t extureForLayer[layer.id()]); 522 this._drawRectangle(vertices, style.borderColor, gl.LINE_LOOP);
489 this._drawRectangle(vertices, colors.borderColor, gl.LINE_LOOP); 523 gl.lineWidth(1);
490 } 524 }
491 this._scrollRectQuadsForLayer[layer.id()] = this._calculateScrollRectQua dsForLayer(layer); 525 this._scrollRectQuadsForLayer[layer.id()] = this._calculateScrollRectQua dsForLayer(layer);
492 var scrollRectQuads = this._scrollRectQuadsForLayer[layer.id()]; 526 var scrollRectQuads = this._scrollRectQuadsForLayer[layer.id()];
493 for (var i = 0; i < scrollRectQuads.length; ++i) { 527 for (var i = 0; i < scrollRectQuads.length; ++i) {
494 vertices = this._calculateVerticesForQuad(scrollRectQuads[i], this._ calculateScrollRectDepth(layer, i)); 528 vertices = this._calculateVerticesForQuad(scrollRectQuads[i], this._ calculateScrollRectDepth(layer, i));
495 var isSelected = this._isObjectActive(WebInspector.Layers3DView.Outl ineType.Selected, layer, i); 529 var isSelected = this._isObjectActive(WebInspector.Layers3DView.Outl ineType.Selected, layer, i);
496 var color = isSelected ? WebInspector.Layers3DView.SelectedScrollRec tBackgroundColor : WebInspector.Layers3DView.ScrollRectBackgroundColor; 530 var color = isSelected ? WebInspector.Layers3DView.SelectedScrollRec tBackgroundColor : WebInspector.Layers3DView.ScrollRectBackgroundColor;
497 this._drawRectangle(vertices, color, gl.TRIANGLE_FAN); 531 this._drawRectangle(vertices, color, gl.TRIANGLE_FAN);
498 this._drawRectangle(vertices, WebInspector.Layers3DView.ScrollRectBo rderColor, gl.LINE_LOOP); 532 this._drawRectangle(vertices, WebInspector.Layers3DView.ScrollRectBo rderColor, gl.LINE_LOOP);
499 } 533 }
534 var tiles = this._picturesForLayer[layer.id()] || [];
535 for (var i = 0; i < tiles.length; ++i) {
536 var tile = tiles[i];
537 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] });
538 vertices = this._calculateVerticesForQuad(quad, layerDepth);
539 this._drawRectangle(vertices, style.color, gl.TRIANGLE_FAN, tile.tex ture);
540 }
500 }, 541 },
501 542
502 _drawViewport: function() 543 _drawViewport: function()
503 { 544 {
504 var viewport = this._layerTree.viewportSize(); 545 var viewport = this._layerTree.viewportSize();
505 var vertices = [0, 0, 0, viewport.width, 0, 0, viewport.width, viewport. height, 0, 0, viewport.height, 0]; 546 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]; 547 var color = [0, 0, 0, 1];
507 this._gl.lineWidth(3.0); 548 this._gl.lineWidth(3.0);
508 this._drawRectangle(vertices, color, this._gl.LINE_LOOP); 549 this._drawRectangle(vertices, color, this._gl.LINE_LOOP);
509 this._gl.lineWidth(1.0); 550 this._gl.lineWidth(1.0);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 _onDoubleClick: function(event) 738 _onDoubleClick: function(event)
698 { 739 {
699 var object = this._activeObjectFromEventPoint(event); 740 var object = this._activeObjectFromEventPoint(event);
700 if (object && object.layer) 741 if (object && object.layer)
701 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, object.layer); 742 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, object.layer);
702 event.stopPropagation(); 743 event.stopPropagation();
703 }, 744 },
704 745
705 __proto__: WebInspector.VBox.prototype 746 __proto__: WebInspector.VBox.prototype
706 } 747 }
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