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

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