| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <link rel="import" href="/base/base.html"> |
| <link rel="import" href="/extras/chrome/cc/raster_task.html"> |
| <link rel="import" href="/extras/chrome/cc/raster_task_view.html"> |
| <link rel="import" href="/extras/chrome/cc/selection.html"> |
| <link rel="import" href="/core/analysis/single_event_sub_view.html"> |
| <script> |
| 'use strict'; |
| |
| tr.exportTo('tr.e.cc', function() { |
| /** |
| * @constructor |
| */ |
| function RasterTaskSelection(selection) { |
| tr.e.cc.Selection.call(this); |
| var whySupported = RasterTaskSelection.whySuported(selection); |
| if (!whySupported.ok) |
| throw new Error('Fail: ' + whySupported.why); |
| this.slices_ = tr.b.asArray(selection); |
| this.tiles_ = this.slices_.map(function(slice) { |
| var tile = tr.e.cc.getTileFromRasterTaskSlice(slice); |
| if (tile === undefined) |
| throw new Error('This should never happen due to .supports check.'); |
| return tile; |
| }); |
| } |
| RasterTaskSelection.whySuported = function(selection) { |
| if (!(selection instanceof tr.c.Selection)) |
| return {ok: false, why: 'Must be selection'}; |
| |
| if (selection.length === 0) |
| return {ok: false, why: 'Selection must be non empty'}; |
| |
| var tile0; |
| for (var i = 0; i < selection.length; i++) { |
| var event = selection[i]; |
| if (!(event instanceof tr.model.Slice)) |
| return {ok: false, why: 'Not a slice'}; |
| |
| var tile = tr.e.cc.getTileFromRasterTaskSlice(selection[i]); |
| if (tile === undefined) |
| return {ok: false, why: 'No tile found'}; |
| |
| if (i === 0) { |
| tile0 = tile; |
| } else { |
| if (tile.containingSnapshot != tile0.containingSnapshot) { |
| return { |
| ok: false, |
| why: 'Raster tasks are from different compositor instances' |
| }; |
| } |
| } |
| } |
| return {ok: true}; |
| } |
| |
| RasterTaskSelection.supports = function(selection) { |
| return RasterTaskSelection.whySuported(selection).ok; |
| }; |
| |
| RasterTaskSelection.prototype = { |
| __proto__: tr.e.cc.Selection.prototype, |
| |
| get specicifity() { |
| return 3; |
| }, |
| |
| get associatedLayerId() { |
| var tile0 = this.tiles_[0]; |
| var allSameLayer = this.tiles_.every(function(tile) { |
| tile.layerId == tile0.layerId; |
| }); |
| if (allSameLayer) |
| return tile0.layerId; |
| return undefined; |
| }, |
| |
| get extraHighlightsByLayerId() { |
| var highlights = {}; |
| this.tiles_.forEach(function(tile, i) { |
| if (highlights[tile.layerId] === undefined) |
| highlights[tile.layerId] = []; |
| var slice = this.slices_[i]; |
| highlights[tile.layerId].push({ |
| colorKey: slice.title, |
| rect: tile.layerRect |
| }); |
| }, this); |
| return highlights; |
| }, |
| |
| createAnalysis: function() { |
| var sel = new tr.c.Selection(); |
| this.slices_.forEach(function(slice) { |
| sel.push(slice); |
| }); |
| |
| var analysis; |
| if (sel.length == 1) |
| analysis = document.createElement('tr-c-a-single-event-sub-view'); |
| else |
| analysis = new RasterTaskView(); |
| analysis.selection = sel; |
| return analysis; |
| }, |
| |
| findEquivalent: function(lthi) { |
| // Raster tasks are only valid in one LTHI. |
| return undefined; |
| }, |
| |
| // RasterTaskSelection specific stuff follows. |
| get containingSnapshot() { |
| return this.tiles_[0].containingSnapshot; |
| } |
| }; |
| |
| return { |
| RasterTaskSelection: RasterTaskSelection |
| }; |
| }); |
| </script> |