зеркало из https://github.com/mozilla/gecko-dev.git
Merge m-c to inbound, a=merge
This commit is contained in:
Коммит
97868e2577
|
@ -3415,9 +3415,9 @@ ElementEditor.prototype = {
|
|||
let newAttributeIndex;
|
||||
if (isDeletedAttribute) {
|
||||
newAttributeIndex = attributeIndex;
|
||||
} else if (direction == Ci.nsIFocusManager.MOVEFOCUS_FORWARD) {
|
||||
} else if (direction == Services.focus.MOVEFOCUS_FORWARD) {
|
||||
newAttributeIndex = attributeIndex + 1;
|
||||
} else if (direction == Ci.nsIFocusManager.MOVEFOCUS_BACKWARD) {
|
||||
} else if (direction == Services.focus.MOVEFOCUS_BACKWARD) {
|
||||
newAttributeIndex = attributeIndex - 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/* eslint-disable mozilla/reject-some-requires */
|
||||
const {Ci} = require("chrome");
|
||||
/* eslint-enable mozilla/reject-some-requires */
|
||||
const promise = require("promise");
|
||||
const CssLogic = require("devtools/shared/inspector/css-logic");
|
||||
const {ELEMENT_STYLE} = require("devtools/shared/specs/styles");
|
||||
|
@ -627,7 +624,7 @@ Rule.prototype = {
|
|||
editClosestTextProperty: function (textProperty, direction) {
|
||||
let index = this.textProps.indexOf(textProperty);
|
||||
|
||||
if (direction === Ci.nsIFocusManager.MOVEFOCUS_FORWARD) {
|
||||
if (direction === Services.focus.MOVEFOCUS_FORWARD) {
|
||||
for (++index; index < this.textProps.length; ++index) {
|
||||
if (!this.textProps[index].invisible) {
|
||||
break;
|
||||
|
@ -638,7 +635,7 @@ Rule.prototype = {
|
|||
} else {
|
||||
this.textProps[index].editor.nameSpan.click();
|
||||
}
|
||||
} else if (direction === Ci.nsIFocusManager.MOVEFOCUS_BACKWARD) {
|
||||
} else if (direction === Services.focus.MOVEFOCUS_BACKWARD) {
|
||||
for (--index; index >= 0; --index) {
|
||||
if (!this.textProps[index].invisible) {
|
||||
break;
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/* eslint-disable mozilla/reject-some-requires */
|
||||
const {Ci} = require("chrome");
|
||||
/* eslint-enable mozilla/reject-some-requires */
|
||||
/* eslint-disable mozilla/reject-some-requires */
|
||||
const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
|
||||
/* eslint-enable mozilla/reject-some-requires */
|
||||
|
@ -584,7 +581,7 @@ RuleEditor.prototype = {
|
|||
* The move focus direction number.
|
||||
*/
|
||||
_moveSelectorFocus: function (direction) {
|
||||
if (!direction || direction === Ci.nsIFocusManager.MOVEFOCUS_BACKWARD) {
|
||||
if (!direction || direction === Services.focus.MOVEFOCUS_BACKWARD) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/* eslint-disable mozilla/reject-some-requires */
|
||||
const {Ci} = require("chrome");
|
||||
/* eslint-enable mozilla/reject-some-requires */
|
||||
const {l10n} = require("devtools/shared/inspector/css-logic");
|
||||
const {getCssProperties} = require("devtools/shared/fronts/css-properties");
|
||||
const {InplaceEditor, editableField} =
|
||||
|
@ -22,6 +19,7 @@ const {
|
|||
parseDeclarations,
|
||||
parseSingleValue,
|
||||
} = require("devtools/shared/css-parsing-utils");
|
||||
const Services = require("Services");
|
||||
|
||||
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
|
||||
|
@ -642,7 +640,7 @@ TextPropertyEditor.prototype = {
|
|||
// Remove a property if the property value is empty and the property
|
||||
// value is not about to be focused
|
||||
if (!this.prop.value &&
|
||||
direction !== Ci.nsIFocusManager.MOVEFOCUS_FORWARD) {
|
||||
direction !== Services.focus.MOVEFOCUS_FORWARD) {
|
||||
this.remove(direction);
|
||||
return;
|
||||
}
|
||||
|
@ -741,7 +739,7 @@ TextPropertyEditor.prototype = {
|
|||
// A timeout is used here to accurately check the state, since the inplace
|
||||
// editor `done` and `destroy` events fire before the next editor
|
||||
// is focused.
|
||||
if (!value.trim() && direction !== Ci.nsIFocusManager.MOVEFOCUS_BACKWARD) {
|
||||
if (!value.trim() && direction !== Services.focus.MOVEFOCUS_BACKWARD) {
|
||||
setTimeout(() => {
|
||||
if (!this.editing) {
|
||||
this.remove(direction);
|
||||
|
|
|
@ -300,7 +300,7 @@
|
|||
<label value="&netmonitorUI.perfNotice1;"/>
|
||||
<button id="requests-menu-perf-notice-button"
|
||||
standalone="true"
|
||||
label="&netmonitorUI.perfNotice3;"
|
||||
tooltiptext="&netmonitorUI.perfNotice3;"
|
||||
class="devtools-toolbarbutton"/>
|
||||
<label value="&netmonitorUI.perfNotice2;"/>
|
||||
</hbox>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
const {Ci, Cc} = require("chrome");
|
||||
const Services = require("Services");
|
||||
const focusManager = Services.focus;
|
||||
|
||||
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
const CONTENT_TYPES = {
|
||||
|
@ -38,8 +39,8 @@ const CONTENT_TYPES = {
|
|||
// for safety.
|
||||
const MAX_POPUP_ENTRIES = 500;
|
||||
|
||||
const FOCUS_FORWARD = Ci.nsIFocusManager.MOVEFOCUS_FORWARD;
|
||||
const FOCUS_BACKWARD = Ci.nsIFocusManager.MOVEFOCUS_BACKWARD;
|
||||
const FOCUS_FORWARD = focusManager.MOVEFOCUS_FORWARD;
|
||||
const FOCUS_BACKWARD = focusManager.MOVEFOCUS_BACKWARD;
|
||||
|
||||
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
|
@ -83,8 +84,8 @@ function isKeyIn(key, ...keys) {
|
|||
* Called when input is committed or blurred. Called with
|
||||
* current value, a boolean telling the caller whether to
|
||||
* commit the change, and the direction of the next element to be
|
||||
* selected. Direction may be one of nsIFocusManager.MOVEFOCUS_FORWARD,
|
||||
* nsIFocusManager.MOVEFOCUS_BACKWARD, or null (no movement).
|
||||
* selected. Direction may be one of Services.focus.MOVEFOCUS_FORWARD,
|
||||
* Services.focus.MOVEFOCUS_BACKWARD, or null (no movement).
|
||||
* This function is called before the editor has been torn down.
|
||||
* {Function} destroy:
|
||||
* Called when the editor is destroyed and has been torn down.
|
||||
|
@ -1554,10 +1555,6 @@ function moveFocus(win, direction) {
|
|||
return focusManager.moveFocus(win, null, direction, 0);
|
||||
}
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "focusManager", function () {
|
||||
return Services.focus;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "CSSPropertyList", function () {
|
||||
return domUtils.getCSSPropertyNames(domUtils.INCLUDE_ALIASES).sort();
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/* globals localStorage, window */
|
||||
/* globals localStorage, window, document, NodeFilter */
|
||||
|
||||
// Some constants from nsIPrefBranch.idl.
|
||||
const PREF_INVALID = 0;
|
||||
|
@ -519,6 +519,63 @@ const Services = {
|
|||
};
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* An implementation of Services.focus that holds just the
|
||||
* properties and methods needed by devtools.
|
||||
* @see nsIFocusManager.idl for details.
|
||||
*/
|
||||
focus: {
|
||||
// These values match nsIFocusManager in order to make testing a
|
||||
// bit simpler.
|
||||
MOVEFOCUS_FORWARD: 1,
|
||||
MOVEFOCUS_BACKWARD: 2,
|
||||
|
||||
get focusedElement() {
|
||||
if (!document.hasFocus()) {
|
||||
return null;
|
||||
}
|
||||
return document.activeElement;
|
||||
},
|
||||
|
||||
moveFocus: function (window, startElement, type, flags) {
|
||||
if (flags !== 0) {
|
||||
throw new Error("shim Services.focus.moveFocus only accepts flags===0");
|
||||
}
|
||||
if (type !== Services.focus.MOVEFOCUS_FORWARD
|
||||
&& type !== Services.focus.MOVEFOCUS_BACKWARD) {
|
||||
throw new Error("shim Services.focus.moveFocus only supports " +
|
||||
" MOVEFOCUS_FORWARD and MOVEFOCUS_BACKWARD");
|
||||
}
|
||||
|
||||
if (!startElement) {
|
||||
startElement = document.activeElement || document;
|
||||
}
|
||||
|
||||
let iter = document.createTreeWalker(document, NodeFilter.SHOW_ELEMENT, {
|
||||
acceptNode: function (node) {
|
||||
let tabIndex = node.getAttribute("tabindex");
|
||||
if (tabIndex === "-1") {
|
||||
return NodeFilter.FILTER_SKIP;
|
||||
}
|
||||
node.focus();
|
||||
if (document.activeElement == node) {
|
||||
return NodeFilter.FILTER_ACCEPT;
|
||||
}
|
||||
return NodeFilter.FILTER_SKIP;
|
||||
}
|
||||
});
|
||||
|
||||
iter.currentNode = startElement;
|
||||
|
||||
// Sets the focus via side effect in the filter.
|
||||
if (type === Services.focus.MOVEFOCUS_FORWARD) {
|
||||
iter.nextNode();
|
||||
} else {
|
||||
iter.previousNode();
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,4 +3,5 @@ support-files =
|
|||
prefs-wrapper.js
|
||||
|
||||
[test_service_appinfo.html]
|
||||
[test_service_focus.html]
|
||||
[test_service_prefs.html]
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1278473
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 1278473 - replace Services.focus</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
||||
|
||||
<script type="application/javascript;version=1.8">
|
||||
"use strict";
|
||||
var exports = {};
|
||||
</script>
|
||||
|
||||
<script type="application/javascript;version=1.8"
|
||||
src="resource://devtools/client/shared/shim/Services.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<span>
|
||||
<span id="start" testvalue="0" tabindex="0"> </span>
|
||||
<label>
|
||||
<input testvalue="1" type="radio">Hi</input>
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" tabindex="-1">Bye</input>
|
||||
</label>
|
||||
<label style="display: none">
|
||||
<input id="button3" type="radio" tabindex="-1">Invisible</input>
|
||||
</label>
|
||||
<input id="button4" type="radio" disabled="true">Disabled</input>
|
||||
<span testvalue="2" tabindex="0"> </span>
|
||||
</span>
|
||||
|
||||
<script type="application/javascript;version=1.8">
|
||||
"use strict";
|
||||
|
||||
// The test assumes these are identical, so assert it here.
|
||||
is(Services.focus.MOVEFOCUS_BACKWARD, SpecialPowers.Services.focus.MOVEFOCUS_BACKWARD,
|
||||
"check MOVEFOCUS_BACKWARD");
|
||||
is(Services.focus.MOVEFOCUS_FORWARD, SpecialPowers.Services.focus.MOVEFOCUS_FORWARD,
|
||||
"check MOVEFOCUS_FORWARD");
|
||||
|
||||
function moveFocus(element, type, expect) {
|
||||
let current = document.activeElement;
|
||||
const suffix = "(type=" + type + ", to=" + expect + ")";
|
||||
|
||||
// First try with the platform implementation.
|
||||
SpecialPowers.Services.focus.moveFocus(window, element, type, 0);
|
||||
is(document.activeElement.getAttribute("testvalue"), expect,
|
||||
"platform moveFocus " + suffix);
|
||||
|
||||
// Reset the focus and try again with the shim.
|
||||
current.focus();
|
||||
is(document.activeElement, current, "reset " + suffix);
|
||||
|
||||
Services.focus.moveFocus(window, element, type, 0);
|
||||
is(document.activeElement.getAttribute("testvalue"), expect,
|
||||
"shim moveFocus " + suffix);
|
||||
}
|
||||
|
||||
let start = document.querySelector("#start");
|
||||
start.focus();
|
||||
is(document.activeElement.getAttribute("testvalue"), "0", "initial focus");
|
||||
|
||||
moveFocus(null, Services.focus.MOVEFOCUS_FORWARD, "1");
|
||||
moveFocus(null, Services.focus.MOVEFOCUS_FORWARD, "2");
|
||||
let end = document.activeElement;
|
||||
moveFocus(null, Services.focus.MOVEFOCUS_BACKWARD, "1");
|
||||
moveFocus(null, Services.focus.MOVEFOCUS_BACKWARD, "0");
|
||||
|
||||
moveFocus(start, Services.focus.MOVEFOCUS_FORWARD, "1");
|
||||
moveFocus(end, Services.focus.MOVEFOCUS_BACKWARD, "1");
|
||||
</script>
|
||||
</body>
|
|
@ -84,18 +84,6 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
|
|||
LOCAL_INCLUDES += [
|
||||
'/dom/system/gonk',
|
||||
]
|
||||
if CONFIG['ANDROID_VERSION'] == '15':
|
||||
LOCAL_INCLUDES += [
|
||||
'%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
|
||||
'dalvik/libnativehelper/include/nativehelper',
|
||||
'frameworks/base/include',
|
||||
'frameworks/base/include/binder',
|
||||
'frameworks/base/include/media',
|
||||
'frameworks/base/include/media/stagefright/openmax',
|
||||
'frameworks/base/include/utils',
|
||||
'frameworks/base/media/libstagefright/include',
|
||||
]
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_B2G_FM']:
|
||||
LOCAL_INCLUDES += [
|
||||
|
|
|
@ -72,6 +72,7 @@ typedef union {
|
|||
* the unit is a must before asking for the value in any particular
|
||||
* form.
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
class nsStyleCoord {
|
||||
public:
|
||||
// Non-reference counted calc() value. See nsStyleStruct.h for some uses
|
||||
|
@ -262,6 +263,7 @@ private:
|
|||
* This is commonly used to hold the widths of the borders, margins,
|
||||
* or paddings of a box.
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
class nsStyleSides {
|
||||
public:
|
||||
nsStyleSides();
|
||||
|
@ -340,6 +342,7 @@ protected:
|
|||
* nsStyleCoord pairs. This is used to hold the dimensions of the
|
||||
* corners of a box (for, e.g., border-radius and outline-radius).
|
||||
*/
|
||||
/** <div rustbindgen private accessor="unsafe"></div> */
|
||||
class nsStyleCorners {
|
||||
public:
|
||||
nsStyleCorners();
|
||||
|
|
|
@ -36,22 +36,6 @@ if CONFIG['GNU_CXX']:
|
|||
]
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
|
||||
if CONFIG['ANDROID_VERSION'] == '15':
|
||||
LOCAL_INCLUDES += [
|
||||
'%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
|
||||
'dalvik/libnativehelper/include/nativehelper',
|
||||
'frameworks/base/include/',
|
||||
'frameworks/base/include/binder/',
|
||||
'frameworks/base/include/media/',
|
||||
'frameworks/base/include/media/stagefright/openmax',
|
||||
'frameworks/base/include/utils/',
|
||||
'frameworks/base/media/libstagefright/include',
|
||||
'frameworks/base/native/include',
|
||||
'hardware/libhardware/include',
|
||||
'system/core/include',
|
||||
]
|
||||
]
|
||||
|
||||
EXTRA_DSO_LDOPTS += [
|
||||
'-lutils',
|
||||
'-lstagefright',
|
||||
|
|
|
@ -13,6 +13,10 @@ Cu.import("resource://gre/modules/Task.jsm");
|
|||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Color", "resource://gre/modules/Color.jsm");
|
||||
XPCOMUtils.defineLazyGetter(this, "kDebug", () => {
|
||||
const kDebugPref = "findbar.modalHighlight.debug";
|
||||
return Services.prefs.getPrefType(kDebugPref) && Services.prefs.getBoolPref(kDebugPref);
|
||||
});
|
||||
|
||||
const kModalHighlightRepaintFreqMs = 10;
|
||||
const kModalHighlightPref = "findbar.modalHighlight";
|
||||
|
@ -50,6 +54,10 @@ const kModalStyle = `
|
|||
z-index: 2;
|
||||
}
|
||||
|
||||
.findbar-modalHighlight-outline.findbar-debug {
|
||||
z-index: 2147483647;
|
||||
}
|
||||
|
||||
.findbar-modalHighlight-outline[grow] {
|
||||
transform: scaleX(1.5) scaleY(1.5)
|
||||
}
|
||||
|
@ -73,6 +81,12 @@ const kModalStyle = `
|
|||
z-index: 1;
|
||||
}
|
||||
|
||||
.findbar-modalHighlight-outlineMask.findbar-debug {
|
||||
z-index: 2147483646;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.findbar-modalHighlight-outlineMask[brighttext] {
|
||||
background: #fff;
|
||||
}
|
||||
|
@ -88,6 +102,34 @@ const kModalStyle = `
|
|||
}`;
|
||||
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
|
||||
function mockAnonymousContentNode(domNode) {
|
||||
return {
|
||||
setTextContentForElement(id, text) {
|
||||
(domNode.querySelector("#" + id) || domNode).textContent = text;
|
||||
},
|
||||
getAttributeForElement(id, attrName) {
|
||||
let node = domNode.querySelector("#" + id) || domNode;
|
||||
if (!node.hasAttribute(attrName))
|
||||
return undefined;
|
||||
return node.getAttribute(attrName);
|
||||
},
|
||||
setAttributeForElement(id, attrName, attrValue) {
|
||||
(domNode.querySelector("#" + id) || domNode).setAttribute(attrName, attrValue);
|
||||
},
|
||||
removeAttributeForElement(id, attrName) {
|
||||
let node = domNode.querySelector("#" + id) || domNode;
|
||||
if (!node.hasAttribute(attrName))
|
||||
return;
|
||||
node.removeAttribute(attrName);
|
||||
},
|
||||
remove() {
|
||||
try {
|
||||
domNode.parentNode.removeChild(domNode);
|
||||
} catch (ex) {}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* FinderHighlighter class that is used by Finder.jsm to take care of the
|
||||
* 'Highlight All' feature, which can highlight all find occurrences in a page.
|
||||
|
@ -367,6 +409,8 @@ FinderHighlighter.prototype = {
|
|||
if (!this._modalHighlightOutline)
|
||||
return;
|
||||
|
||||
if (kDebug)
|
||||
this._modalHighlightOutline.remove();
|
||||
try {
|
||||
this.finder._getWindow().document
|
||||
.removeAnonymousContent(this._modalHighlightOutline);
|
||||
|
@ -578,7 +622,7 @@ FinderHighlighter.prototype = {
|
|||
// Create the main (yellow) highlight outline box.
|
||||
let outlineBox = document.createElement("div");
|
||||
outlineBox.setAttribute("id", kModalOutlineId);
|
||||
outlineBox.className = kModalOutlineId;
|
||||
outlineBox.className = kModalOutlineId + (kDebug ? ` ${kModalIdPrefix}-findbar-debug` : "");
|
||||
let outlineBoxText = document.createElement("span");
|
||||
outlineBoxText.setAttribute("id", kModalOutlineId + "-text");
|
||||
outlineBox.appendChild(outlineBoxText);
|
||||
|
@ -587,7 +631,9 @@ FinderHighlighter.prototype = {
|
|||
|
||||
this._repaintHighlightAllMask(window);
|
||||
|
||||
this._modalHighlightOutline = document.insertAnonymousContent(container);
|
||||
this._modalHighlightOutline = kDebug ?
|
||||
mockAnonymousContentNode(document.body.appendChild(container.firstChild)) :
|
||||
document.insertAnonymousContent(container);
|
||||
return this._modalHighlightOutline;
|
||||
},
|
||||
|
||||
|
@ -607,7 +653,7 @@ FinderHighlighter.prototype = {
|
|||
// Make sure the dimmed mask node takes the full width and height that's available.
|
||||
let {width, height} = this._getWindowDimensions(window);
|
||||
maskNode.setAttribute("id", kMaskId);
|
||||
maskNode.setAttribute("class", kMaskId);
|
||||
maskNode.setAttribute("class", kMaskId + (kDebug ? ` ${kModalIdPrefix}-findbar-debug` : ""));
|
||||
maskNode.setAttribute("style", `width: ${width}px; height: ${height}px;`);
|
||||
if (this._brightText)
|
||||
maskNode.setAttribute("brighttext", "true");
|
||||
|
@ -629,7 +675,9 @@ FinderHighlighter.prototype = {
|
|||
// free to alter DOM nodes inside the CanvasFrame.
|
||||
this._removeHighlightAllMask(window);
|
||||
|
||||
this._modalHighlightAllMask = document.insertAnonymousContent(maskNode);
|
||||
this._modalHighlightAllMask = kDebug ?
|
||||
mockAnonymousContentNode(document.body.appendChild(maskNode)) :
|
||||
document.insertAnonymousContent(maskNode);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -641,6 +689,8 @@ FinderHighlighter.prototype = {
|
|||
if (this._modalHighlightAllMask) {
|
||||
// If the current window isn't the one the content was inserted into, this
|
||||
// will fail, but that's fine.
|
||||
if (kDebug)
|
||||
this._modalHighlightAllMask.remove();
|
||||
try {
|
||||
window.document.removeAnonymousContent(this._modalHighlightAllMask);
|
||||
} catch(ex) {}
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:set ts=4 sw=4 sts=4 et: */
|
||||
/*
|
||||
* Copyright (c) 2015 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "HwcICS.h"
|
||||
#include "cutils/properties.h"
|
||||
#include "libdisplay/GonkDisplay.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
HwcICS::HwcICS()
|
||||
: HwcHALBase()
|
||||
{
|
||||
mHwc = (HwcDevice*)GetGonkDisplay()->GetHWCDevice();
|
||||
if (!mHwc) {
|
||||
printf_stderr("HwcHAL Error: Cannot load hwcomposer");
|
||||
}
|
||||
}
|
||||
|
||||
HwcICS::~HwcICS()
|
||||
{
|
||||
mHwc = nullptr;
|
||||
mEGLDisplay = nullptr;
|
||||
mEGLSurface = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
HwcICS::SetEGLInfo(hwc_display_t aEGLDisplay,
|
||||
hwc_surface_t aEGLSurface)
|
||||
{
|
||||
mEGLDisplay = aEGLDisplay;
|
||||
mEGLSurface = aEGLSurface;
|
||||
}
|
||||
|
||||
bool
|
||||
HwcICS::Query(QueryType aType)
|
||||
{
|
||||
bool value = false;
|
||||
switch (aType) {
|
||||
case QueryType::COLOR_FILL: {
|
||||
char propValue[PROPERTY_VALUE_MAX];
|
||||
property_get("ro.display.colorfill", propValue, "0");
|
||||
value = (atoi(propValue) == 1) ? true : false;
|
||||
break;
|
||||
}
|
||||
case QueryType::RB_SWAP:
|
||||
value = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
value = false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int
|
||||
HwcICS::Set(HwcList* aList,
|
||||
uint32_t aDisp)
|
||||
{
|
||||
if (!mHwc) {
|
||||
return -1;
|
||||
}
|
||||
return mHwc->set(mHwc, mEGLDisplay, mEGLSurface, aList);
|
||||
}
|
||||
|
||||
int
|
||||
HwcICS::ResetHwc()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
HwcICS::Prepare(HwcList *aList,
|
||||
uint32_t aDisp,
|
||||
hwc_rect_t aDispRect,
|
||||
buffer_handle_t aHandle,
|
||||
int aFenceFd)
|
||||
{
|
||||
return mHwc->prepare(mHwc, aList);
|
||||
}
|
||||
|
||||
bool
|
||||
HwcICS::SupportTransparency() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
HwcICS::GetGeometryChangedFlag(bool aGeometryChanged) const
|
||||
{
|
||||
return HWC_GEOMETRY_CHANGED;
|
||||
}
|
||||
|
||||
void
|
||||
HwcICS::SetCrop(HwcLayer& aLayer,
|
||||
const hwc_rect_t &aSrcCrop) const
|
||||
{
|
||||
aLayer.sourceCrop = aSrcCrop;
|
||||
}
|
||||
|
||||
bool
|
||||
HwcICS::EnableVsync(bool aEnable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
HwcICS::RegisterHwcEventCallback(const HwcHALProcs_t &aProcs)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create HwcICS
|
||||
UniquePtr<HwcHALBase>
|
||||
HwcHALBase::CreateHwcHAL()
|
||||
{
|
||||
return Move(MakeUnique<HwcICS>());
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -1,69 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:set ts=4 sw=4 sts=4 et: */
|
||||
/*
|
||||
* Copyright (c) 2015 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef mozilla_HwcICS
|
||||
#define mozilla_HwcICS
|
||||
|
||||
#include "HwcHALBase.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class HwcICS final : public HwcHALBase {
|
||||
public:
|
||||
explicit HwcICS();
|
||||
|
||||
virtual ~HwcICS();
|
||||
|
||||
virtual bool HasHwc() const override { return static_cast<bool>(mHwc); }
|
||||
|
||||
virtual void SetEGLInfo(hwc_display_t aEGLDisplay,
|
||||
hwc_surface_t aEGLSurface) override;
|
||||
|
||||
virtual bool Query(QueryType aType) override;
|
||||
|
||||
virtual int Set(HwcList *aList,
|
||||
uint32_t aDisp) override;
|
||||
|
||||
virtual int ResetHwc() override;
|
||||
|
||||
virtual int Prepare(HwcList *aList,
|
||||
uint32_t aDisp,
|
||||
hwc_rect_t aDispRect,
|
||||
buffer_handle_t aHandle,
|
||||
int aFenceFd) override;
|
||||
|
||||
virtual bool SupportTransparency() const override;
|
||||
|
||||
virtual uint32_t GetGeometryChangedFlag(bool aGeometryChanged) const override;
|
||||
|
||||
virtual void SetCrop(HwcLayer &aLayer,
|
||||
const hwc_rect_t &aSrcCrop) const override;
|
||||
|
||||
virtual bool EnableVsync(bool aEnable) override;
|
||||
|
||||
virtual bool RegisterHwcEventCallback(const HwcHALProcs_t &aProcs) override;
|
||||
|
||||
private:
|
||||
HwcDevice *mHwc = nullptr;
|
||||
hwc_display_t mEGLDisplay = nullptr;
|
||||
hwc_surface_t mEGLSurface = nullptr;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_HwcICS
|
|
@ -1,232 +0,0 @@
|
|||
/* Copyright 2013 Mozilla Foundation and Mozilla contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "GonkDisplayICS.h"
|
||||
#include <ui/FramebufferNativeWindow.h>
|
||||
|
||||
#include <hardware/hardware.h>
|
||||
#include <hardware/gralloc.h>
|
||||
#include <hardware/hwcomposer.h>
|
||||
#include <hardware_legacy/power.h>
|
||||
#include <cutils/log.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
|
||||
using namespace android;
|
||||
|
||||
|
||||
namespace {
|
||||
static const char* kSleepFile = "/sys/power/wait_for_fb_sleep";
|
||||
static const char* kWakeFile = "/sys/power/wait_for_fb_wake";
|
||||
static mozilla::GonkDisplay::OnEnabledCallbackType sEnabledCallback;
|
||||
static pthread_t sFramebufferWatchThread;
|
||||
|
||||
static void *
|
||||
frameBufferWatcher(void *)
|
||||
{
|
||||
int len = 0;
|
||||
char buf;
|
||||
|
||||
while (true) {
|
||||
// Cannot use epoll here because kSleepFile and kWakeFile are
|
||||
// always ready to read and blocking.
|
||||
{
|
||||
mozilla::ScopedClose fd(open(kSleepFile, O_RDONLY, 0));
|
||||
do {
|
||||
len = read(fd.get(), &buf, 1);
|
||||
} while (len < 0 && errno == EINTR);
|
||||
NS_WARN_IF_FALSE(len >= 0, "WAIT_FOR_FB_SLEEP failed");
|
||||
}
|
||||
sEnabledCallback(false);
|
||||
|
||||
{
|
||||
mozilla::ScopedClose fd(open(kWakeFile, O_RDONLY, 0));
|
||||
do {
|
||||
len = read(fd.get(), &buf, 1);
|
||||
} while (len < 0 && errno == EINTR);
|
||||
NS_WARN_IF_FALSE(len >= 0, "WAIT_FOR_FB_WAKE failed");
|
||||
}
|
||||
sEnabledCallback(true);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static GonkDisplayICS* sGonkDisplay = nullptr;
|
||||
|
||||
static int
|
||||
FramebufferNativeWindowCancelBufferNoop(ANativeWindow* aWindow,
|
||||
android_native_buffer_t* aBuffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GonkDisplayICS::GonkDisplayICS()
|
||||
: mModule(nullptr)
|
||||
, mHwc(nullptr)
|
||||
{
|
||||
// Some gralloc HALs need this in order to open the
|
||||
// framebuffer device after we restart with the screen off.
|
||||
//
|
||||
// this *must* run BEFORE allocating the
|
||||
// FramebufferNativeWindow.
|
||||
set_screen_state(1);
|
||||
|
||||
// For some devices, it takes a while for the framebuffer to become
|
||||
// usable. So we wait until the framebuffer has woken up before we
|
||||
// try to open it.
|
||||
{
|
||||
char buf;
|
||||
int len = 0;
|
||||
ScopedClose fd(open("/sys/power/wait_for_fb_wake", O_RDONLY, 0));
|
||||
do {
|
||||
len = read(fd.get(), &buf, 1);
|
||||
} while (len < 0 && errno == EINTR);
|
||||
if (len < 0) {
|
||||
LOGE("wait_for_fb_sleep failed errno: %d", errno);
|
||||
}
|
||||
}
|
||||
|
||||
mFBSurface = new FramebufferNativeWindow();
|
||||
|
||||
// ICS FramebufferNativeWindow doesn't set the |cancelBuffer|
|
||||
// function pointer.
|
||||
// It will crash when deleting the EGL window surface.
|
||||
if (!mFBSurface->cancelBuffer) {
|
||||
mFBSurface->cancelBuffer = FramebufferNativeWindowCancelBufferNoop;
|
||||
}
|
||||
|
||||
int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule);
|
||||
LOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID);
|
||||
if (!err) {
|
||||
err = hwc_open(mModule, &mHwc);
|
||||
LOGE_IF(err, "%s device failed to initialize (%s)",
|
||||
HWC_HARDWARE_COMPOSER, strerror(-err));
|
||||
}
|
||||
|
||||
xdpi = mFBSurface->xdpi;
|
||||
|
||||
const framebuffer_device_t *fbdev = mFBSurface->getDevice();
|
||||
surfaceformat = fbdev->format;
|
||||
}
|
||||
|
||||
GonkDisplayICS::~GonkDisplayICS()
|
||||
{
|
||||
if (mHwc)
|
||||
hwc_close(mHwc);
|
||||
}
|
||||
|
||||
void
|
||||
GonkDisplayICS::SetEnabled(bool enabled)
|
||||
{
|
||||
set_screen_state(enabled);
|
||||
}
|
||||
|
||||
void
|
||||
GonkDisplayICS::OnEnabled(OnEnabledCallbackType callback)
|
||||
{
|
||||
if (sEnabledCallback)
|
||||
return;
|
||||
sEnabledCallback = callback;
|
||||
|
||||
// Watching screen on/off state by using a pthread
|
||||
// which implicitly calls exit() when the main thread ends
|
||||
if (pthread_create(&sFramebufferWatchThread, NULL, frameBufferWatcher, NULL)) {
|
||||
NS_RUNTIMEABORT("Failed to create framebufferWatcherThread, aborting...");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void*
|
||||
GonkDisplayICS::GetHWCDevice()
|
||||
{
|
||||
return mHwc;
|
||||
}
|
||||
|
||||
bool
|
||||
GonkDisplayICS::SwapBuffers(EGLDisplay dpy, EGLSurface sur)
|
||||
{
|
||||
// Should be called when composition rendering is complete for a frame.
|
||||
// Only HWC v1.0 needs this call. ICS gonk always needs the call.
|
||||
mFBSurface->compositionComplete();
|
||||
|
||||
if (!mHwc) {
|
||||
if (sur != EGL_NO_SURFACE) {
|
||||
return eglSwapBuffers(dpy, sur);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
mHwc->prepare(mHwc, nullptr);
|
||||
return !mHwc->set(mHwc, dpy, sur, 0);
|
||||
}
|
||||
|
||||
ANativeWindowBuffer*
|
||||
GonkDisplayICS::DequeueBuffer()
|
||||
{
|
||||
ANativeWindow *window = static_cast<ANativeWindow *>(mFBSurface.get());
|
||||
ANativeWindowBuffer *buf = nullptr;
|
||||
window->dequeueBuffer(window, &buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool
|
||||
GonkDisplayICS::QueueBuffer(ANativeWindowBuffer *buf)
|
||||
{
|
||||
ANativeWindow *window = static_cast<ANativeWindow *>(mFBSurface.get());
|
||||
return !window->queueBuffer(window, buf);
|
||||
}
|
||||
|
||||
void
|
||||
GonkDisplayICS::UpdateDispSurface(EGLDisplay dpy, EGLSurface sur)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
GonkDisplayICS::SetDispReleaseFd(int fd)
|
||||
{
|
||||
}
|
||||
|
||||
GonkDisplay::NativeData
|
||||
GonkDisplayICS::GetNativeData(GonkDisplay::DisplayType aDisplayType,
|
||||
android::IGraphicBufferProducer* aSink)
|
||||
{
|
||||
MOZ_ASSERT(aDisplayType == DISPLAY_PRIMARY, "ICS gonk supports primary display only.");
|
||||
|
||||
NativeData data;
|
||||
data.mNativeWindow = static_cast<ANativeWindow *>(mFBSurface.get());
|
||||
data.mXdpi = xdpi;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
__attribute__ ((visibility ("default")))
|
||||
GonkDisplay*
|
||||
GetGonkDisplay()
|
||||
{
|
||||
if (!sGonkDisplay)
|
||||
sGonkDisplay = new GonkDisplayICS();
|
||||
return sGonkDisplay;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -1,72 +0,0 @@
|
|||
/* Copyright 2013 Mozilla Foundation and Mozilla contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GONKDISPLAYICS_H
|
||||
#define GONKDISPLAYICS_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "GonkDisplay.h"
|
||||
#include "ui/FramebufferNativeWindow.h"
|
||||
#include "hardware/hwcomposer.h"
|
||||
#include "utils/RefBase.h"
|
||||
|
||||
namespace android {
|
||||
class IGraphicBufferProducer;
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class MOZ_EXPORT GonkDisplayICS : public GonkDisplay {
|
||||
public:
|
||||
GonkDisplayICS();
|
||||
~GonkDisplayICS();
|
||||
|
||||
virtual void SetEnabled(bool enabled);
|
||||
|
||||
virtual void OnEnabled(OnEnabledCallbackType callback);
|
||||
|
||||
virtual void* GetHWCDevice();
|
||||
|
||||
virtual bool SwapBuffers(EGLDisplay dpy, EGLSurface sur);
|
||||
|
||||
virtual ANativeWindowBuffer* DequeueBuffer();
|
||||
|
||||
virtual bool QueueBuffer(ANativeWindowBuffer* handle);
|
||||
|
||||
virtual void UpdateDispSurface(EGLDisplay dpy, EGLSurface sur);
|
||||
|
||||
virtual void SetDispReleaseFd(int fd);
|
||||
|
||||
virtual int GetPrevDispAcquireFd()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual NativeData GetNativeData(
|
||||
GonkDisplay::DisplayType aDisplayType,
|
||||
android::IGraphicBufferProducer* aSink = nullptr);
|
||||
|
||||
virtual void NotifyBootAnimationStopped() {}
|
||||
|
||||
private:
|
||||
hw_module_t const* mModule;
|
||||
hwc_composer_device_t* mHwc;
|
||||
android::sp<android::FramebufferNativeWindow> mFBSurface;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* GONKDISPLAYICS_H */
|
|
@ -35,10 +35,6 @@ elif CONFIG['ANDROID_VERSION'] == '17':
|
|||
'GonkDisplayJB.cpp',
|
||||
'GraphicBufferAlloc.cpp',
|
||||
]
|
||||
elif CONFIG['ANDROID_VERSION'] == '15':
|
||||
SOURCES += [
|
||||
'GonkDisplayICS.cpp'
|
||||
]
|
||||
elif CONFIG['ANDROID_VERSION'] and CONFIG['COMPILE_ENVIRONMENT']:
|
||||
error('Unsupported platform version: %s' % (CONFIG['ANDROID_VERSION']))
|
||||
|
||||
|
@ -52,18 +48,12 @@ DEFINES['XPCOM_GLUE'] = True
|
|||
|
||||
DISABLE_STL_WRAPPING = True
|
||||
|
||||
if CONFIG['ANDROID_VERSION'] > '15':
|
||||
LOCAL_INCLUDES += [
|
||||
'%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
|
||||
'frameworks/native/include/gui',
|
||||
'frameworks/native/opengl/include',
|
||||
'system/core/libsuspend/include',
|
||||
]
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
|
||||
'frameworks/native/include/gui',
|
||||
'frameworks/native/opengl/include',
|
||||
'hardware/libhardware/include',
|
||||
'hardware/libhardware_legacy/include',
|
||||
'system/core/libsuspend/include',
|
||||
]
|
||||
]
|
||||
|
|
|
@ -50,10 +50,6 @@ if CONFIG['ANDROID_VERSION'] >= '17':
|
|||
SOURCES += [
|
||||
'hwchal/HwcHAL.cpp',
|
||||
]
|
||||
elif CONFIG['ANDROID_VERSION'] == '15':
|
||||
SOURCES += [
|
||||
'hwchal/HwcICS.cpp',
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
'GeckoTouchDispatcher.cpp',
|
||||
|
@ -89,20 +85,14 @@ LOCAL_INCLUDES += [
|
|||
|
||||
DEFINES['HAVE_OFF64_T'] = True
|
||||
DEFINES['SK_BUILD_FOR_ANDROID_NDK'] = True
|
||||
|
||||
if CONFIG['ANDROID_VERSION'] != '15':
|
||||
DEFINES['HAVE_POSIX_CLOCKS'] = True
|
||||
DEFINES['HAVE_POSIX_CLOCKS'] = True
|
||||
|
||||
if CONFIG['MOZ_OMX_DECODER']:
|
||||
DEFINES['MOZ_OMX_DECODER'] = True
|
||||
|
||||
if CONFIG['ANDROID_VERSION'] > '15':
|
||||
LOCAL_INCLUDES += [
|
||||
'%' + '%s/frameworks/native/opengl/include' % CONFIG['ANDROID_SOURCE'],
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
|
||||
'frameworks/native/opengl/include',
|
||||
'hardware/libhardware/include',
|
||||
'hardware/libhardware_legacy/include',
|
||||
]
|
||||
|
|
|
@ -19,6 +19,4 @@
|
|||
# include "GonkNativeWindowKK.h"
|
||||
#elif defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
|
||||
# include "GonkNativeWindowJB.h"
|
||||
#elif defined(MOZ_WIDGET_GONK) && ANDROID_VERSION == 15
|
||||
# include "GonkNativeWindowICS.h"
|
||||
#endif
|
||||
|
|
|
@ -1,673 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
* Copyright (C) 2012-2013 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "mozilla/layers/GrallocTextureClient.h"
|
||||
#include "mozilla/layers/ImageBridgeChild.h"
|
||||
#include "mozilla/layers/ShadowLayers.h"
|
||||
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
|
||||
#include "GonkNativeWindow.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
/**
|
||||
* DOM_CAMERA_LOGI() is enabled in debug builds, and turned on by setting
|
||||
* MOZ_LOG=Camera:N environment variable, where N >= 3.
|
||||
*
|
||||
* CNW_LOGE() is always enabled.
|
||||
*/
|
||||
#define CNW_LOGD(...) DOM_CAMERA_LOGI(__VA_ARGS__)
|
||||
#define CNW_LOGE(...) {(void)printf_stderr(__VA_ARGS__);}
|
||||
|
||||
using namespace android;
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::layers;
|
||||
|
||||
GonkNativeWindow::GonkNativeWindow() :
|
||||
mAbandoned(false),
|
||||
mDefaultWidth(1),
|
||||
mDefaultHeight(1),
|
||||
mPixelFormat(PIXEL_FORMAT_RGBA_8888),
|
||||
mBufferCount(MIN_BUFFER_SLOTS + 1),
|
||||
mConnectedApi(NO_CONNECTED_API),
|
||||
mFrameCounter(0),
|
||||
mNewFrameCallback(nullptr) {
|
||||
}
|
||||
|
||||
GonkNativeWindow::~GonkNativeWindow() {
|
||||
freeAllBuffersLocked();
|
||||
}
|
||||
|
||||
void GonkNativeWindow::abandon()
|
||||
{
|
||||
CNW_LOGD("abandon");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mQueue.clear();
|
||||
mAbandoned = true;
|
||||
freeAllBuffersLocked();
|
||||
mDequeueCondition.signal();
|
||||
}
|
||||
|
||||
void GonkNativeWindow::freeAllBuffersLocked()
|
||||
{
|
||||
CNW_LOGD("freeAllBuffersLocked");
|
||||
|
||||
for (int i = 0; i < NUM_BUFFER_SLOTS; ++i) {
|
||||
if (mSlots[i].mGraphicBuffer != NULL) {
|
||||
if (mSlots[i].mTextureClient) {
|
||||
mSlots[i].mTextureClient->ClearRecycleCallback();
|
||||
// release TextureClient in ImageBridge thread
|
||||
RefPtr<TextureClientReleaseTask> task =
|
||||
MakeAndAddRef<TextureClientReleaseTask>(mSlots[i].mTextureClient);
|
||||
mSlots[i].mTextureClient = NULL;
|
||||
ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
|
||||
}
|
||||
mSlots[i].mGraphicBuffer = NULL;
|
||||
mSlots[i].mBufferState = BufferSlot::FREE;
|
||||
mSlots[i].mFrameNumber = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GonkNativeWindow::clearRenderingStateBuffersLocked()
|
||||
{
|
||||
CNW_LOGD("clearRenderingStateBuffersLocked");
|
||||
|
||||
for (int i = 0; i < NUM_BUFFER_SLOTS; ++i) {
|
||||
if (mSlots[i].mGraphicBuffer != NULL) {
|
||||
// Clear RENDERING state buffer
|
||||
if (mSlots[i].mBufferState == BufferSlot::RENDERING) {
|
||||
if (mSlots[i].mTextureClient) {
|
||||
mSlots[i].mTextureClient->ClearRecycleCallback();
|
||||
// release TextureClient in ImageBridge thread
|
||||
RefPtr<TextureClientReleaseTask> task =
|
||||
MakeAndAddRef<TextureClientReleaseTask>(mSlots[i].mTextureClient);
|
||||
mSlots[i].mTextureClient = NULL;
|
||||
ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
|
||||
}
|
||||
mSlots[i].mGraphicBuffer = NULL;
|
||||
mSlots[i].mBufferState = BufferSlot::FREE;
|
||||
mSlots[i].mFrameNumber = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::setBufferCount(int bufferCount)
|
||||
{
|
||||
CNW_LOGD("setBufferCount: count=%d", bufferCount);
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
if (mAbandoned) {
|
||||
CNW_LOGE("setBufferCount: GonkNativeWindow has been abandoned!");
|
||||
return NO_INIT;
|
||||
}
|
||||
|
||||
if (bufferCount > NUM_BUFFER_SLOTS) {
|
||||
CNW_LOGE("setBufferCount: bufferCount larger than slots available");
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
if (bufferCount < MIN_BUFFER_SLOTS) {
|
||||
CNW_LOGE("setBufferCount: requested buffer count (%d) is less than "
|
||||
"minimum (%d)", bufferCount, MIN_BUFFER_SLOTS);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
// Error out if the user has dequeued buffers.
|
||||
for (int i=0 ; i<mBufferCount ; i++) {
|
||||
if (mSlots[i].mBufferState == BufferSlot::DEQUEUED) {
|
||||
CNW_LOGE("setBufferCount: client owns some buffers");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (bufferCount >= mBufferCount) {
|
||||
mBufferCount = bufferCount;
|
||||
//clear only buffers in RENDERING state.
|
||||
clearRenderingStateBuffersLocked();
|
||||
mQueue.clear();
|
||||
mDequeueCondition.signal();
|
||||
return OK;
|
||||
}
|
||||
|
||||
// here we're guaranteed that the client doesn't have dequeued buffers
|
||||
// and will release all of its buffer references.
|
||||
freeAllBuffersLocked();
|
||||
mBufferCount = bufferCount;
|
||||
mQueue.clear();
|
||||
mDequeueCondition.signal();
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::setDefaultBufferSize(uint32_t w, uint32_t h)
|
||||
{
|
||||
CNW_LOGD("setDefaultBufferSize: w=%d, h=%d", w, h);
|
||||
if (!w || !h) {
|
||||
CNW_LOGE("setDefaultBufferSize: dimensions cannot be 0 (w=%d, h=%d)",
|
||||
w, h);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mDefaultWidth = w;
|
||||
mDefaultHeight = h;
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::requestBuffer(int slot, sp<GraphicBuffer>* buf)
|
||||
{
|
||||
CNW_LOGD("requestBuffer: slot=%d", slot);
|
||||
Mutex::Autolock lock(mMutex);
|
||||
if (mAbandoned) {
|
||||
CNW_LOGE("requestBuffer: GonkNativeWindow has been abandoned!");
|
||||
return NO_INIT;
|
||||
}
|
||||
if (slot < 0 || mBufferCount <= slot) {
|
||||
CNW_LOGE("requestBuffer: slot index out of range [0, %d]: %d",
|
||||
mBufferCount, slot);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
mSlots[slot].mRequestBufferCalled = true;
|
||||
*buf = mSlots[slot].mGraphicBuffer;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
|
||||
uint32_t format, uint32_t usage)
|
||||
{
|
||||
if ((w && !h) || (!w && h)) {
|
||||
CNW_LOGE("dequeueBuffer: invalid size: w=%u, h=%u", w, h);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
status_t returnFlags(OK);
|
||||
bool updateFormat = false;
|
||||
bool alloc = false;
|
||||
int buf = INVALID_BUFFER_SLOT;
|
||||
|
||||
{
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
int found = -1;
|
||||
int dequeuedCount = 0;
|
||||
int renderingCount = 0;
|
||||
bool tryAgain = true;
|
||||
|
||||
CNW_LOGD("dequeueBuffer: E");
|
||||
while (tryAgain) {
|
||||
if (mAbandoned) {
|
||||
CNW_LOGE("dequeueBuffer: GonkNativeWindow has been abandoned!");
|
||||
return NO_INIT;
|
||||
}
|
||||
// look for a free buffer to give to the client
|
||||
found = INVALID_BUFFER_SLOT;
|
||||
dequeuedCount = 0;
|
||||
renderingCount = 0;
|
||||
for (int i = 0; i < mBufferCount; i++) {
|
||||
const int state = mSlots[i].mBufferState;
|
||||
switch (state) {
|
||||
case BufferSlot::DEQUEUED:
|
||||
CNW_LOGD("dequeueBuffer: slot %d is DEQUEUED\n", i);
|
||||
dequeuedCount++;
|
||||
break;
|
||||
|
||||
case BufferSlot::RENDERING:
|
||||
CNW_LOGD("dequeueBuffer: slot %d is RENDERING\n", i);
|
||||
renderingCount++;
|
||||
break;
|
||||
|
||||
case BufferSlot::FREE:
|
||||
CNW_LOGD("dequeueBuffer: slot %d is FREE\n", i);
|
||||
/* We return the oldest of the free buffers to avoid
|
||||
* stalling the producer if possible. This is because
|
||||
* the consumer may still have pending reads of the
|
||||
* buffers in flight.
|
||||
*/
|
||||
if (found < 0 ||
|
||||
mSlots[i].mFrameNumber < mSlots[found].mFrameNumber) {
|
||||
found = i;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
CNW_LOGD("dequeueBuffer: slot %d is %d\n", i, state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// See whether a buffer has been in RENDERING state since the last
|
||||
// setBufferCount so we know whether to perform the
|
||||
// MIN_UNDEQUEUED_BUFFERS check below.
|
||||
if (renderingCount > 0) {
|
||||
// make sure the client is not trying to dequeue more buffers
|
||||
// than allowed.
|
||||
const int avail = mBufferCount - (dequeuedCount + 1);
|
||||
if (avail < MIN_UNDEQUEUED_BUFFERS) {
|
||||
CNW_LOGE("dequeueBuffer: MIN_UNDEQUEUED_BUFFERS=%d exceeded "
|
||||
"(dequeued=%d)",
|
||||
MIN_UNDEQUEUED_BUFFERS,
|
||||
dequeuedCount);
|
||||
return -EBUSY;
|
||||
}
|
||||
}
|
||||
|
||||
// we're in synchronous mode and didn't find a buffer, we need to
|
||||
// wait for some buffers to be consumed
|
||||
tryAgain = (found == INVALID_BUFFER_SLOT);
|
||||
if (tryAgain) {
|
||||
CNW_LOGD("dequeueBuffer: Try again");
|
||||
mDequeueCondition.wait(mMutex);
|
||||
CNW_LOGD("dequeueBuffer: Now");
|
||||
}
|
||||
}
|
||||
|
||||
if (found == INVALID_BUFFER_SLOT) {
|
||||
// This should not happen.
|
||||
CNW_LOGE("dequeueBuffer: no available buffer slots");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
buf = found;
|
||||
*outBuf = found;
|
||||
|
||||
const bool useDefaultSize = !w && !h;
|
||||
if (useDefaultSize) {
|
||||
// use the default size
|
||||
w = mDefaultWidth;
|
||||
h = mDefaultHeight;
|
||||
}
|
||||
|
||||
updateFormat = (format != 0);
|
||||
if (!updateFormat) {
|
||||
// keep the current (or default) format
|
||||
format = mPixelFormat;
|
||||
}
|
||||
|
||||
mSlots[buf].mBufferState = BufferSlot::DEQUEUED;
|
||||
|
||||
const sp<GraphicBuffer>& gbuf(mSlots[buf].mGraphicBuffer);
|
||||
if ((gbuf == NULL) ||
|
||||
((uint32_t(gbuf->width) != w) ||
|
||||
(uint32_t(gbuf->height) != h) ||
|
||||
(uint32_t(gbuf->format) != format) ||
|
||||
((uint32_t(gbuf->usage) & usage) != usage))) {
|
||||
mSlots[buf].mGraphicBuffer = NULL;
|
||||
mSlots[buf].mRequestBufferCalled = false;
|
||||
if (mSlots[buf].mTextureClient) {
|
||||
mSlots[buf].mTextureClient->ClearRecycleCallback();
|
||||
// release TextureClient in ImageBridge thread
|
||||
RefPtr<TextureClientReleaseTask> task =
|
||||
MakeAndAddRef<TextureClientReleaseTask>(mSlots[buf].mTextureClient);
|
||||
mSlots[buf].mTextureClient = NULL;
|
||||
ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(task.forget());
|
||||
}
|
||||
alloc = true;
|
||||
}
|
||||
} // end lock scope
|
||||
|
||||
if (alloc) {
|
||||
ClientIPCAllocator* allocator = ImageBridgeChild::GetSingleton();
|
||||
usage |= GraphicBuffer::USAGE_HW_TEXTURE;
|
||||
GrallocTextureData* texData = GrallocTextureData::Create(IntSize(w, h), format,
|
||||
gfx::BackendType::NONE, usage,
|
||||
allocator);
|
||||
if (!texData) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
RefPtr<TextureClient> textureClient = new TextureClient(texData, TextureFlags::RECYCLE | TextureFlags::DEALLOCATE_CLIENT, allocator);
|
||||
|
||||
{ // Scope for the lock
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
if (mAbandoned) {
|
||||
CNW_LOGE("dequeueBuffer: SurfaceTexture has been abandoned!");
|
||||
return NO_INIT;
|
||||
}
|
||||
|
||||
if (updateFormat) {
|
||||
mPixelFormat = format;
|
||||
}
|
||||
mSlots[buf].mGraphicBuffer = texData->GetGraphicBuffer();
|
||||
mSlots[buf].mTextureClient = textureClient;
|
||||
|
||||
returnFlags |= ISurfaceTexture::BUFFER_NEEDS_REALLOCATION;
|
||||
|
||||
CNW_LOGD("dequeueBuffer: returning slot=%d buf=%p ", buf,
|
||||
mSlots[buf].mGraphicBuffer->handle);
|
||||
}
|
||||
}
|
||||
|
||||
CNW_LOGD("dequeueBuffer: returning slot=%d buf=%p ", buf,
|
||||
mSlots[buf].mGraphicBuffer->handle );
|
||||
|
||||
CNW_LOGD("dequeueBuffer: X");
|
||||
return returnFlags;
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::setSynchronousMode(bool enabled)
|
||||
{
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int GonkNativeWindow::getSlotFromBufferLocked(
|
||||
android_native_buffer_t* buffer) const
|
||||
{
|
||||
if (buffer == NULL) {
|
||||
CNW_LOGE("getSlotFromBufferLocked: encountered NULL buffer");
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
|
||||
if (mSlots[i].mGraphicBuffer != NULL && mSlots[i].mGraphicBuffer->handle == buffer->handle) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
CNW_LOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
int GonkNativeWindow::getSlotFromTextureClientLocked(
|
||||
TextureClient* client) const
|
||||
{
|
||||
if (client == NULL) {
|
||||
CNW_LOGE("getSlotFromBufferLocked: encountered NULL buffer");
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
|
||||
if (mSlots[i].mTextureClient == client) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
CNW_LOGE("getSlotFromBufferLocked: unknown TextureClient: %p", client);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
already_AddRefed<TextureClient>
|
||||
GonkNativeWindow::getTextureClientFromBuffer(ANativeWindowBuffer* buffer)
|
||||
{
|
||||
int buf = getSlotFromBufferLocked(buffer);
|
||||
if (buf < 0 || buf >= mBufferCount ||
|
||||
mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<TextureClient> client(mSlots[buf].mTextureClient);
|
||||
return client.forget();
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::queueBuffer(int buf, int64_t timestamp,
|
||||
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform)
|
||||
{
|
||||
{
|
||||
Mutex::Autolock lock(mMutex);
|
||||
CNW_LOGD("queueBuffer: E");
|
||||
CNW_LOGD("queueBuffer: buf=%d", buf);
|
||||
|
||||
if (mAbandoned) {
|
||||
CNW_LOGE("queueBuffer: GonkNativeWindow has been abandoned!");
|
||||
return NO_INIT;
|
||||
}
|
||||
if (buf < 0 || buf >= mBufferCount) {
|
||||
CNW_LOGE("queueBuffer: slot index out of range [0, %d]: %d",
|
||||
mBufferCount, buf);
|
||||
return -EINVAL;
|
||||
} else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
|
||||
CNW_LOGE("queueBuffer: slot %d is not owned by the client "
|
||||
"(state=%d)", buf, mSlots[buf].mBufferState);
|
||||
return -EINVAL;
|
||||
} else if (!mSlots[buf].mRequestBufferCalled) {
|
||||
CNW_LOGE("queueBuffer: slot %d was enqueued without requesting a "
|
||||
"buffer", buf);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mQueue.push_back(buf);
|
||||
|
||||
mSlots[buf].mBufferState = BufferSlot::QUEUED;
|
||||
mSlots[buf].mTimestamp = timestamp;
|
||||
mFrameCounter++;
|
||||
mSlots[buf].mFrameNumber = mFrameCounter;
|
||||
|
||||
mDequeueCondition.signal();
|
||||
|
||||
*outWidth = mDefaultWidth;
|
||||
*outHeight = mDefaultHeight;
|
||||
*outTransform = 0;
|
||||
}
|
||||
|
||||
// OnNewFrame might call lockCurrentBuffer so we must release the
|
||||
// mutex first.
|
||||
if (mNewFrameCallback) {
|
||||
mNewFrameCallback->OnNewFrame();
|
||||
}
|
||||
CNW_LOGD("queueBuffer: X");
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
already_AddRefed<TextureClient>
|
||||
GonkNativeWindow::getCurrentBuffer() {
|
||||
CNW_LOGD("GonkNativeWindow::getCurrentBuffer");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
if (mAbandoned) {
|
||||
CNW_LOGE("getCurrentBuffer: GonkNativeWindow has been abandoned!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(mQueue.empty()) {
|
||||
mDequeueCondition.signal();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Fifo::iterator front(mQueue.begin());
|
||||
int buf = *front;
|
||||
CNW_LOGD("getCurrentBuffer: buf=%d", buf);
|
||||
|
||||
mSlots[buf].mBufferState = BufferSlot::RENDERING;
|
||||
|
||||
mQueue.erase(front);
|
||||
mDequeueCondition.signal();
|
||||
|
||||
mSlots[buf].mTextureClient->SetRecycleCallback(GonkNativeWindow::RecycleCallback, this);
|
||||
RefPtr<TextureClient> client(mSlots[buf].mTextureClient);
|
||||
return client.forget();
|
||||
}
|
||||
|
||||
|
||||
/* static */ void
|
||||
GonkNativeWindow::RecycleCallback(TextureClient* client, void* closure) {
|
||||
GonkNativeWindow* nativeWindow =
|
||||
static_cast<GonkNativeWindow*>(closure);
|
||||
|
||||
MOZ_ASSERT(client && !client->IsDead());
|
||||
client->ClearRecycleCallback();
|
||||
nativeWindow->returnBuffer(client);
|
||||
}
|
||||
|
||||
void GonkNativeWindow::returnBuffer(TextureClient* client) {
|
||||
CNW_LOGD("GonkNativeWindow::returnBuffer");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
if (mAbandoned) {
|
||||
CNW_LOGD("returnBuffer: GonkNativeWindow has been abandoned!");
|
||||
return;
|
||||
}
|
||||
|
||||
int index = getSlotFromTextureClientLocked(client);
|
||||
if (index < 0 || index >= mBufferCount) {
|
||||
CNW_LOGE("returnBuffer: slot index out of range [0, %d]: %d",
|
||||
mBufferCount, index);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSlots[index].mBufferState != BufferSlot::RENDERING) {
|
||||
CNW_LOGE("returnBuffer: slot %d is not owned by the compositor (state=%d)",
|
||||
index, mSlots[index].mBufferState);
|
||||
return;
|
||||
}
|
||||
|
||||
mSlots[index].mBufferState = BufferSlot::FREE;
|
||||
mDequeueCondition.signal();
|
||||
return;
|
||||
}
|
||||
|
||||
void GonkNativeWindow::cancelBuffer(int buf) {
|
||||
CNW_LOGD("cancelBuffer: slot=%d", buf);
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
if (mAbandoned) {
|
||||
CNW_LOGD("cancelBuffer: GonkNativeWindow has been abandoned!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (buf < 0 || buf >= mBufferCount) {
|
||||
CNW_LOGE("cancelBuffer: slot index out of range [0, %d]: %d",
|
||||
mBufferCount, buf);
|
||||
return;
|
||||
} else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
|
||||
CNW_LOGE("cancelBuffer: slot %d is not owned by the client (state=%d)",
|
||||
buf, mSlots[buf].mBufferState);
|
||||
return;
|
||||
}
|
||||
mSlots[buf].mBufferState = BufferSlot::FREE;
|
||||
mSlots[buf].mFrameNumber = 0;
|
||||
mDequeueCondition.signal();
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::setCrop(const Rect& crop) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::setTransform(uint32_t transform) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::connect(int api,
|
||||
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
|
||||
CNW_LOGD("connect: api=%d", api);
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
if (mAbandoned) {
|
||||
CNW_LOGE("connect: GonkNativeWindow has been abandoned!");
|
||||
return NO_INIT;
|
||||
}
|
||||
|
||||
int err = NO_ERROR;
|
||||
switch (api) {
|
||||
case NATIVE_WINDOW_API_EGL:
|
||||
case NATIVE_WINDOW_API_CPU:
|
||||
case NATIVE_WINDOW_API_MEDIA:
|
||||
case NATIVE_WINDOW_API_CAMERA:
|
||||
if (mConnectedApi != NO_CONNECTED_API) {
|
||||
CNW_LOGE("connect: already connected (cur=%d, req=%d)",
|
||||
mConnectedApi, api);
|
||||
err = -EINVAL;
|
||||
} else {
|
||||
mConnectedApi = api;
|
||||
*outWidth = mDefaultWidth;
|
||||
*outHeight = mDefaultHeight;
|
||||
*outTransform = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
err = -EINVAL;
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::disconnect(int api) {
|
||||
CNW_LOGD("disconnect: api=%d", api);
|
||||
|
||||
int err = NO_ERROR;
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
if (mAbandoned) {
|
||||
// it is not really an error to disconnect after the surface
|
||||
// has been abandoned, it should just be a no-op.
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
switch (api) {
|
||||
case NATIVE_WINDOW_API_EGL:
|
||||
case NATIVE_WINDOW_API_CPU:
|
||||
case NATIVE_WINDOW_API_MEDIA:
|
||||
case NATIVE_WINDOW_API_CAMERA:
|
||||
if (mConnectedApi == api) {
|
||||
mQueue.clear();
|
||||
freeAllBuffersLocked();
|
||||
mConnectedApi = NO_CONNECTED_API;
|
||||
mDequeueCondition.signal();
|
||||
} else {
|
||||
CNW_LOGE("disconnect: connected to another api (cur=%d, req=%d)",
|
||||
mConnectedApi, api);
|
||||
err = -EINVAL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
CNW_LOGE("disconnect: unknown API %d", api);
|
||||
err = -EINVAL;
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
status_t GonkNativeWindow::setScalingMode(int mode) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
void GonkNativeWindow::setNewFrameCallback(
|
||||
GonkNativeWindowNewFrameCallback* aCallback) {
|
||||
CNW_LOGD("setNewFrameCallback");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mNewFrameCallback = aCallback;
|
||||
}
|
||||
|
||||
int GonkNativeWindow::query(int what, int* outValue)
|
||||
{
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
if (mAbandoned) {
|
||||
CNW_LOGE("query: GonkNativeWindow has been abandoned!");
|
||||
return NO_INIT;
|
||||
}
|
||||
|
||||
int value;
|
||||
switch (what) {
|
||||
case NATIVE_WINDOW_WIDTH:
|
||||
value = mDefaultWidth;
|
||||
break;
|
||||
case NATIVE_WINDOW_HEIGHT:
|
||||
value = mDefaultHeight;
|
||||
break;
|
||||
case NATIVE_WINDOW_FORMAT:
|
||||
value = mPixelFormat;
|
||||
break;
|
||||
case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
|
||||
value = MIN_UNDEQUEUED_BUFFERS;
|
||||
break;
|
||||
default:
|
||||
return BAD_VALUE;
|
||||
}
|
||||
outValue[0] = value;
|
||||
return NO_ERROR;
|
||||
}
|
|
@ -1,296 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
* Copyright (C) 2012 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NATIVEWINDOW_GONKNATIVEWINDOW_ICS_H
|
||||
#define NATIVEWINDOW_GONKNATIVEWINDOW_ICS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <gui/ISurfaceTexture.h>
|
||||
#include <ui/egl/android_natives.h>
|
||||
#include <ui/GraphicBuffer.h>
|
||||
#include <ui/Rect.h>
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/threads.h>
|
||||
|
||||
#include "CameraCommon.h"
|
||||
#include "GrallocImages.h"
|
||||
#include "mozilla/layers/LayersSurfaces.h"
|
||||
#include "mozilla/layers/TextureClient.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
// The user of GonkNativeWindow who wants to receive notification of
|
||||
// new frames should implement this interface.
|
||||
class GonkNativeWindowNewFrameCallback {
|
||||
public:
|
||||
virtual void OnNewFrame() = 0;
|
||||
};
|
||||
|
||||
class GonkNativeWindow : public BnSurfaceTexture
|
||||
{
|
||||
friend class GonkNativeWindowClient;
|
||||
|
||||
typedef mozilla::layers::TextureClient TextureClient;
|
||||
|
||||
public:
|
||||
enum { MIN_UNDEQUEUED_BUFFERS = 2 };
|
||||
enum { MIN_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS };
|
||||
enum { NUM_BUFFER_SLOTS = 32 };
|
||||
enum { NO_CONNECTED_API = 0 };
|
||||
enum { NATIVE_WINDOW_SET_BUFFERS_SIZE = 0x10000000 };
|
||||
|
||||
GonkNativeWindow();
|
||||
~GonkNativeWindow(); // this class cannot be overloaded
|
||||
|
||||
// Get next frame from the queue and mark it as RENDERING, caller
|
||||
// owns the returned buffer.
|
||||
already_AddRefed<TextureClient> getCurrentBuffer();
|
||||
|
||||
// Return the buffer to the queue and mark it as FREE. After that
|
||||
// the buffer is useable again for the decoder.
|
||||
void returnBuffer(TextureClient* client);
|
||||
|
||||
// setBufferCount updates the number of available buffer slots. After
|
||||
// calling this all buffer slots are owned by the GonkNativeWindow object
|
||||
// (i.e. they are not owned by the client).
|
||||
virtual status_t setBufferCount(int bufferCount);
|
||||
|
||||
// requestBuffer requests a new buffer for the given index.
|
||||
virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
|
||||
|
||||
// dequeueBuffer gets the next buffer slot index for the client to use. If a
|
||||
// buffer slot is available then that slot index is written to the location
|
||||
// pointed to by the buf argument and a status of OK is returned. If no
|
||||
// slot is available then a status of -EBUSY is returned and buf is
|
||||
// unmodified.
|
||||
virtual status_t dequeueBuffer(int *buf, uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t usage);
|
||||
|
||||
// queueBuffer returns a filled buffer to the GonkNativeWindow. In addition,
|
||||
// a timestamp must be provided for the buffer. The timestamp is in
|
||||
// nanoseconds, and must be monotonically increasing. Its other semantics
|
||||
// (zero point, etc) are client-dependent and should be documented by the
|
||||
// client.
|
||||
virtual status_t queueBuffer(int buf, int64_t timestamp,
|
||||
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
|
||||
virtual void cancelBuffer(int buf);
|
||||
virtual status_t setCrop(const Rect& reg);
|
||||
virtual status_t setTransform(uint32_t transform);
|
||||
virtual status_t setScalingMode(int mode);
|
||||
|
||||
virtual int query(int what, int* value);
|
||||
|
||||
// Qcom specific function
|
||||
virtual int performQcomOperation(int operation, int arg1, int arg2, int arg3) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
// GonkNativeWindow do not implement the function and always works in
|
||||
// synchronous mode.
|
||||
virtual status_t setSynchronousMode(bool enabled);
|
||||
|
||||
// connect attempts to connect a client API to the GonkNativeWindow.
|
||||
//
|
||||
// This method will fail if the connect was previously called on the
|
||||
// GonkNativeWindow and no corresponding disconnect call was made.
|
||||
virtual status_t connect(int api,
|
||||
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
|
||||
|
||||
// disconnect attempts to disconnect a client API from the GonkNativeWindow.
|
||||
// This method will fail if the the GonkNativeWindow is not currently
|
||||
// connected to the specified client API.
|
||||
virtual status_t disconnect(int api);
|
||||
|
||||
void setNewFrameCallback(GonkNativeWindowNewFrameCallback* aCallback);
|
||||
|
||||
// setDefaultBufferSize is used to set the size of buffers returned by
|
||||
// requestBuffers when a with and height of zero is requested.
|
||||
// A call to setDefaultBufferSize() may trigger requestBuffers() to
|
||||
// be called from the client.
|
||||
status_t setDefaultBufferSize(uint32_t width, uint32_t height);
|
||||
|
||||
// abandon frees all the buffers and puts the GonkNativeWindow into the
|
||||
// 'abandoned' state. Once put in this state the GonkNativeWindow can never
|
||||
// leave it. When in the 'abandoned' state, all methods of the
|
||||
// ISurfaceTexture interface will fail with the NO_INIT error.
|
||||
//
|
||||
// Note that while calling this method causes all the buffers to be freed
|
||||
// from the perspective of the the GonkNativeWindow, if there are additional
|
||||
// references on the buffers (e.g. if a buffer is referenced by a client)
|
||||
// then those buffer will remain allocated.
|
||||
void abandon();
|
||||
|
||||
already_AddRefed<TextureClient> getTextureClientFromBuffer(ANativeWindowBuffer* buffer);
|
||||
|
||||
static void RecycleCallback(TextureClient* client, void* closure);
|
||||
|
||||
protected:
|
||||
|
||||
// freeAllBuffersLocked frees the resources (both GraphicBuffer and
|
||||
// EGLImage) for all slots by removing them from the slots and appending
|
||||
// then to the freeList. This must be called with mMutex locked.
|
||||
void freeAllBuffersLocked();
|
||||
|
||||
// clearRenderingStateBuffersLocked clear the resources in RENDERING state;
|
||||
// But do not destroy the gralloc buffer. It is still in the video stream
|
||||
// awaiting rendering.
|
||||
// this must be called with mMutex locked.
|
||||
void clearRenderingStateBuffersLocked();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
|
||||
|
||||
int getSlotFromTextureClientLocked(TextureClient* client) const;
|
||||
|
||||
enum { INVALID_BUFFER_SLOT = -1 };
|
||||
|
||||
struct BufferSlot {
|
||||
|
||||
BufferSlot()
|
||||
: mBufferState(BufferSlot::FREE),
|
||||
mTimestamp(0),
|
||||
mFrameNumber(0){
|
||||
}
|
||||
|
||||
// mGraphicBuffer points to the buffer allocated for this slot or is NULL
|
||||
// if no buffer has been allocated.
|
||||
sp<GraphicBuffer> mGraphicBuffer;
|
||||
|
||||
// mTextureClient is a thin abstraction over remotely allocated GraphicBuffer.
|
||||
RefPtr<TextureClient> mTextureClient;
|
||||
|
||||
// BufferState represents the different states in which a buffer slot
|
||||
// can be.
|
||||
enum BufferState {
|
||||
// FREE indicates that the buffer is not currently being used and
|
||||
// will not be used in the future until it gets dequeued and
|
||||
// subsequently queued by the client.
|
||||
FREE = 0,
|
||||
|
||||
// DEQUEUED indicates that the buffer has been dequeued by the
|
||||
// client, but has not yet been queued or canceled. The buffer is
|
||||
// considered 'owned' by the client, and the server should not use
|
||||
// it for anything.
|
||||
//
|
||||
// Note that when in synchronous-mode (mSynchronousMode == true),
|
||||
// the buffer that's currently attached to the texture may be
|
||||
// dequeued by the client. That means that the current buffer can
|
||||
// be in either the DEQUEUED or QUEUED state. In asynchronous mode,
|
||||
// however, the current buffer is always in the QUEUED state.
|
||||
DEQUEUED = 1,
|
||||
|
||||
// QUEUED indicates that the buffer has been queued by the client,
|
||||
// and has not since been made available for the client to dequeue.
|
||||
// Attaching the buffer to the texture does NOT transition the
|
||||
// buffer away from the QUEUED state. However, in Synchronous mode
|
||||
// the current buffer may be dequeued by the client under some
|
||||
// circumstances. See the note about the current buffer in the
|
||||
// documentation for DEQUEUED.
|
||||
QUEUED = 2,
|
||||
|
||||
// RENDERING indicates that the buffer has been sent to
|
||||
// the compositor, and has not yet available for the
|
||||
// client to dequeue. When the compositor has finished its
|
||||
// job, the buffer will be returned to FREE state.
|
||||
RENDERING = 3,
|
||||
};
|
||||
|
||||
// mBufferState is the current state of this buffer slot.
|
||||
BufferState mBufferState;
|
||||
|
||||
// mRequestBufferCalled is used for validating that the client did
|
||||
// call requestBuffer() when told to do so. Technically this is not
|
||||
// needed but useful for debugging and catching client bugs.
|
||||
bool mRequestBufferCalled;
|
||||
|
||||
// mTimestamp is the current timestamp for this buffer slot. This gets
|
||||
// to set by queueBuffer each time this slot is queued.
|
||||
int64_t mTimestamp;
|
||||
|
||||
// mFrameNumber is the number of the queued frame for this slot.
|
||||
uint64_t mFrameNumber;
|
||||
};
|
||||
|
||||
// mSlots is the array of buffer slots that must be mirrored on the client
|
||||
// side. This allows buffer ownership to be transferred between the client
|
||||
// and server without sending a GraphicBuffer over binder. The entire array
|
||||
// is initialized to NULL at construction time, and buffers are allocated
|
||||
// for a slot when requestBuffer is called with that slot's index.
|
||||
BufferSlot mSlots[NUM_BUFFER_SLOTS];
|
||||
|
||||
// mDequeueCondition condition used for dequeueBuffer in synchronous mode
|
||||
mutable Condition mDequeueCondition;
|
||||
|
||||
// mAbandoned indicates that the GonkNativeWindow will no longer be used to
|
||||
// consume buffers pushed to it.
|
||||
// It is initialized to false, and set to true in the abandon method. A
|
||||
// GonkNativeWindow that has been abandoned will return the NO_INIT error
|
||||
// from all control methods capable of returning an error.
|
||||
bool mAbandoned;
|
||||
|
||||
// mTimestamp is the timestamp that will be used for the next buffer queue
|
||||
// operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
|
||||
// a timestamp is auto-generated when queueBuffer is called.
|
||||
int64_t mTimestamp;
|
||||
|
||||
// mDefaultWidth holds the default width of allocated buffers. It is used
|
||||
// in requestBuffers() if a width and height of zero is specified.
|
||||
uint32_t mDefaultWidth;
|
||||
|
||||
// mDefaultHeight holds the default height of allocated buffers. It is used
|
||||
// in requestBuffers() if a width and height of zero is specified.
|
||||
uint32_t mDefaultHeight;
|
||||
|
||||
// mPixelFormat holds the pixel format of allocated buffers. It is used
|
||||
// in requestBuffers() if a format of zero is specified.
|
||||
uint32_t mPixelFormat;
|
||||
|
||||
// mBufferCount is the number of buffer slots that the client and server
|
||||
// must maintain. It defaults to MIN_BUFFER_SLOTS + 1 and can be changed
|
||||
// by calling setBufferCount or setBufferCountServer
|
||||
int mBufferCount;
|
||||
|
||||
// mConnectedApi indicates the API that is currently connected to this
|
||||
// GonkNativeWindow. It defaults to NO_CONNECTED_API (= 0), and gets updated
|
||||
// by the connect and disconnect methods.
|
||||
int mConnectedApi;
|
||||
|
||||
// mQueue is a FIFO of queued buffers used in synchronous mode
|
||||
// GonkNativeWindow always works in synchronous mode
|
||||
typedef Vector<int> Fifo;
|
||||
Fifo mQueue;
|
||||
|
||||
// mMutex is the mutex used to prevent concurrent access to the member
|
||||
// variables of GonkNativeWindow objects. It must be locked whenever the
|
||||
// member variables are accessed.
|
||||
mutable Mutex mMutex;
|
||||
|
||||
// mFrameCounter is the free running counter, incremented for every buffer queued
|
||||
uint64_t mFrameCounter;
|
||||
|
||||
GonkNativeWindowNewFrameCallback* mNewFrameCallback;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // NATIVEWINDOW_GONKNATIVEWINDOW_ICS_H
|
|
@ -47,10 +47,6 @@ elif CONFIG['ANDROID_VERSION'] in ('17', '18'):
|
|||
'GonkConsumerBaseJB.h',
|
||||
'GonkNativeWindowJB.h',
|
||||
]
|
||||
elif CONFIG['ANDROID_VERSION'] == '15':
|
||||
EXPORTS += [
|
||||
'GonkNativeWindowICS.h',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_B2G_CAMERA'] or CONFIG['MOZ_OMX_DECODER'] or CONFIG['MOZ_WEBRTC']:
|
||||
if CONFIG['ANDROID_VERSION'] >= '21':
|
||||
|
@ -78,10 +74,6 @@ if CONFIG['MOZ_B2G_CAMERA'] or CONFIG['MOZ_OMX_DECODER'] or CONFIG['MOZ_WEBRTC']
|
|||
'GonkConsumerBaseJB.cpp',
|
||||
'GonkNativeWindowJB.cpp',
|
||||
]
|
||||
elif CONFIG['ANDROID_VERSION'] == '15':
|
||||
SOURCES += [
|
||||
'GonkNativeWindowICS.cpp',
|
||||
]
|
||||
|
||||
if CONFIG['ANDROID_VERSION'] >= '18':
|
||||
SOURCES += [
|
||||
|
|
Загрузка…
Ссылка в новой задаче