Commit bd8cd491 authored by Wei Lee's avatar Wei Lee Committed by Commit Bot

CCA: Change the rule for sorting preview resolutions

This CL changes the preview resolution sorting order from:
1. Resolution which is slightly larger than the screen size
2. The larger, the better

To:
(Given |Rc| is the capture resolution and |Rs| is the screen size, and
|Rp| means the preview resolution)

If |Rc| <= |Rs|:
  1. All |Rp| <= |Rc|, and the larger, the better.
  2. All |Rp| > |Rc|, and the smaller, the better.

If |Rc| > |Rs|:
  1. All |Rp| where |Rs| <= |Rp| <= |Rc|, and the smaller, the better.
  2. All |Rp| < |Rs|, and the larger, the better.
  3. All |Rp| > |Rc|, and the smaller, the better.

Bug: 1069440
Test: Manually checks the order in CCA
Change-Id: I7a3a9160e4eac560b060da81fe6657467c476af7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145375
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Reviewed-by: default avatarKuo Jen Wei <inker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759184}
parent a232101b
......@@ -572,31 +572,47 @@ export class PhotoConstraintsPreferrer extends ConstraintsPreferrer {
}
/**
* @param {!ResolutionList} rs
* @param {!ResolutionList} resolutions
* @return {!ResolutionList}
*/
const sortPreview = (rs) => {
if (rs.length === 0) {
const sortPreview = (resolutions) => {
if (resolutions.length === 0) {
return [];
}
rs = [...rs].sort((r1, r2) => r2.width - r1.width);
// Promote resolution slightly larger than screen size to the first.
const /** number */ screenW =
Math.floor(window.screen.width * window.devicePixelRatio);
const /** number */ screenH =
Math.floor(window.screen.height * window.devicePixelRatio);
let /** ?number */ minIdx = null;
rs.forEach(({width, height}, idx) => {
if (width >= screenW && height >= screenH) {
minIdx = idx;
}
});
if (minIdx !== null) {
rs.unshift(...rs.splice(minIdx, 1));
}
return rs;
// Sorts the preview resolution (Rp) according to the capture resolution
// (Rc) and the screen size (Rs) with the following orders:
// If |Rc| <= |Rs|:
// 1. All |Rp| <= |Rc|, and the larger, the better.
// 2. All |Rp| > |Rc|, and the smaller, the better.
//
// If |Rc| > |Rs|:
// 1. All |Rp| where |Rs| <= |Rp| <= |Rc|, and the smaller, the
// better.
// 2. All |Rp| < |Rs|, and the larger, the better.
// 3. All |Rp| > |Rc|, and the smaller, the better.
//
const Rs = Math.floor(window.screen.width * window.devicePixelRatio);
const Rc = captureR.width;
const cmpDescending = (r1, r2) => r2.width - r1.width;
const cmpAscending = (r1, r2) => r1.width - r2.width;
if (Rc <= Rs) {
const notLargerThanRc =
resolutions.filter((r) => r.width <= Rc).sort(cmpDescending);
const largerThanRc =
resolutions.filter((r) => r.width > Rc).sort(cmpAscending);
return notLargerThanRc.concat(largerThanRc);
} else {
const betweenRsRc =
resolutions.filter((r) => Rs <= r.width && r.width <= Rc)
.sort(cmpAscending);
const smallerThanRs =
resolutions.filter((r) => r.width < Rs).sort(cmpDescending);
const largerThanRc =
resolutions.filter((r) => r.width > Rc).sort(cmpAscending);
return betweenRsRc.concat(smallerThanRs).concat(largerThanRc);
}
};
const /** !Array<!MediaStreamConstraints> */ previewCandidates =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment