Merge last green changeset from inbound to mozilla-central

This commit is contained in:
Matt Brubeck 2012-01-19 10:37:48 -08:00
commit f26465597e
395 changed files with 16682 additions and 6194 deletions

View File

@ -281,7 +281,7 @@ pref("browser.urlbar.doubleClickSelectsAll", true);
#else
pref("browser.urlbar.doubleClickSelectsAll", false);
#endif
pref("browser.urlbar.autoFill", false);
pref("browser.urlbar.autoFill", true);
// 0: Match anywhere (e.g., middle of words)
// 1: Match on word boundaries and then try matching anywhere
// 2: Match only on word boundaries (e.g., after / or .)
@ -294,7 +294,7 @@ pref("browser.urlbar.maxRichResults", 12);
// The amount of time (ms) to wait after the user has stopped typing
// before starting to perform autocomplete. 50 is the default set in
// autocomplete.xml.
pref("browser.urlbar.delay", 50);
pref("browser.urlbar.delay", 0);
// The special characters below can be typed into the urlbar to either restrict
// the search to visited history, bookmarked, tagged pages; or force a match on

View File

@ -502,7 +502,7 @@
<textbox id="urlbar" flex="1"
placeholder="&urlbar.placeholder;"
type="autocomplete"
autocompletesearch="history"
autocompletesearch="urlinline history"
autocompletesearchparam="enable-actions"
autocompletepopup="PopupAutoCompleteRichResult"
completeselectedindex="true"

View File

@ -69,7 +69,7 @@
<hbox align="center">
<textbox id="dialog.input" flex="1" type="autocomplete"
completeselectedindex="true"
autocompletesearch="history"
autocompletesearch="urlinline history"
enablehistory="true"
class="uri-element"
oninput="doEnabling();"/>

View File

@ -215,6 +215,7 @@ _BROWSER_FILES = \
browser_tabfocus.js \
browser_tabs_isActive.js \
browser_tabs_owner.js \
browser_urlbarAutoFillTrimURLs.js \
browser_urlbarCopying.js \
browser_urlbarEnter.js \
browser_urlbarTrimURLs.js \

View File

@ -0,0 +1,85 @@
/* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/. */
// This test ensures that autoFilled values are not trimmed, unless the user
// selects from the autocomplete popup.
function test() {
waitForExplicitFinish();
const PREF_TRIMURL = "browser.urlbar.trimURLs";
const PREF_AUTOFILL = "browser.urlbar.autoFill";
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PREF_TRIMURL);
Services.prefs.clearUserPref(PREF_AUTOFILL);
URLBarSetURI();
});
Services.prefs.setBoolPref(PREF_TRIMURL, true);
Services.prefs.setBoolPref(PREF_AUTOFILL, true);
// Adding a tab would hit switch-to-tab, so it's safer to just add a visit.
let callback = {
handleError: function () {},
handleResult: function () {},
handleCompletion: continue_test
};
let history = Cc["@mozilla.org/browser/history;1"]
.getService(Ci.mozIAsyncHistory);
history.updatePlaces({ uri: NetUtil.newURI("http://www.autofilltrimurl.com/")
, visits: [ { transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED
, visitDate: Date.now() * 1000
} ]
}, callback);
}
function continue_test() {
function test_autoFill(aTyped, aExpected, aCallback) {
gURLBar.inputField.value = aTyped.substr(0, aTyped.length - 1);
gURLBar.focus();
gURLBar.selectionStart = aTyped.length - 1;
gURLBar.selectionEnd = aTyped.length - 1;
EventUtils.synthesizeKey(aTyped.substr(-1), {});
is(gURLBar.value, aExpected, "trim was applied correctly");
aCallback();
}
test_autoFill("http://", "http://", function () {
test_autoFill("http://a", "http://autofilltrimurl.com/", function () {
test_autoFill("http://www.autofilltrimurl.com", "http://www.autofilltrimurl.com/", function () {
// Now ensure selecting from the popup correctly trims.
waitForSearchComplete(function () {
EventUtils.synthesizeKey("VK_DOWN", {});
is(gURLBar.value, "www.autofilltrimurl.com", "trim was applied correctly");
gURLBar.closePopup();
waitForClearHistory(finish);
});
});
});
});
}
function waitForClearHistory(aCallback) {
Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) {
Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
aCallback();
}, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
PlacesUtils.bhistory.removeAllPages();
}
function waitForSearchComplete(aCallback) {
info("Waiting for onSearchComplete");
let onSearchComplete = gURLBar.onSearchComplete;
registerCleanupFunction(function () {
gURLBar.onSearchComplete = onSearchComplete;
});
gURLBar.onSearchComplete = function () {
ok(gURLBar.popupOpen, "The autocomplete popup is correctly open");
is(gURLBar.controller.matchCount, 1, "Found the expected number of matches")
onSearchComplete.apply(gURLBar);
aCallback();
}
}

View File

@ -667,7 +667,13 @@
try {
val = losslessDecodeURI(makeURI(val));
} catch (ex) { }
// Trim popup selected values, but never trim results coming from
// autofill.
if (this.popup.selectedIndex == -1)
this._disableTrim = true;
this.value = val;
this._disableTrim = false;
// Completing a result should simulate the user typing the result, so
// fire an input event.

View File

@ -38,6 +38,8 @@
#
# ***** END LICENSE BLOCK *****
Components.utils.import("resource://gre/modules/Services.jsm");
const Ci = Components.interfaces;
const Cc = Components.classes;
@ -51,22 +53,23 @@ var gEngineManagerDialog = {
init: function engineManager_init() {
gEngineView = new EngineView(new EngineStore());
var prefService = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
var suggestEnabled = prefService.getBoolPref(BROWSER_SUGGEST_PREF);
var suggestEnabled = Services.prefs.getBoolPref(BROWSER_SUGGEST_PREF);
document.getElementById("enableSuggest").checked = suggestEnabled;
var tree = document.getElementById("engineList");
tree.view = gEngineView;
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.addObserver(this, "browser-search-engine-modified", false);
Services.obs.addObserver(this, "browser-search-engine-modified", false);
},
destroy: function engineManager_destroy() {
// Remove the observer
Services.obs.removeObserver(this, "browser-search-engine-modified");
},
observe: function engineManager_observe(aEngine, aTopic, aVerb) {
if (aTopic == "browser-search-engine-modified") {
aEngine.QueryInterface(Ci.nsISearchEngine)
aEngine.QueryInterface(Ci.nsISearchEngine);
switch (aVerb) {
case "engine-added":
gEngineView._engineStore.addEngine(aEngine);
@ -74,38 +77,24 @@ var gEngineManagerDialog = {
break;
case "engine-changed":
gEngineView._engineStore.reloadIcons();
gEngineView.invalidate();
break;
case "engine-removed":
case "engine-current":
// Not relevant
return;
break;
}
gEngineView.invalidate();
}
},
onOK: function engineManager_onOK() {
// Remove the observer
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.removeObserver(this, "browser-search-engine-modified");
// Set the preference
var newSuggestEnabled = document.getElementById("enableSuggest").checked;
var prefService = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
prefService.setBoolPref(BROWSER_SUGGEST_PREF, newSuggestEnabled);
Services.prefs.setBoolPref(BROWSER_SUGGEST_PREF, newSuggestEnabled);
// Commit the changes
gEngineView._engineStore.commit();
},
onCancel: function engineManager_onCancel() {
// Remove the observer
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.removeObserver(this, "browser-search-engine-modified");
},
onRestoreDefaults: function engineManager_onRestoreDefaults() {
var num = gEngineView._engineStore.restoreDefaultEngines();
@ -129,7 +118,7 @@ var gEngineManagerDialog = {
gEngineView.rowCountChanged(index, -1);
gEngineView.invalidate();
gEngineView.selection.select(Math.min(index, gEngineView.lastIndex));
gEngineView.ensureRowIsVisible(Math.min(index, gEngineView.lastIndex));
gEngineView.ensureRowIsVisible(gEngineView.currentIndex);
document.getElementById("engineList").focus();
},
@ -156,14 +145,12 @@ var gEngineManagerDialog = {
if (!selectedEngine)
return;
var prompt = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService);
var alias = { value: selectedEngine.alias };
var strings = document.getElementById("engineManagerBundle");
var title = strings.getString("editTitle");
var msg = strings.getFormattedString("editMsg", [selectedEngine.name]);
while (prompt.prompt(window, title, msg, alias, null, { })) {
while (Services.prompt.prompt(window, title, msg, alias, null, {})) {
var bduplicate = false;
var eduplicate = false;
@ -178,7 +165,7 @@ var gEngineManagerDialog = {
// Check for duplicates in changes we haven't committed yet
let engines = gEngineView._engineStore.engines;
for each (let engine in engines) {
if (engine.alias == alias.value &&
if (engine.alias == alias.value &&
engine.name != selectedEngine.name) {
eduplicate = true;
break;
@ -193,7 +180,7 @@ var gEngineManagerDialog = {
var emsg = strings.getFormattedString("duplicateEngineMsg",
[engine.name]);
prompt.alert(window, dtitle, (eduplicate) ? emsg : bmsg);
Services.prompt.alert(window, dtitle, eduplicate ? emsg : bmsg);
} else {
gEngineView._engineStore.changeEngine(selectedEngine, "alias",
alias.value);
@ -204,23 +191,24 @@ var gEngineManagerDialog = {
},
onSelect: function engineManager_onSelect() {
// buttons only work if an engine is selected and it's not the last engine
var disableButtons = (gEngineView.selectedIndex == -1) ||
(gEngineView.lastIndex == 0);
// Buttons only work if an engine is selected and it's not the last engine,
// the latter is true when the selected is first and last at the same time.
var lastSelected = (gEngineView.selectedIndex == gEngineView.lastIndex);
var firstSelected = (gEngineView.selectedIndex == 0);
var noSelection = (gEngineView.selectedIndex == -1);
document.getElementById("cmd_remove").setAttribute("disabled",
disableButtons);
document.getElementById("cmd_remove")
.setAttribute("disabled", noSelection ||
(firstSelected && lastSelected));
document.getElementById("cmd_moveup").setAttribute("disabled",
disableButtons || firstSelected);
document.getElementById("cmd_moveup")
.setAttribute("disabled", noSelection || firstSelected);
document.getElementById("cmd_movedown").setAttribute("disabled",
disableButtons || lastSelected);
document.getElementById("cmd_editkeyword").setAttribute("disabled",
noSelection);
document.getElementById("cmd_movedown")
.setAttribute("disabled", noSelection || lastSelected);
document.getElementById("cmd_editkeyword")
.setAttribute("disabled", noSelection);
}
};
@ -243,9 +231,7 @@ EngineMoveOp.prototype = {
_engine: null,
_newIndex: null,
commit: function EMO_commit() {
var searchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
searchService.moveEngine(this._engine, this._newIndex);
Services.search.moveEngine(this._engine, this._newIndex);
}
}
@ -257,9 +243,7 @@ function EngineRemoveOp(aEngineClone) {
EngineRemoveOp.prototype = {
_engine: null,
commit: function ERO_commit() {
var searchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
searchService.removeEngine(this._engine);
Services.search.removeEngine(this._engine);
}
}
@ -274,9 +258,7 @@ EngineUnhideOp.prototype = {
_newIndex: null,
commit: function EUO_commit() {
this._engine.hidden = false;
var searchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
searchService.moveEngine(this._engine, this._newIndex);
Services.search.moveEngine(this._engine, this._newIndex);
}
}
@ -298,10 +280,8 @@ EngineChangeOp.prototype = {
}
function EngineStore() {
var searchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
this._engines = searchService.getVisibleEngines().map(this._cloneEngine);
this._defaultEngines = searchService.getDefaultEngines().map(this._cloneEngine);
this._engines = Services.search.getVisibleEngines().map(this._cloneEngine);
this._defaultEngines = Services.search.getDefaultEngines().map(this._cloneEngine);
this._ops = [];
@ -334,12 +314,12 @@ EngineStore.prototype = {
return null;
},
_cloneEngine: function ES_cloneObj(aEngine) {
var newO=[];
_cloneEngine: function ES_cloneEngine(aEngine) {
var clonedObj={};
for (var i in aEngine)
newO[i] = aEngine[i];
newO.originalEngine = aEngine;
return newO;
clonedObj[i] = aEngine[i];
clonedObj.originalEngine = aEngine;
return clonedObj;
},
// Callback for Array's some(). A thisObj must be passed to some()
@ -348,9 +328,7 @@ EngineStore.prototype = {
},
commit: function ES_commit() {
var searchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
var currentEngine = this._cloneEngine(searchService.currentEngine);
var currentEngine = this._cloneEngine(Services.search.currentEngine);
for (var i = 0; i < this._ops.length; i++)
this._ops[i].commit();
@ -358,7 +336,7 @@ EngineStore.prototype = {
// Needed if the user deletes currentEngine and then restores it.
if (this._defaultEngines.some(this._isSameEngine, currentEngine) &&
!currentEngine.originalEngine.hidden)
searchService.currentEngine = currentEngine.originalEngine;
Services.search.currentEngine = currentEngine.originalEngine;
},
addEngine: function ES_addEngine(aEngine) {
@ -386,7 +364,7 @@ EngineStore.prototype = {
var index = this._getIndexForEngine(aEngine);
if (index == -1)
throw new Error("invalid engine?");
this._engines.splice(index, 1);
this._ops.push(new EngineRemoveOp(aEngine));
if (this._defaultEngines.some(this._isSameEngine, aEngine))
@ -442,8 +420,8 @@ EngineView.prototype = {
get selectedIndex() {
var seln = this.selection;
if (seln.getRangeCount() > 0) {
var min = { };
seln.getRangeAt(0, min, { });
var min = {};
seln.getRangeAt(0, min, {});
return min.value;
}
return -1;
@ -496,7 +474,7 @@ EngineView.prototype = {
var sourceIndex = this.getSourceIndexFromDrag(dataTransfer);
return (sourceIndex != -1 &&
sourceIndex != targetIndex &&
sourceIndex != (targetIndex + orientation));
sourceIndex != targetIndex + orientation);
},
drop: function(dropIndex, orientation, dataTransfer) {
@ -508,7 +486,7 @@ EngineView.prototype = {
dropIndex--;
} else {
if (orientation == Ci.nsITreeView.DROP_AFTER)
dropIndex++;
dropIndex++;
}
this._engineStore.moveEngine(sourceEngine, dropIndex);
@ -516,7 +494,6 @@ EngineView.prototype = {
// Redraw, and adjust selection
this.invalidate();
this.selection.clearSelection();
this.selection.select(dropIndex);
},

View File

@ -48,8 +48,8 @@
buttonlabelextra2="&restoreDefaults.label;"
buttonaccesskeyextra2="&restoreDefaults.accesskey;"
onload="gEngineManagerDialog.init();"
onunload="gEngineManagerDialog.destroy();"
ondialogaccept="gEngineManagerDialog.onOK();"
ondialogcancel="gEngineManagerDialog.onCancel();"
ondialogextra2="gEngineManagerDialog.onRestoreDefaults();"
title="&engineManager.title;"
style="&engineManager.style;"
@ -88,7 +88,7 @@
<tree id="engineList" flex="1" rows="10" hidecolumnpicker="true"
seltype="single" onselect="gEngineManagerDialog.onSelect();">
<treechildren id="engineChildren" flex="1"
ondragstart="onDragEngineStart(event)"/>
ondragstart="onDragEngineStart(event);"/>
<treecols>
<treecol id="engineName" flex="4" label="&columnLabel.name;"/>
<treecol id="engineKeyword" flex="1" label="&columnLabel.keyword;"/>
@ -104,7 +104,7 @@
label="&up.label;"
accesskey="&up.accesskey;"
command="cmd_moveup"/>
<button id="dn"
<button id="down"
label="&dn.label;"
accesskey="&dn.accesskey;"
command="cmd_movedown"/>
@ -119,11 +119,9 @@
<checkbox id="enableSuggest"
label="&enableSuggest.label;"
accesskey="&enableSuggest.accesskey;"/>
<spacer flex="1"/>
</hbox>
<hbox>
<label id="addEngines" class="text-link" value="&addEngine.label;"
onclick="if (event.button == 0) { gEngineManagerDialog.loadAddEngines(); }"/>
<spacer flex="1"/>
</hbox>
</dialog>

View File

@ -223,7 +223,6 @@
@BINPATH@/components/prefetch.xpt
@BINPATH@/components/profile.xpt
@BINPATH@/components/profiler.xpt
@BINPATH@/components/proxyObject.xpt
@BINPATH@/components/rdf.xpt
@BINPATH@/components/satchel.xpt
@BINPATH@/components/saxparser.xpt

View File

@ -45,5 +45,5 @@
}
#engineList treechildren::-moz-tree-row {
height: 20px !important;
height: 20px;
}

View File

@ -45,5 +45,5 @@
}
#engineList treechildren::-moz-tree-row {
height: 20px !important;
height: 20px;
}

View File

@ -45,5 +45,5 @@
}
#engineList treechildren::-moz-tree-row {
height: 20px !important;
height: 20px;
}

View File

@ -104,6 +104,7 @@
#include "nsDOMFile.h"
#include "nsIFileChannel.h"
#include "mozilla/Telemetry.h"
#include "sampler.h"
using namespace mozilla;
@ -2017,6 +2018,7 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
NS_IMETHODIMP
nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult status)
{
SAMPLE_LABEL("content", "nsXMLHttpRequest::OnStopRequest");
if (!IsSameOrBaseChannel(request, mChannel)) {
return NS_OK;
}

View File

@ -21,21 +21,20 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=166235
<script type="application/javascript">
/** Test for Bug 166235 **/
var Cc = SpecialPowers.wrap(Components).classes;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var webnav = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
var webnav = SpecialPowers.wrap(window).QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
var docShell = webnav.QueryInterface(Components.interfaces.nsIDocShell);
var documentViewer = docShell.contentViewer
.QueryInterface(Components.interfaces.nsIContentViewerEdit);
var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
.getService(Components.interfaces.nsIClipboard);
var clipboard = Cc["@mozilla.org/widget/clipboard;1"]
.getService(Components.interfaces.nsIClipboard);
var textarea = document.getElementById('input');
var textarea = SpecialPowers.wrap(document).getElementById('input');
function copyChildrenToClipboard(id) {
textarea.blur();
@ -47,11 +46,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=166235
is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true);
}
function getClipboardData(mime) {
var transferable = Components.classes['@mozilla.org/widget/transferable;1']
.createInstance(Components.interfaces.nsITransferable);
var transferable = Cc['@mozilla.org/widget/transferable;1']
.createInstance(Components.interfaces.nsITransferable);
transferable.addDataFlavor(mime);
clipboard.getData(transferable, 1);
var data = {};
var data = SpecialPowers.wrap({});
transferable.getTransferData(mime, data, {}) ;
return data;
}

View File

@ -19,27 +19,25 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=375314
/** Test for Bug 375314 **/
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var lastContentType = -1;
const testURL = window.location.href + "/this/is/the/test/url";
const Cc = Components.classes;
const Cc = SpecialPowers.wrap(Components).classes;
const Ci = Components.interfaces;
// Content policy / factory implementation for the test
var policyID = Components.ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
var policyID = SpecialPowers.wrap(Components).ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
var policyName = "@mozilla.org/testpolicy;1";
var policy = {
// nsISupports implementation
QueryInterface: function(iid) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
iid = SpecialPowers.wrap(iid);
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIFactory) ||
iid.equals(Ci.nsIContentPolicy))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
throw SpecialPowers.wrap(Components).results.NS_ERROR_NO_INTERFACE;
},
// nsIFactory implementation
@ -49,10 +47,9 @@ var policy = {
// nsIContentPolicy implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// Remember last content type seen for the test url
if (contentLocation.spec == testURL) {
if (SpecialPowers.wrap(contentLocation).spec == testURL) {
lastContentType = contentType;
return Ci.nsIContentPolicy.REJECT_REQUEST;
}
@ -61,15 +58,15 @@ var policy = {
},
shouldProcess: function(contentType, contentLocation, requestOrigin, context, mimeTypeGuess, extra) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
return Ci.nsIContentPolicy.ACCEPT;
}
}
// Register content policy
var componentManager = Components.manager
.QueryInterface(Ci.nsIComponentRegistrar);
var componentManager = SpecialPowers.wrap(Components).manager
.QueryInterface(Ci.nsIComponentRegistrar);
componentManager.registerFactory(policyID, "Test content policy", policyName, policy);
var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
@ -85,7 +82,6 @@ SimpleTest.waitForExplicitFinish();
setTimeout(runNextTest, 0);
function runNextTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (curTest >= 0) {
var type = "TYPE_" + tests[curTest];
@ -113,7 +109,6 @@ function runNextTest() {
setTimeout(function() {
// Component must be unregistered delayed, otherwise other content
// policy will not be removed from the category correctly
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
componentManager.unregisterFactory(policyID, policy);
}, 0);

View File

@ -23,17 +23,17 @@ function loadFileContent(aFile, aCharset) {
if(aCharset == undefined)
aCharset = 'UTF-8';
var baseUri = Components.classes['@mozilla.org/network/standard-url;1']
var baseUri = SpecialPowers.wrap(Components).classes['@mozilla.org/network/standard-url;1']
.createInstance(Components.interfaces.nsIURI);
baseUri.spec = window.location.href;
var ios = Components.classes['@mozilla.org/network/io-service;1']
var ios = SpecialPowers.wrap(Components).classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
var chann = ios.newChannel(aFile, aCharset, baseUri);
var cis = Components.interfaces.nsIConverterInputStream;
var inputStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
var inputStream = SpecialPowers.wrap(Components).classes["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(cis);
inputStream.init(chann.open(), aCharset, 1024, cis.DEFAULT_REPLACEMENT_CHARACTER);
var str = {}, content = '';
@ -45,12 +45,11 @@ function loadFileContent(aFile, aCharset) {
function testHtmlSerializer_1 () {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const de = Components.interfaces.nsIDocumentEncoder
var encoder = Components.classes["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
var encoder = SpecialPowers.wrap(Components).classes["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
.createInstance(Components.interfaces.nsIDocumentEncoder);
var doc = $("testframe").contentDocument;
var doc = SpecialPowers.wrap($("testframe")).contentDocument;
var out, expected;
// in the following tests, we must use the OutputLFLineBreak flag, to avoid

View File

@ -224,6 +224,7 @@
#include "nsDOMNavigationTiming.h"
#include "nsITimedChannel.h"
#include "mozilla/StartupTimeline.h"
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
@ -1224,6 +1225,11 @@ nsDocShell::LoadURI(nsIURI * aURI,
NS_ENSURE_ARG(aURI);
if (!StartupTimeline::HasRecord(StartupTimeline::FIRST_LOAD_URI) &&
mItemType == typeContent && !NS_IsAboutBlank(aURI)) {
StartupTimeline::RecordOnce(StartupTimeline::FIRST_LOAD_URI);
}
// Extract the info from the DocShellLoadInfo struct...
if (aLoadInfo) {
aLoadInfo->GetReferrer(getter_AddRefs(referrer));

View File

@ -49,10 +49,15 @@
#include "skia/SkDashPathEffect.h"
#include "Logging.h"
#include "HelpersSkia.h"
#include "gfxImageSurface.h"
#include "Tools.h"
#include <algorithm>
#ifdef ANDROID
# define USE_SOFT_CLIPPING false
#else
# define USE_SOFT_CLIPPING true
#endif
namespace mozilla {
namespace gfx {
@ -65,8 +70,9 @@ SkColor ColorToSkColor(const Color &color, Float aAlpha)
class GradientStopsSkia : public GradientStops
{
public:
GradientStopsSkia(const std::vector<GradientStop>& aStops, uint32_t aNumStops)
GradientStopsSkia(const std::vector<GradientStop>& aStops, uint32_t aNumStops, ExtendMode aExtendMode)
: mCount(aNumStops)
, mExtendMode(aExtendMode)
{
if (mCount == 0) {
return;
@ -103,6 +109,7 @@ public:
std::vector<SkColor> mColors;
std::vector<SkScalar> mPositions;
int mCount;
ExtendMode mExtendMode;
};
SkXfermode::Mode
@ -208,12 +215,89 @@ ExtendModeToTileMode(ExtendMode aMode)
return SkShader::kClamp_TileMode;
}
void SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, Float aAlpha = 1.0)
{
switch (aPattern.GetType()) {
case PATTERN_COLOR: {
Color color = static_cast<const ColorPattern&>(aPattern).mColor;
aPaint.setColor(ColorToSkColor(color, aAlpha));
break;
}
case PATTERN_LINEAR_GRADIENT: {
const LinearGradientPattern& pat = static_cast<const LinearGradientPattern&>(aPattern);
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode);
if (stops->mCount >= 2) {
SkPoint points[2];
points[0] = SkPoint::Make(SkFloatToScalar(pat.mBegin.x), SkFloatToScalar(pat.mBegin.y));
points[1] = SkPoint::Make(SkFloatToScalar(pat.mEnd.x), SkFloatToScalar(pat.mEnd.y));
SkShader* shader = SkGradientShader::CreateLinear(points,
&stops->mColors.front(),
&stops->mPositions.front(),
stops->mCount,
mode);
SkMatrix mat;
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
shader->setLocalMatrix(mat);
SkSafeUnref(aPaint.setShader(shader));
} else {
aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
}
break;
}
case PATTERN_RADIAL_GRADIENT: {
const RadialGradientPattern& pat = static_cast<const RadialGradientPattern&>(aPattern);
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode);
if (stops->mCount >= 2) {
SkPoint points[2];
points[0] = SkPoint::Make(SkFloatToScalar(pat.mCenter1.x), SkFloatToScalar(pat.mCenter1.y));
points[1] = SkPoint::Make(SkFloatToScalar(pat.mCenter2.x), SkFloatToScalar(pat.mCenter2.y));
SkShader* shader = SkGradientShader::CreateTwoPointRadial(points[0],
SkFloatToScalar(pat.mRadius1),
points[1],
SkFloatToScalar(pat.mRadius2),
&stops->mColors.front(),
&stops->mPositions.front(),
stops->mCount,
mode);
SkMatrix mat;
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
shader->setLocalMatrix(mat);
SkSafeUnref(aPaint.setShader(shader));
} else {
aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
}
break;
}
case PATTERN_SURFACE: {
const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
const SkBitmap& bitmap = static_cast<SourceSurfaceSkia*>(pat.mSurface.get())->GetBitmap();
SkShader::TileMode mode = ExtendModeToTileMode(pat.mExtendMode);
SkShader* shader = SkShader::CreateBitmapShader(bitmap, mode, mode);
SkMatrix mat;
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
shader->setLocalMatrix(mat);
SkSafeUnref(aPaint.setShader(shader));
if (pat.mFilter == FILTER_POINT) {
aPaint.setFilterBitmap(false);
}
break;
}
}
}
struct AutoPaintSetup {
AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Pattern& aPattern)
: mNeedsRestore(false), mAlpha(1.0)
{
Init(aCanvas, aOptions);
SetPattern(aPattern);
SetPaintPattern(mPaint, aPattern, mAlpha);
}
AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions)
@ -261,60 +345,6 @@ struct AutoPaintSetup {
mPaint.setFilterBitmap(true);
}
void SetPattern(const Pattern& aPattern)
{
if (aPattern.GetType() == PATTERN_COLOR) {
Color color = static_cast<const ColorPattern&>(aPattern).mColor;
mPaint.setColor(ColorToSkColor(color, mAlpha));
} else if (aPattern.GetType() == PATTERN_LINEAR_GRADIENT) {
const LinearGradientPattern& pat = static_cast<const LinearGradientPattern&>(aPattern);
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
if (stops->mCount >= 2) {
SkPoint points[2];
points[0] = SkPoint::Make(SkFloatToScalar(pat.mBegin.x), SkFloatToScalar(pat.mBegin.y));
points[1] = SkPoint::Make(SkFloatToScalar(pat.mEnd.x), SkFloatToScalar(pat.mEnd.y));
SkShader* shader = SkGradientShader::CreateLinear(points,
&stops->mColors.front(),
&stops->mPositions.front(),
stops->mCount,
SkShader::kClamp_TileMode);
SkSafeUnref(mPaint.setShader(shader));
} else {
mPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
}
} else if (aPattern.GetType() == PATTERN_RADIAL_GRADIENT) {
const RadialGradientPattern& pat = static_cast<const RadialGradientPattern&>(aPattern);
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
if (stops->mCount >= 2) {
SkPoint points[2];
points[0] = SkPoint::Make(SkFloatToScalar(pat.mCenter1.x), SkFloatToScalar(pat.mCenter1.y));
points[1] = SkPoint::Make(SkFloatToScalar(pat.mCenter2.x), SkFloatToScalar(pat.mCenter2.y));
SkShader* shader = SkGradientShader::CreateTwoPointRadial(points[0],
SkFloatToScalar(pat.mRadius1),
points[1],
SkFloatToScalar(pat.mRadius2),
&stops->mColors.front(),
&stops->mPositions.front(),
stops->mCount,
SkShader::kClamp_TileMode);
SkSafeUnref(mPaint.setShader(shader));
} else {
mPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
}
} else {
const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
const SkBitmap& bitmap = static_cast<SourceSurfaceSkia*>(pat.mSurface.get())->GetBitmap();
SkShader::TileMode mode = ExtendModeToTileMode(pat.mExtendMode);
SkShader* shader = SkShader::CreateBitmapShader(bitmap, mode, mode);
SkSafeUnref(mPaint.setShader(shader));
}
}
// TODO: Maybe add an operator overload to access this easier?
SkPaint mPaint;
bool mNeedsRestore;
@ -542,6 +572,36 @@ DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
mCanvas->drawPosText(&indices.front(), aBuffer.mNumGlyphs*2, &offsets.front(), paint.mPaint);
}
void
DrawTargetSkia::Mask(const Pattern &aSource,
const Pattern &aMask,
const DrawOptions &aOptions)
{
MarkChanged();
AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
SkPaint maskPaint;
SetPaintPattern(maskPaint, aMask);
SkLayerRasterizer *raster = new SkLayerRasterizer();
raster->addLayer(maskPaint);
SkSafeUnref(paint.mPaint.setRasterizer(raster));
// Skia only uses the mask rasterizer when we are drawing a path/rect.
// Take our destination bounds and convert them into user space to use
// as the path to draw.
SkPath path;
path.addRect(SkRect::MakeWH(mSize.width, mSize.height));
Matrix temp = mTransform;
temp.Invert();
SkMatrix mat;
GfxMatrixToSkiaMatrix(temp, mat);
path.transform(mat);
mCanvas->drawPath(path, paint.mPaint);
}
TemporaryRef<SourceSurface>
DrawTargetSkia::CreateSourceSurfaceFromData(unsigned char *aData,
const IntSize &aSize,
@ -624,6 +684,21 @@ DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
return true;
}
void
DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat)
{
mBitmap.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride);
mBitmap.setPixels(aData);
SkAutoTUnref<SkDevice> device(new SkDevice(mBitmap));
SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get()));
mSize = aSize;
mDevice = device.get();
mCanvas = canvas.get();
mFormat = aFormat;
}
void
DrawTargetSkia::SetTransform(const Matrix& aTransform)
{
@ -646,7 +721,7 @@ DrawTargetSkia::ClearRect(const Rect &aRect)
MarkChanged();
SkPaint paint;
mCanvas->save();
mCanvas->clipRect(RectToSkRect(aRect), SkRegion::kIntersect_Op);
mCanvas->clipRect(RectToSkRect(aRect), SkRegion::kIntersect_Op, USE_SOFT_CLIPPING);
paint.setColor(SkColorSetARGB(0, 0, 0, 0));
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
mCanvas->drawPaint(paint);
@ -662,7 +737,16 @@ DrawTargetSkia::PushClip(const Path *aPath)
const PathSkia *skiaPath = static_cast<const PathSkia*>(aPath);
mCanvas->save(SkCanvas::kClip_SaveFlag);
mCanvas->clipPath(skiaPath->GetPath());
mCanvas->clipPath(skiaPath->GetPath(), SkRegion::kIntersect_Op, USE_SOFT_CLIPPING);
}
void
DrawTargetSkia::PushClipRect(const Rect& aRect)
{
SkRect rect = RectToSkRect(aRect);
mCanvas->save(SkCanvas::kClip_SaveFlag);
mCanvas->clipRect(rect, SkRegion::kIntersect_Op, USE_SOFT_CLIPPING);
}
void
@ -681,7 +765,7 @@ DrawTargetSkia::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, Ex
}
std::stable_sort(stops.begin(), stops.end());
return new GradientStopsSkia(stops, aNumStops);
return new GradientStopsSkia(stops, aNumStops, aExtendMode);
}
void

View File

@ -101,10 +101,9 @@ public:
const DrawOptions &aOptions = DrawOptions());
virtual void Mask(const Pattern &aSource,
const Pattern &aMask,
const DrawOptions &aOptions = DrawOptions())
{ return; }
const DrawOptions &aOptions = DrawOptions());
virtual void PushClip(const Path *aPath);
virtual void PushClipRect(const Rect &aRect) { }
virtual void PushClipRect(const Rect& aRect);
virtual void PopClip();
virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
const IntSize &aSize,
@ -120,6 +119,7 @@ public:
virtual void SetTransform(const Matrix &aTransform);
bool Init(const IntSize &aSize, SurfaceFormat aFormat);
void Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
operator std::string() const {
std::stringstream stream;
@ -138,7 +138,6 @@ private:
SkRefPtr<SkCanvas> mCanvas;
SkRefPtr<SkDevice> mDevice;
nsRefPtr<gfxImageSurface> mImageSurface;
SurfaceFormat mFormat;
vector<SourceSurfaceSkia*> mSnapshots;
};

View File

@ -74,14 +74,14 @@ SourceSurfaceSkia::InitFromData(unsigned char* aData,
int32_t aStride,
SurfaceFormat aFormat)
{
mBitmap.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride);
if (!mBitmap.allocPixels()) {
SkBitmap temp;
temp.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride);
temp.setPixels(aData);
if (!temp.copyTo(&mBitmap, GfxFormatToSkiaConfig(aFormat))) {
return false;
}
if (!mBitmap.copyPixelsFrom(aData, mBitmap.getSafeSize(), aStride)) {
return false;
}
mSize = aSize;
mFormat = aFormat;
mStride = aStride;

View File

@ -47,6 +47,7 @@
#include "gfxFailure.h"
#include "prenv.h"
#include "mozilla/Preferences.h"
#include "sampler.h"
namespace mozilla {
namespace gl {
@ -195,6 +196,7 @@ public:
bool SwapBuffers()
{
SAMPLE_LABEL("GLContext", "SwapBuffers");
[mContext flushBuffer];
return true;
}

View File

@ -64,6 +64,8 @@
#include "gfxCrashReporterUtils.h"
#include "sampler.h"
namespace mozilla {
namespace layers {
@ -758,6 +760,7 @@ LayerManagerOGL::BindAndDrawQuadWithTextureRect(LayerProgram *aProg,
void
LayerManagerOGL::Render()
{
SAMPLE_LABEL("LayerManagerOGL", "Render");
if (mDestroyed) {
NS_WARNING("Call on destroyed layer manager");
return;

View File

@ -308,9 +308,7 @@ endif
ifeq (android,$(MOZ_WIDGET_TOOLKIT))
CPPSRCS += \
SkFontHost_FreeType.cpp \
SkFontHost_android.cpp \
SkFontHost_gamma.cpp \
SkFontHost_none.cpp \
SkMMapStream.cpp \
SkTime_Unix.cpp \
$(NULL)
@ -326,6 +324,7 @@ EXPORTS_skia += \
$(NULL)
CPPSRCS += \
SkFontHost_win.cpp \
SkFontHost_sandbox_none.cpp \
SkTime_win.cpp \
$(NULL)
endif

5
gfx/skia/README_MOZILLA Normal file
View File

@ -0,0 +1,5 @@
The source from this directory was copied from the skia subversion trunk
using the update.sh script. The changes made were those applied by update.sh,
the addition/update of Makefile.in files for the Mozilla build system.
The subversion revision used was r2980.

View File

@ -1,7 +1,7 @@
diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/SkGradientShader.cpp
--- a/gfx/skia/src/effects/SkGradientShader.cpp
+++ b/gfx/skia/src/effects/SkGradientShader.cpp
@@ -165,16 +165,17 @@ private:
@@ -167,16 +167,17 @@ private:
mutable uint16_t* fCache16; // working ptr. If this is NULL, we need to recompute the cache values
mutable SkPMColor* fCache32; // working ptr. If this is NULL, we need to recompute the cache values
@ -15,11 +15,11 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,
U8CPU alpha);
void setCacheAlpha(U8CPU alpha) const;
void initCommon();
typedef SkShader INHERITED;
};
@@ -505,16 +506,31 @@ static inline U8CPU dither_fixed_to_8(Sk
@@ -512,16 +513,31 @@ static inline U8CPU dither_fixed_to_8(Sk
* For dithering with premultiply, we want to ceiling the alpha component,
* to ensure that it is always >= any color component.
*/
@ -51,7 +51,7 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
SkFixed a = SkMulDiv255Round(SkColorGetA(c0), paintAlpha);
SkFixed da;
{
@@ -606,24 +622,24 @@ const uint16_t* Gradient_Shader::getCach
@@ -613,24 +629,24 @@ const uint16_t* Gradient_Shader::getCach
}
}
return fCache16;
@ -78,7 +78,7 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
int prevIndex = 0;
for (int i = 1; i < fColorCount; i++) {
int nextIndex = SkFixedToFFFF(rec[i].fPos) >> (16 - kCache32Bits);
@@ -637,28 +653,31 @@ const SkPMColor* Gradient_Shader::getCac
@@ -644,28 +660,31 @@ const SkPMColor* Gradient_Shader::getCac
}
SkASSERT(prevIndex == kCache32Count - 1);
}
@ -112,7 +112,7 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
* over and over, we'd like to return exactly the same "bitmap" if possible,
* allowing the client to utilize a cache of our bitmap (e.g. with a GPU).
* To do that, we maintain a private cache of built-bitmaps, based on our
@@ -866,29 +885,37 @@ void Linear_Gradient::shadeSpan(int x, i
@@ -875,28 +894,38 @@ void Linear_Gradient::shadeSpan(int x, i
dx = dxStorage[0];
} else {
SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
@ -121,35 +121,36 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
if (SkFixedNearlyZero(dx)) {
// we're a vertical gradient, so no change in a span
- unsigned fi = proc(fx);
- SkASSERT(fi <= 0xFFFF);
- // TODO: dither version
- sk_memset32(dstC, cache[fi >> (16 - kCache32Bits)], count);
- unsigned fi = proc(fx) >> (16 - kCache32Bits);
- sk_memset32_dither(dstC, cache[toggle + fi],
- cache[(toggle ^ TOGGLE_MASK) + fi], count);
+ if (proc == clamp_tileproc) {
+ if (fx < 0) {
+ sk_memset32(dstC, cache[-1], count);
+ } else if (fx > 0xFFFF) {
+ sk_memset32(dstC, cache[kCache32Count * 2], count);
+ } else {
+ sk_memset32(dstC, cache[fx >> (16 - kCache32Bits)], count);
+ unsigned fi = proc(fx) >> (16 - kCache32Bits);
+ sk_memset32_dither(dstC, cache[toggle + fi],
+ cache[(toggle ^ TOGGLE_MASK) + fi], count);
+ }
+ } else {
+ unsigned fi = proc(fx);
+ SkASSERT(fi <= 0xFFFF);
+ // TODO: dither version
+ sk_memset32(dstC, cache[fi >> (16 - kCache32Bits)], count);
+ unsigned fi = proc(fx) >> (16 - kCache32Bits);
+ sk_memset32_dither(dstC, cache[toggle + fi],
+ cache[(toggle ^ TOGGLE_MASK) + fi], count);
+ }
} else if (proc == clamp_tileproc) {
SkClampRange range;
range.init(fx, dx, count, 0, 0xFF);
- range.init(fx, dx, count, 0, 0xFF);
+ range.init(fx, dx, count, cache[-1], cache[kCache32Count * 2]);
if ((count = range.fCount0) > 0) {
- sk_memset32_dither(dstC,
- cache[toggle + range.fV0],
- cache[(toggle ^ TOGGLE_MASK) + range.fV0],
- count);
+ // Do we really want to dither the clamp values?
+ sk_memset32(dstC, cache[-1], count);
+ // Do we really want to dither the clamp values?
+ sk_memset32(dstC, range.fV0, count);
dstC += count;
}
if ((count = range.fCount1) > 0) {
@ -158,7 +159,7 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
for (int i = 0; i < unroll; i++) {
NO_CHECK_ITER; NO_CHECK_ITER;
NO_CHECK_ITER; NO_CHECK_ITER;
@@ -897,20 +924,17 @@ void Linear_Gradient::shadeSpan(int x, i
@@ -905,20 +934,17 @@ void Linear_Gradient::shadeSpan(int x, i
}
if ((count &= 7) > 0) {
do {
@ -171,7 +172,7 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
- cache[toggle + range.fV1],
- cache[(toggle ^ TOGGLE_MASK) + range.fV1],
- count);
+ sk_memset32(dstC, cache[kCache32Count * 2], count);
+ sk_memset32(dstC, range.fV1, count);
}
} else if (proc == mirror_tileproc) {
do {
@ -180,7 +181,7 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
fx += dx;
*dstC++ = cache[toggle + fi];
toggle ^= TOGGLE_MASK;
@@ -1662,19 +1686,24 @@ public:
@@ -1670,19 +1699,24 @@ public:
}
SkScalar b = (SkScalarMul(fDiff.fX, fx) +
SkScalarMul(fDiff.fY, fy) - fStartRadius) * 2;
@ -208,17 +209,3 @@ diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/Sk
for (; count > 0; --count) {
SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, fOneOverTwoA, posRoot);
SkFixed index = mirror_tileproc(t);
diff --git a/gfx/skia/update.sh b/gfx/skia/update.sh
--- a/gfx/skia/update.sh
+++ b/gfx/skia/update.sh
@@ -90,9 +90,10 @@ if [ -n "$rev" ]; then
version=$rev
sed -i "" "s/r[0-9][0-9][0-9][0-9]/r$version/" README_MOZILLA
else
echo "Remember to update README_MOZILLA with the version details."
fi
# Patch to get arm opts to build with frame pointers enabled. Bug 689069
patch -p3 < arm-opts.patch
+patch -p3

View File

@ -0,0 +1,70 @@
diff --git a/gfx/skia/include/core/SkPaint.h b/gfx/skia/include/core/SkPaint.h
--- a/gfx/skia/include/core/SkPaint.h
+++ b/gfx/skia/include/core/SkPaint.h
@@ -836,16 +836,19 @@ public:
/** Return the path (outline) for the specified text.
Note: just like SkCanvas::drawText, this will respect the Align setting
in the paint.
*/
void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
SkPath* path) const;
+ void getPosTextPath(const void* text, size_t length,
+ const SkPoint pos[], SkPath* path) const;
+
#ifdef SK_BUILD_FOR_ANDROID
const SkGlyph& getUnicharMetrics(SkUnichar);
const void* findImage(const SkGlyph&);
uint32_t getGenerationID() const;
#endif
// returns true if the paint's settings (e.g. xfermode + alpha) resolve to
diff --git a/gfx/skia/src/core/SkPaint.cpp b/gfx/skia/src/core/SkPaint.cpp
--- a/gfx/skia/src/core/SkPaint.cpp
+++ b/gfx/skia/src/core/SkPaint.cpp
@@ -1242,16 +1242,43 @@ void SkPaint::getTextPath(const void* te
const SkPath* iterPath;
while ((iterPath = iter.next(&xpos)) != NULL) {
matrix.postTranslate(xpos - prevXPos, 0);
path->addPath(*iterPath, matrix);
prevXPos = xpos;
}
}
+void SkPaint::getPosTextPath(const void* textData, size_t length,
+ const SkPoint pos[], SkPath* path) const {
+ SkASSERT(length == 0 || textData != NULL);
+
+ const char* text = (const char*)textData;
+ if (text == NULL || length == 0 || path == NULL) {
+ return;
+ }
+
+ SkTextToPathIter iter(text, length, *this, false, true);
+ SkMatrix matrix;
+ SkPoint prevPos;
+ prevPos.set(0, 0);
+
+ matrix.setScale(iter.getPathScale(), iter.getPathScale());
+ path->reset();
+
+ unsigned int i = 0;
+ const SkPath* iterPath;
+ while ((iterPath = iter.next(NULL)) != NULL) {
+ matrix.postTranslate(pos[i].fX - prevPos.fX, pos[i].fY - prevPos.fY);
+ path->addPath(*iterPath, matrix);
+ prevPos = pos[i];
+ i++;
+ }
+}
+
static void add_flattenable(SkDescriptor* desc, uint32_t tag,
SkFlattenableWriteBuffer* buffer) {
buffer->flatten(desc->addEntry(tag, buffer->size(), NULL));
}
// SkFontHost can override this choice in FilterRec()
static SkMask::Format computeMaskFormat(const SkPaint& paint) {
uint32_t flags = paint.getFlags();

View File

@ -93,18 +93,18 @@
//#define SkLONGLONG int64_t
/* Some envorinments do not suport writable globals (eek!). If yours does not,
define this flag.
*/
//#define SK_USE_RUNTIME_GLOBALS
/* To write debug messages to a console, skia will call SkDebugf(...) following
printf conventions (e.g. const char* format, ...). If you want to redirect
this to something other than printf, define yours here
*/
//#define SkDebugf(...) MyFunction(__VA_ARGS__)
/*
* To specify a different default font cache limit, define this. If this is
* undefined, skia will use a built-in value.
*/
//#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024)
/* If defined, use CoreText instead of ATSUI on OS X.
*/
//#define SK_USE_MAC_CORE_TEXT
@ -145,6 +145,8 @@
//#define SK_SUPPORT_UNITTEST
#endif
/* Don't dither 32bit gradients, to match what the canvas test suite expects.
*/
#define SK_DISABLE_DITHER_32BIT_GRADIENT
/* If your system embeds skia and has complex event logging, define this
@ -168,8 +170,10 @@
#define SK_A32_SHIFT 24
#endif
/* Don't include stdint.h on windows as it conflicts with our build system.
*/
#ifdef SK_BUILD_FOR_WIN32
#define SK_IGNORE_STDINT_DOT_H
#endif
#define SK_IGNORE_STDINT_DOT_H
#endif
#endif

View File

@ -158,6 +158,19 @@ public:
*/
Sk64 getSafeSize64() const ;
/** Returns true if this bitmap is marked as immutable, meaning that the
contents of its pixels will not change for the lifetime of the bitmap.
*/
bool isImmutable() const;
/** Marks this bitmap as immutable, meaning that the contents of its
pixels will not change for the lifetime of the bitmap and of the
underlying pixelref. This state can be set, but it cannot be
cleared once it is set. This state propagates to all other bitmaps
that share the same pixelref.
*/
void setImmutable();
/** Returns true if the bitmap is opaque (has no translucent/transparent pixels).
*/
bool isOpaque() const;
@ -225,12 +238,11 @@ public:
/** Copies the bitmap's pixels to the location pointed at by dst and returns
true if possible, returns false otherwise.
In the event that the bitmap's stride is equal to dstRowBytes, and if
it is greater than strictly required by the bitmap's current config
(this may happen if the bitmap is an extracted subset of another), then
this function will copy bytes past the eand of each row, excluding the
last row. No copies are made outside of the declared size of dst,
however.
In the case when the dstRowBytes matches the bitmap's rowBytes, the copy
may be made faster by copying over the dst's per-row padding (for all
rows but the last). By setting preserveDstPad to true the caller can
disable this optimization and ensure that pixels in the padding are not
overwritten.
Always returns false for RLE formats.
@ -239,27 +251,12 @@ public:
pixels using indicated stride.
@param dstRowBytes Width of each line in the buffer. If -1, uses
bitmap's internal stride.
@param preserveDstPad Must we preserve padding in the dst
*/
bool copyPixelsTo(void* const dst, size_t dstSize, int dstRowBytes = -1)
bool copyPixelsTo(void* const dst, size_t dstSize, int dstRowBytes = -1,
bool preserveDstPad = false)
const;
/** Copies the pixels at location src to the bitmap's pixel buffer.
Returns true if copy if possible (bitmap buffer is large enough),
false otherwise.
Like copyPixelsTo, this function may write values beyond the end of
each row, although never outside the defined buffer.
Always returns false for RLE formats.
@param src Location of the source buffer.
@param srcSize Height of source buffer in pixels.
@param srcRowBytes Width of each line in the buffer. If -1, uses i
bitmap's internal stride.
*/
bool copyPixelsFrom(const void* const src, size_t srcSize,
int srcRowBytes = -1);
/** Use the standard HeapAllocator to create the pixelref that manages the
pixel memory. It will be sized based on the current width/height/config.
If this is called multiple times, a new pixelref object will be created
@ -478,19 +475,29 @@ public:
*/
bool extractSubset(SkBitmap* dst, const SkIRect& subset) const;
/** Makes a deep copy of this bitmap, respecting the requested config.
Returns false if either there is an error (i.e. the src does not have
pixels) or the request cannot be satisfied (e.g. the src has per-pixel
alpha, and the requested config does not support alpha).
@param dst The bitmap to be sized and allocated
@param c The desired config for dst
@param allocator Allocator used to allocate the pixelref for the dst
bitmap. If this is null, the standard HeapAllocator
will be used.
@return true if the copy could be made.
*/
/** Makes a deep copy of this bitmap, respecting the requested config,
* and allocating the dst pixels on the cpu.
* Returns false if either there is an error (i.e. the src does not have
* pixels) or the request cannot be satisfied (e.g. the src has per-pixel
* alpha, and the requested config does not support alpha).
* @param dst The bitmap to be sized and allocated
* @param c The desired config for dst
* @param allocator Allocator used to allocate the pixelref for the dst
* bitmap. If this is null, the standard HeapAllocator
* will be used.
* @return true if the copy could be made.
*/
bool copyTo(SkBitmap* dst, Config c, Allocator* allocator = NULL) const;
/** Makes a deep copy of this bitmap, respecting the requested config, and
* with custom allocation logic that will keep the copied pixels
* in the same domain as the source: If the src pixels are allocated for
* the cpu, then so will the dst. If the src pixels are allocated on the
* gpu (typically as a texture), the it will do the same for the dst.
* If the request cannot be fulfilled, returns false and dst is unmodified.
*/
bool deepCopyTo(SkBitmap* dst, Config c) const;
/** Returns true if this bitmap can be deep copied into the requested config
by calling copyTo().
*/
@ -595,8 +602,9 @@ private:
mutable int fRawPixelGenerationID;
enum Flags {
kImageIsOpaque_Flag = 0x01,
kImageIsVolatile_Flag = 0x02
kImageIsOpaque_Flag = 0x01,
kImageIsVolatile_Flag = 0x02,
kImageIsImmutable_Flag = 0x04
};
uint32_t fRowBytes;

View File

@ -17,29 +17,49 @@
#include "SkRegion.h"
#include "SkMask.h"
/** SkBlitter and its subclasses are responsible for actually writing pixels
into memory. Besides efficiency, they handle clipping and antialiasing.
*/
class SkBlitter {
public:
virtual ~SkBlitter();
/// Blit a horizontal run of one or more pixels.
virtual void blitH(int x, int y, int width);
virtual void blitAntiH(int x, int y, const SkAlpha* antialias,
const int16_t* runs);
/// Blit a horizontal run of antialiased pixels; runs[] is a *sparse*
/// zero-terminated run-length encoding of spans of constant alpha values.
virtual void blitAntiH(int x, int y, const SkAlpha antialias[],
const int16_t runs[]);
/// Blit a vertical run of pixels with a constant alpha value.
virtual void blitV(int x, int y, int height, SkAlpha alpha);
/// Blit a solid rectangle one or more pixels wide.
virtual void blitRect(int x, int y, int width, int height);
/** Blit a rectangle with one alpha-blended column on the left,
width (zero or more) opaque pixels, and one alpha-blended column
on the right.
The result will always be at least two pixels wide.
*/
virtual void blitAntiRect(int x, int y, int width, int height,
SkAlpha leftAlpha, SkAlpha rightAlpha);
/// Blit a pattern of pixels defined by a rectangle-clipped mask;
/// typically used for text.
virtual void blitMask(const SkMask&, const SkIRect& clip);
/* If the blitter just sets a single value for each pixel, return the
/** If the blitter just sets a single value for each pixel, return the
bitmap it draws into, and assign value. If not, return NULL and ignore
the value parameter.
*/
virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
// not virtual, just helpers
///@name non-virtual helpers
void blitMaskRegion(const SkMask& mask, const SkRegion& clip);
void blitRectRegion(const SkIRect& rect, const SkRegion& clip);
void blitRegion(const SkRegion& clip);
///@}
// factories
/** @name Factories
Return the correct blitter to use given the specified context.
*/
static SkBlitter* Choose(const SkBitmap& device,
const SkMatrix& matrix,
const SkPaint& paint) {
@ -56,6 +76,7 @@ public:
const SkBitmap& src,
int left, int top,
void* storage, size_t storageSize);
///@}
private:
};
@ -85,12 +106,13 @@ public:
fClipRect = clipRect;
}
// overrides
virtual void blitH(int x, int y, int width) SK_OVERRIDE;
virtual void blitAntiH(int x, int y, const SkAlpha[],
const int16_t runs[]) SK_OVERRIDE;
virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
virtual void blitAntiRect(int x, int y, int width, int height,
SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE;
virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE;
virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE;
@ -100,8 +122,8 @@ private:
};
/** Wraps another (real) blitter, and ensures that the real blitter is only
called with coordinates that have been clipped by the specified clipRgn.
This means the caller need not perform the clipping ahead of time.
called with coordinates that have been clipped by the specified clipRgn.
This means the caller need not perform the clipping ahead of time.
*/
class SkRgnClipBlitter : public SkBlitter {
public:
@ -111,12 +133,13 @@ public:
fRgn = clipRgn;
}
// overrides
virtual void blitH(int x, int y, int width) SK_OVERRIDE;
virtual void blitAntiH(int x, int y, const SkAlpha[],
const int16_t runs[]) SK_OVERRIDE;
virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
virtual void blitAntiRect(int x, int y, int width, int height,
SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE;
virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE;
virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE;
@ -125,6 +148,10 @@ private:
const SkRegion* fRgn;
};
/** Factory to set up the appropriate most-efficient wrapper blitter
to apply a clip. Returns a pointer to a member, so lifetime must
be managed carefully.
*/
class SkBlitterClipper {
public:
SkBlitter* apply(SkBlitter* blitter, const SkRegion* clip,

View File

@ -61,6 +61,13 @@ public:
///////////////////////////////////////////////////////////////////////////
/**
* Return the width/height of the underlying device. The current drawable
* area may be small (due to clipping or saveLayer). For a canvas with
* no device, 0,0 will be returned.
*/
SkISize getDeviceSize() const;
/** Return the canvas' device object, which may be null. The device holds
the bitmap of the pixels that the canvas draws into. The reference count
of the returned device is not changed by this call.
@ -99,23 +106,106 @@ public:
///////////////////////////////////////////////////////////////////////////
/**
* Copy the pixels from the device into bitmap. Returns true on success.
* If false is returned, then the bitmap parameter is left unchanged.
* The bitmap parameter is treated as output-only, and will be completely
* overwritten (if the method returns true).
* This enum can be used with read/writePixels to perform a pixel ops to or
* from an 8888 config other than Skia's native config (SkPMColor). There
* are three byte orders supported: native, BGRA, and RGBA. Each has a
* premultiplied and unpremultiplied variant.
*
* Components of a 8888 pixel can be packed/unpacked from a 32bit word using
* either byte offsets or shift values. Byte offsets are endian-invariant
* while shifts are not. BGRA and RGBA configs are defined by byte
* orderings. The native config is defined by shift values (SK_A32_SHIFT,
* ..., SK_B32_SHIFT).
*/
enum Config8888 {
/**
* Skia's native order specified by:
* SK_A32_SHIFT, SK_R32_SHIFT, SK_G32_SHIFT, and SK_B32_SHIFT
*
* kNative_Premul_Config8888 is equivalent to SkPMColor
* kNative_Unpremul_Config8888 has the same component order as SkPMColor
* but is not premultiplied.
*/
kNative_Premul_Config8888,
kNative_Unpremul_Config8888,
/**
* low byte to high byte: B, G, R, A.
*/
kBGRA_Premul_Config8888,
kBGRA_Unpremul_Config8888,
/**
* low byte to high byte: R, G, B, A.
*/
kRGBA_Premul_Config8888,
kRGBA_Unpremul_Config8888,
};
/**
* On success (returns true), copy the canvas pixels into the bitmap.
* On failure, the bitmap parameter is left unchanged and false is
* returned.
*
* The canvas' pixels are converted to the bitmap's config. The only
* supported config is kARGB_8888_Config, though this is likely to be
* relaxed in the future. The meaning of config kARGB_8888_Config is
* modified by the enum param config8888. The default value interprets
* kARGB_8888_Config as SkPMColor
*
* If the bitmap has pixels already allocated, the canvas pixels will be
* written there. If not, bitmap->allocPixels() will be called
* automatically. If the bitmap is backed by a texture readPixels will
* fail.
*
* The actual pixels written is the intersection of the canvas' bounds, and
* the rectangle formed by the bitmap's width,height and the specified x,y.
* If bitmap pixels extend outside of that intersection, they will not be
* modified.
*
* Other failure conditions:
* * If the canvas is backed by a non-raster device (e.g. PDF) then
* readPixels will fail.
* * If bitmap is texture-backed then readPixels will fail. (This may be
* relaxed in the future.)
*
* Example that reads the entire canvas into a bitmap using the native
* SkPMColor:
* SkISize size = canvas->getDeviceSize();
* bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
* size.fHeight);
* if (canvas->readPixels(bitmap, 0, 0)) {
* // use the pixels
* }
*/
bool readPixels(SkBitmap* bitmap,
int x, int y,
Config8888 config8888 = kNative_Premul_Config8888);
/**
* DEPRECATED: This will be removed as soon as webkit is no longer relying
* on it. The bitmap is resized to the intersection of srcRect and the
* canvas bounds. New pixels are always allocated on success. Bitmap is
* unmodified on failure.
*/
bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
bool readPixels(SkBitmap* bitmap);
/**
* Similar to draw sprite, this method will copy the pixels in bitmap onto
* the device, with the top/left corner specified by (x, y). The pixel
* values in the device are completely replaced: there is no blending.
* the canvas, with the top/left corner specified by (x, y). The canvas'
* pixel values are completely replaced: there is no blending.
*
* Currently if bitmap is backed by a texture this is a no-op. This may be
* relaxed in the future.
*
* If the bitmap has config kARGB_8888_Config then the config8888 param
* will determines how the pixel valuess are intepreted. If the bitmap is
* not kARGB_8888_Config then this parameter is ignored.
*
* Note: If you are recording drawing commands on this canvas to
* SkPicture, writePixels() is ignored!
*/
void writePixels(const SkBitmap& bitmap, int x, int y);
void writePixels(const SkBitmap& bitmap,
int x, int y,
Config8888 config8888 = kNative_Premul_Config8888);
///////////////////////////////////////////////////////////////////////////
@ -197,6 +287,11 @@ public:
*/
void restoreToCount(int saveCount);
/** Returns true if drawing is currently going to a layer (from saveLayer)
* rather than to the root device.
*/
bool isDrawingToLayer() const;
/** Preconcat the current matrix with the specified translation
@param dx The distance to translate in X
@param dy The distance to translate in Y
@ -646,7 +741,7 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
/** Draw the text on path, with each character/glyph origin specified by the pos[]
array. The origin is interpreted by the Align setting in the paint.
@param text The text to be drawn
@ -842,6 +937,7 @@ private:
SkBounder* fBounder;
SkDevice* fLastDeviceToGainFocus;
int fLayerCount; // number of successful saveLayer calls
void prepareForDeviceDraw(SkDevice*, const SkMatrix&, const SkRegion&,
const SkClipStack& clipStack);

View File

@ -23,6 +23,31 @@ public:
*/
virtual bool asColorMode(SkColor* color, SkXfermode::Mode* mode);
/**
* If the filter can be represented by a 5x4 matrix, this
* returns true, and sets the matrix appropriately.
* If not, this returns false and ignores the parameter.
*/
virtual bool asColorMatrix(SkScalar matrix[20]);
/**
* If the filter can be represented by per-component table, return true,
* and if table is not null, copy the bitmap containing the table into it.
*
* The table bitmap will be in SkBitmap::kA8_Config. Each row corresponding
* to each component in ARGB order. e.g. row[0] == alpha, row[1] == red,
* etc. To transform a color, you (logically) perform the following:
*
* a' = *table.getAddr8(a, 0);
* r' = *table.getAddr8(r, 1);
* g' = *table.getAddr8(g, 2);
* b' = *table.getAddr8(b, 3);
*
* The original component value is the horizontal index for a given row,
* and the stored value at that index is the new value for that component.
*/
virtual bool asComponentTable(SkBitmap* table);
/** Called with a scanline of colors, as if there was a shader installed.
The implementation writes out its filtered version into result[].
Note: shader and result may be the same buffer.
@ -92,7 +117,8 @@ public:
are ignored.
*/
static SkColorFilter* CreateLightingFilter(SkColor mul, SkColor add);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkColorFilter() {}
SkColorFilter(SkFlattenableReadBuffer& rb) : INHERITED(rb) {}

View File

@ -32,30 +32,32 @@ public:
virtual ~SkColorShader();
virtual uint32_t getFlags() { return fFlags; }
virtual uint8_t getSpan16Alpha() const;
virtual uint32_t getFlags() SK_OVERRIDE;
virtual uint8_t getSpan16Alpha() const SK_OVERRIDE;
virtual bool isOpaque() const SK_OVERRIDE;
virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
const SkMatrix& matrix);
virtual void shadeSpan(int x, int y, SkPMColor span[], int count);
virtual void shadeSpan16(int x, int y, uint16_t span[], int count);
virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
const SkMatrix& matrix) SK_OVERRIDE;
virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE;
virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE;
// we return false for this, use asAGradient
virtual BitmapType asABitmap(SkBitmap* outTexture,
SkMatrix* outMatrix,
TileMode xy[2],
SkScalar* twoPointRadialParams) const;
SkScalar* twoPointRadialParams) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
protected:
SkColorShader(SkFlattenableReadBuffer& );
virtual void flatten(SkFlattenableWriteBuffer& );
virtual Factory getFactory() { return CreateProc; }
SkColorShader(SkFlattenableReadBuffer&);
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE;
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkColorShader, (buffer));
}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SkColor fColor; // ignored if fInheritColor is true
SkPMColor fPMColor; // cached after setContext()
uint32_t fFlags; // cached after setContext()

View File

@ -107,30 +107,28 @@ public:
const SkBitmap& accessBitmap(bool changePixels);
/**
* Copy the pixels from the device into bitmap. Returns true on success.
* If false is returned, then the bitmap parameter is left unchanged.
* The bitmap parameter is treated as output-only, and will be completely
* overwritten (if the method returns true).
*/
virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
/**
* DEPRECATED: This will be made protected once WebKit stops using it.
* Instead use Canvas' writePixels method.
*
* Similar to draw sprite, this method will copy the pixels in bitmap onto
* the device, with the top/left corner specified by (x, y). The pixel
* values in the device are completely replaced: there is no blending.
*
* Currently if bitmap is backed by a texture this is a no-op. This may be
* relaxed in the future.
*
* If the bitmap has config kARGB_8888_Config then the config8888 param
* will determines how the pixel valuess are intepreted. If the bitmap is
* not kARGB_8888_Config then this parameter is ignored.
*/
virtual void writePixels(const SkBitmap& bitmap, int x, int y);
virtual void writePixels(const SkBitmap& bitmap, int x, int y,
SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888);
/**
* Return the device's associated gpu render target, or NULL.
*/
virtual SkGpuRenderTarget* accessRenderTarget() { return NULL; }
protected:
enum Usage {
kGeneral_Usage,
kSaveLayer_Usage, // <! internal use only
};
/**
* Return the device's origin: its offset in device coordinates from
@ -138,6 +136,12 @@ protected:
*/
const SkIPoint& getOrigin() const { return fOrigin; }
protected:
enum Usage {
kGeneral_Usage,
kSaveLayer_Usage, // <! internal use only
};
struct TextFlags {
uint32_t fFlags; // SkPaint::getFlags()
SkPaint::Hinting fHinting;
@ -226,7 +230,7 @@ protected:
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
const SkPoint pos[], const SkPaint& paint,
const SkPath& path, const SkMatrix* matrix);
@ -242,6 +246,37 @@ protected:
virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
const SkPaint&);
/**
* On success (returns true), copy the device pixels into the bitmap.
* On failure, the bitmap parameter is left unchanged and false is
* returned.
*
* The device's pixels are converted to the bitmap's config. The only
* supported config is kARGB_8888_Config, though this is likely to be
* relaxed in the future. The meaning of config kARGB_8888_Config is
* modified by the enum param config8888. The default value interprets
* kARGB_8888_Config as SkPMColor
*
* If the bitmap has pixels already allocated, the device pixels will be
* written there. If not, bitmap->allocPixels() will be called
* automatically. If the bitmap is backed by a texture readPixels will
* fail.
*
* The actual pixels written is the intersection of the device's bounds,
* and the rectangle formed by the bitmap's width,height and the specified
* x,y. If bitmap pixels extend outside of that intersection, they will not
* be modified.
*
* Other failure conditions:
* * If the device is not a raster device (e.g. PDF) then readPixels will
* fail.
* * If bitmap is texture-backed then readPixels will fail. (This may be
* relaxed in the future.)
*/
bool readPixels(SkBitmap* bitmap,
int x, int y,
SkCanvas::Config8888 config8888);
///////////////////////////////////////////////////////////////////////////
/** Update as needed the pixel value in the bitmap, so that the caller can access
@ -256,6 +291,17 @@ protected:
fBitmap.setPixelRef(pr, offset);
return pr;
}
/**
* Implements readPixels API. The caller will ensure that:
* 1. bitmap has pixel config kARGB_8888_Config.
* 2. bitmap has pixels.
* 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
* contained in the device bounds.
*/
virtual bool onReadPixels(const SkBitmap& bitmap,
int x, int y,
SkCanvas::Config8888 config8888);
/** Called when this device is installed into a Canvas. Balanaced by a call
to unlockPixels() when the device is removed from a Canvas.
@ -263,12 +309,26 @@ protected:
virtual void lockPixels();
virtual void unlockPixels();
/**
* Override and return true for filters that the device handles
* intrinsically. Returning false means call the filter.
* Default impl returns false.
*/
virtual bool filterImage(SkImageFilter*, const SkBitmap& src,
const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset);
// This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
// either is identical to kNative_Premul_Config8888. Otherwise, -1.
static const SkCanvas::Config8888 kPMColorAlias;
private:
friend class SkCanvas;
friend struct DeviceCM; //for setMatrixClip
friend class SkDraw;
friend class SkDrawIter;
friend class SkDeviceFilteredPaint;
friend class DeviceImageFilterProxy;
// just called by SkCanvas when built as a layer
void setOrigin(int x, int y) { fOrigin.set(x, y); }

View File

@ -55,7 +55,7 @@ public:
int scalarsPerPosition, const SkPaint& paint) const;
void drawTextOnPath(const char text[], size_t byteLength,
const SkPath&, const SkMatrix*, const SkPaint&) const;
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
void drawPosTextOnPath(const char text[], size_t byteLength,
const SkPoint pos[], const SkPaint& paint,
const SkPath& path, const SkMatrix* matrix) const;
@ -149,6 +149,7 @@ private:
const SkPath* fPath; // returned in next
SkScalar fXPos; // accumulated xpos, returned in next
SkAutoKern fAutoKern;
int fXYIndex; // cache for horizontal -vs- vertical text
};
#endif

View File

@ -15,24 +15,26 @@
/**
* \class SkEmptyShader
* A Shader that always draws nothing.
* A Shader that always draws nothing. Its setContext always returns false,
* so it never expects that its shadeSpan() methods will get called.
*/
class SK_API SkEmptyShader : public SkShader {
public:
SkEmptyShader();
SkEmptyShader() {}
virtual uint32_t getFlags();
virtual uint8_t getSpan16Alpha() const;
virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
const SkMatrix& matrix);
virtual void shadeSpan(int x, int y, SkPMColor span[], int count);
virtual void shadeSpan16(int x, int y, uint16_t span[], int count);
virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
virtual uint32_t getFlags() SK_OVERRIDE;
virtual uint8_t getSpan16Alpha() const SK_OVERRIDE;
virtual bool setContext(const SkBitmap&, const SkPaint&,
const SkMatrix&) SK_OVERRIDE;
virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE;
virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE;
protected:
SkEmptyShader(SkFlattenableReadBuffer&);
virtual Factory getFactory();
virtual void flatten(SkFlattenableWriteBuffer&);
virtual Factory getFactory() SK_OVERRIDE;
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
private:
typedef SkShader INHERITED;

View File

@ -80,6 +80,19 @@ static inline void SkEndianSwap32s(uint32_t array[], int count) {
#define SkEndian_SwapLE32(n) SkEndianSwap32(n)
#endif
// When a bytestream is embedded in a 32-bit word, how far we need to
// shift the word to extract each byte from the low 8 bits by anding with 0xff.
#ifdef SK_CPU_LENDIAN
#define SkEndian_Byte0Shift 0
#define SkEndian_Byte1Shift 8
#define SkEndian_Byte2Shift 16
#define SkEndian_Byte3Shift 24
#else // SK_CPU_BENDIAN
#define SkEndian_Byte0Shift 24
#define SkEndian_Byte1Shift 16
#define SkEndian_Byte2Shift 8
#define SkEndian_Byte3Shift 0
#endif
#endif

View File

@ -20,6 +20,40 @@ class SkFlattenableReadBuffer;
class SkFlattenableWriteBuffer;
class SkString;
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
#define SK_DECLARE_FLATTENABLE_REGISTRAR()
#define SK_DEFINE_FLATTENABLE_REGISTRAR(flattenable) \
static SkFlattenable::Registrar g##flattenable##Reg(#flattenable, \
flattenable::CreateProc);
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable)
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
static SkFlattenable::Registrar g##flattenable##Reg(#flattenable, \
flattenable::CreateProc);
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
#else
#define SK_DECLARE_FLATTENABLE_REGISTRAR() static void Init();
#define SK_DEFINE_FLATTENABLE_REGISTRAR(flattenable) \
void flattenable::Init() { \
SkFlattenable::Registrar(#flattenable, CreateProc); \
}
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
void flattenable::Init() {
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
SkFlattenable::Registrar(#flattenable, flattenable::CreateProc);
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
}
#endif
/** \class SkFlattenable
SkFlattenable is the base class for objects that need to be flattened
@ -61,6 +95,13 @@ public:
protected:
SkFlattenable(SkFlattenableReadBuffer&) {}
private:
#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
static void InitializeFlattenables();
#endif
friend class SkGraphics;
};
// helpers for matrix and region

View File

@ -58,12 +58,24 @@ static inline float sk_float_copysign(float x, float y) {
#define sk_float_acos(x) acosf(x)
#define sk_float_asin(x) asinf(x)
#endif
#define sk_float_atan2(y,x) atan2f(y,x)
#define sk_float_atan2(y,x) atan2f(y,x)
#define sk_float_abs(x) fabsf(x)
#define sk_float_mod(x,y) fmodf(x,y)
#define sk_float_exp(x) expf(x)
#define sk_float_log(x) logf(x)
#define sk_float_isNaN(x) _isnan(x)
#endif
#ifdef SK_BUILD_FOR_WIN
#define sk_float_isfinite(x) _finite(x)
#define sk_float_isnan(x) _isnan(x)
static inline int sk_float_isinf(float x) {
int32_t bits = SkFloat2Bits(x);
return (bits << 1) == (0xFF << 24);
}
#else
#define sk_float_isfinite(x) isfinite(x)
#define sk_float_isnan(x) isnan(x)
#define sk_float_isinf(x) isinf(x)
#endif
#ifdef SK_USE_FLOATBITS

View File

@ -232,20 +232,9 @@ public:
///////////////////////////////////////////////////////////////////////////
/** Return the number of bytes (approx) that should be purged from the font
cache. The input parameter is the cache's estimate of how much as been
allocated by the cache so far.
To purge (basically) everything, return the input parameter.
To purge nothing, return 0
*/
static size_t ShouldPurgeFontCache(size_t sizeAllocatedSoFar);
/** DEPRECATED -- only called by SkFontHost_FreeType internally
/** Return SkScalerContext gamma flag, or 0, based on the paint that will be
used to draw something with antialiasing.
*/
static int ComputeGammaFlag(const SkPaint& paint);
/** Return NULL or a pointer to 256 bytes for the black (table[0]) and
Return NULL or a pointer to 256 bytes for the black (table[0]) and
white (table[1]) gamma tables.
*/
static void GetGammaTables(const uint8_t* tables[2]);
@ -286,7 +275,7 @@ public:
static void SetSubpixelOrder(LCDOrder order);
static LCDOrder GetSubpixelOrder();
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
///////////////////////////////////////////////////////////////////////////
/**
@ -297,6 +286,14 @@ public:
*/
static uint32_t GetUnitsPerEm(SkFontID fontID);
#endif
/** If Skia is running in a constrained environment and the typeface
implementation is handle based, the typeface data may become
unavailable asynchronously. If a font host or scaler context method is
unable to access font data, it may call this function as a request to
make the handle contained in the typeface useable.
*/
static void EnsureTypefaceAccessible(const SkTypeface& typeface);
};
#endif

View File

@ -14,24 +14,57 @@
class SkGraphics {
public:
/**
* Call this at process initialization time if your environment does not
* permit static global initializers that execute code. Note that
* Init() is not thread-safe.
*/
static void Init();
/**
* Call this to release any memory held privately, such as the font cache.
*/
static void Term();
/** Return the (approximate) number of bytes used by the font cache.
*/
static size_t GetFontCacheUsed();
/** Attempt to purge the font cache until <= the specified amount remains
in the cache. Specifying 0 will attempt to purge the entire cache.
Returns true if some amount was purged from the font cache.
*/
static bool SetFontCacheUsed(size_t usageInBytes);
/** Return the version numbers for the library. If the parameter is not
null, it is set to the version number.
/**
* Return the version numbers for the library. If the parameter is not
* null, it is set to the version number.
*/
static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
/**
* Return the max number of bytes that should be used by the font cache.
* If the cache needs to allocate more, it will purge previous entries.
* This max can be changed by calling SetFontCacheLimit().
*/
static size_t GetFontCacheLimit();
/**
* Specify the max number of bytes that should be used by the font cache.
* If the cache needs to allocate more, it will purge previous entries.
*
* This function returns the previous setting, as if GetFontCacheLimit()
* had be called before the new limit was set.
*/
static size_t SetFontCacheLimit(size_t bytes);
/**
* For debugging purposes, this will attempt to purge the font cache. It
* does not change the limit, but will cause subsequent font measures and
* draws to be recreated, since they will no longer be in the cache.
*/
static void PurgeFontCache();
/**
* Applications with command line options may pass optional state, such
* as cache sizes, here, for instance:
* font-cache-limit=12345678
*
* The flags format is name=value[;name=value...] with no spaces.
* This format is subject to change.
*/
static void SetFlags(const char* flags);
private:
/** This is automatically called by SkGraphics::Init(), and must be
implemented by the host OS. This allows the host OS to register a callback

View File

@ -10,8 +10,44 @@
#include "SkFlattenable.h"
class SkImageFilter : public SkFlattenable {
class SkBitmap;
class SkDevice;
class SkMatrix;
struct SkPoint;
/**
* Experimental.
*
* Base class for image filters. If one is installed in the paint, then
* all drawing occurs as usual, but it is as if the drawing happened into an
* offscreen (before the xfermode is applied). This offscreen bitmap will
* then be handed to the imagefilter, who in turn creates a new bitmap which
* is what will finally be drawn to the device (using the original xfermode).
*
* THIS SIGNATURE IS TEMPORARY
*
* There are several weaknesses in this function signature:
* 1. Does not expose the destination/target device, so filters that can draw
* directly to it are unable to take advantage of that optimization.
* 2. Does not expose a way to create a "compabitible" image (i.e. gpu -> gpu)
* 3. As with #1, the filter is unable to "read" the dest (which would be slow)
*
* Therefore, we should not create any real dependencies on this API yet -- it
* is being checked in as a check-point so we can explore these and other
* considerations.
*/
class SK_API SkImageFilter : public SkFlattenable {
public:
class Proxy {
public:
virtual SkDevice* createDevice(int width, int height) = 0;
// returns true if the proxy handled the filter itself. if this returns
// false then the filter's code will be called.
virtual bool filterImage(SkImageFilter*, const SkBitmap& src,
const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset) = 0;
};
/**
* Request a new (result) image to be created from the src image.
@ -26,12 +62,32 @@ public:
* If the result image cannot be created, return false, in which case both
* the result and offset parameters will be ignored by the caller.
*/
bool filterImage(const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkPoint* offset);
bool filterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset);
/**
* Given the src bounds of an image, this returns the bounds of the result
* image after the filter has been applied.
*/
bool filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst);
/**
* Experimental.
*
* If the filter can be expressed as a gaussian-blur, return true and
* set the sigma to the values for horizontal and vertical.
*/
virtual bool asABlur(SkSize* sigma) const;
protected:
virtual bool onFilterImage(const SkBitmap& src, const SkMatrix&
SkBitmap* result, SkPoint* offset) = 0;
SkImageFilter() {}
explicit SkImageFilter(SkFlattenableReadBuffer& rb) : INHERITED(rb) {}
// Default impl returns false
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* offset);
// Default impl copies src into dst and returns true
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*);
private:
typedef SkFlattenable INHERITED;

View File

@ -19,7 +19,6 @@ public:
virtual void setMemory(const void* data, size_t length, bool);
private:
int fFildes;
void* fAddr;
size_t fSize;

View File

@ -37,6 +37,7 @@ public:
return SkNEW_ARGS(SkMallocPixelRef, (buffer));
}
SK_DECLARE_PIXEL_REF_REGISTRAR()
protected:
// overrides from SkPixelRef
virtual void* onLockPixels(SkColorTable**);

View File

@ -13,7 +13,7 @@
#include "SkString.h"
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
#include <dirent.h>
#endif
@ -58,7 +58,7 @@ public:
#ifdef SK_BUILD_FOR_WIN
HANDLE fHandle;
uint16_t* fPath16;
#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
DIR* fDIR;
SkString fPath, fSuffix;
#endif

View File

@ -21,6 +21,7 @@ class SkFlattenableWriteBuffer;
struct SkGlyph;
struct SkRect;
class SkGlyphCache;
class SkImageFilter;
class SkMaskFilter;
class SkMatrix;
class SkPath;
@ -98,9 +99,7 @@ public:
kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
// experimental/private
kForceAAText_Flag = 0x1000,
kVerticalText_Flag = 0x1000,
// when adding extra flags, note that the fFlags member is specified
// with a bit-width and you'll have to expand it.
@ -202,6 +201,20 @@ public:
*/
void setAutohinted(bool useAutohinter);
bool isVerticalText() const {
return SkToBool(this->getFlags() & kVerticalText_Flag);
}
/**
* Helper for setting or clearing the kVerticalText_Flag bit in
* setFlags(...).
*
* If this bit is set, then advances are treated as Y values rather than
* X values, and drawText will places its glyphs vertically rather than
* horizontally.
*/
void setVerticalText(bool);
/** Helper for getFlags(), returning true if kUnderlineText_Flag bit is set
@return true if the underlineText bit is set in the paint's flags.
*/
@ -595,6 +608,9 @@ public:
*/
SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
SkImageFilter* getImageFilter() const { return fImageFilter; }
SkImageFilter* setImageFilter(SkImageFilter*);
/**
* Return the paint's SkDrawLooper (if any). Does not affect the looper's
* reference count.
@ -743,23 +759,29 @@ public:
return this->textToGlyphs(text, byteLength, NULL);
}
/** Return the width of the text.
@param text The text to be measured
@param length Number of bytes of text to measure
@param bounds If not NULL, returns the bounds of the text,
relative to (0, 0).
@param scale If not 0, return width as if the canvas were scaled
by this value
@return The advance width of the text
*/
/** Return the width of the text. This will return the vertical measure
* if isVerticalText() is true, in which case the returned value should
* be treated has a height instead of a width.
*
* @param text The text to be measured
* @param length Number of bytes of text to measure
* @param bounds If not NULL, returns the bounds of the text,
* relative to (0, 0).
* @param scale If not 0, return width as if the canvas were scaled
* by this value
* @return The advance width of the text
*/
SkScalar measureText(const void* text, size_t length,
SkRect* bounds, SkScalar scale = 0) const;
/** Return the width of the text.
@param text Address of the text
@param length Number of bytes of text to measure
@return The width of the text
*/
/** Return the width of the text. This will return the vertical measure
* if isVerticalText() is true, in which case the returned value should
* be treated has a height instead of a width.
*
* @param text Address of the text
* @param length Number of bytes of text to measure
* @return The width of the text
*/
SkScalar measureText(const void* text, size_t length) const {
return this->measureText(text, length, NULL, 0);
}
@ -777,33 +799,38 @@ public:
kBackward_TextBufferDirection
};
/** Return the width of the text.
@param text The text to be measured
@param length Number of bytes of text to measure
@param maxWidth Maximum width. Only the subset of text whose accumulated
widths are <= maxWidth are measured.
@param measuredWidth Optional. If non-null, this returns the actual
width of the measured text.
@param tbd Optional. The direction the text buffer should be
traversed during measuring.
@return The number of bytes of text that were measured. Will be
<= length.
*/
/** Return the number of bytes of text that were measured. If
* isVerticalText() is true, then the vertical advances are used for
* the measurement.
*
* @param text The text to be measured
* @param length Number of bytes of text to measure
* @param maxWidth Maximum width. Only the subset of text whose accumulated
* widths are <= maxWidth are measured.
* @param measuredWidth Optional. If non-null, this returns the actual
* width of the measured text.
* @param tbd Optional. The direction the text buffer should be
* traversed during measuring.
* @return The number of bytes of text that were measured. Will be
* <= length.
*/
size_t breakText(const void* text, size_t length, SkScalar maxWidth,
SkScalar* measuredWidth = NULL,
TextBufferDirection tbd = kForward_TextBufferDirection)
const;
/** Return the advance widths for the characters in the string.
@param text the text
@param byteLength number of bytes to of text
@param widths If not null, returns the array of advance widths of
the glyphs. If not NULL, must be at least a large
as the number of unichars in the specified text.
@param bounds If not null, returns the bounds for each of
character, relative to (0, 0)
@return the number of unichars in the specified text.
*/
/** Return the advances for the text. These will be vertical advances if
* isVerticalText() returns true.
*
* @param text the text
* @param byteLength number of bytes to of text
* @param widths If not null, returns the array of advances for
* the glyphs. If not NULL, must be at least a large
* as the number of unichars in the specified text.
* @param bounds If not null, returns the bounds for each of
* character, relative to (0, 0)
* @return the number of unichars in the specified text.
*/
int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
SkRect bounds[] = NULL) const;
@ -817,7 +844,7 @@ public:
void getPosTextPath(const void* text, size_t length,
const SkPoint pos[], SkPath* path) const;
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
const SkGlyph& getUnicharMetrics(SkUnichar);
const void* findImage(const SkGlyph&);
@ -841,20 +868,18 @@ private:
SkColorFilter* fColorFilter;
SkRasterizer* fRasterizer;
SkDrawLooper* fLooper;
SkImageFilter* fImageFilter;
SkColor fColor;
SkScalar fWidth;
SkScalar fMiterLimit;
unsigned fFlags : 13;
unsigned fFlags : 14;
unsigned fTextAlign : 2;
unsigned fCapType : 2;
unsigned fJoinType : 2;
unsigned fStyle : 2;
unsigned fTextEncoding : 2; // 3 values
unsigned fHinting : 2;
#ifdef ANDROID
uint32_t fGenerationID;
#endif
SkDrawCacheProc getDrawCacheProc() const;
SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
@ -880,6 +905,12 @@ private:
friend class SkDraw;
friend class SkPDFDevice;
friend class SkTextToPathIter;
#ifdef SK_BUILD_FOR_ANDROID
// In order for the == operator to work properly this must be the last field
// in the struct so that we can do a memcmp to this field's offset.
uint32_t fGenerationID;
#endif
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -13,7 +13,7 @@
#include "SkMatrix.h"
#include "SkTDArray.h"
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
#define GEN_ID_INC fGenerationID++
#define GEN_ID_PTR_INC(ptr) ptr->fGenerationID++
#else
@ -38,7 +38,7 @@ public:
~SkPath();
SkPath& operator=(const SkPath&);
friend bool operator==(const SkPath&, const SkPath&);
friend bool operator!=(const SkPath& a, const SkPath& b) {
return !(a == b);
@ -70,7 +70,7 @@ public:
/** Set the path's fill type. This is used to define how "inside" is
computed. The default value is kWinding_FillType.
@param ft The new fill type for this path
*/
void setFillType(FillType ft) {
@ -180,6 +180,35 @@ public:
*/
bool isEmpty() const;
/** Test a line for zero length
@return true if the line is of zero length; otherwise false.
*/
static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) {
return p1.equalsWithinTolerance(p2, SK_ScalarNearlyZero);
}
/** Test a quad for zero length
@return true if the quad is of zero length; otherwise false.
*/
static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
const SkPoint& p3) {
return p1.equalsWithinTolerance(p2, SK_ScalarNearlyZero) &&
p2.equalsWithinTolerance(p3, SK_ScalarNearlyZero);
}
/** Test a cubic curve for zero length
@return true if the cubic is of zero length; otherwise false.
*/
static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
const SkPoint& p3, const SkPoint& p4) {
return p1.equalsWithinTolerance(p2, SK_ScalarNearlyZero) &&
p2.equalsWithinTolerance(p3, SK_ScalarNearlyZero) &&
p3.equalsWithinTolerance(p4, SK_ScalarNearlyZero);
}
/** Returns true if the path specifies a rectangle. If so, and if rect is
not null, set rect to the bounds of the path. If the path does not
specify a rectangle, return false and ignore rect.
@ -594,17 +623,23 @@ public:
/** Iterate through all of the segments (lines, quadratics, cubics) of
each contours in a path.
The iterator cleans up the segments along the way, removing degenerate
segments and adding close verbs where necessary. When the forceClose
argument is provided, each contour (as defined by a new starting
move command) will be completed with a close verb regardless of the
contour's contents.
*/
class SK_API Iter {
public:
Iter();
Iter(const SkPath&, bool forceClose);
Iter();
Iter(const SkPath&, bool forceClose);
void setPath(const SkPath&, bool forceClose);
/** Return the next verb in this iteration of the path. When all
segments have been visited, return kDone_Verb.
@param pts The points representing the current verb and/or segment
@return The verb for the current segment
*/
@ -614,12 +649,12 @@ public:
line was the result of a close() command (i.e. the end point is the
initial moveto for this contour). If next() returned a different
verb, this returns an undefined value.
@return If the last call to next() returned kLine_Verb, return true
if it was the result of an explicit close command.
*/
bool isCloseLine() const { return SkToBool(fCloseLine); }
/** Returns true if the current contour is closed (has a kClose_Verb)
@return true if the current contour is closed (has a kClose_Verb)
*/
@ -633,11 +668,37 @@ public:
SkPoint fLastPt;
SkBool8 fForceClose;
SkBool8 fNeedClose;
SkBool8 fNeedMoveTo;
SkBool8 fCloseLine;
SkBool8 fSegmentState;
bool cons_moveTo(SkPoint pts[1]);
Verb autoClose(SkPoint pts[2]);
void consumeDegenerateSegments();
};
/** Iterate through the verbs in the path, providing the associated points.
*/
class SK_API RawIter {
public:
RawIter();
RawIter(const SkPath&);
void setPath(const SkPath&);
/** Return the next verb in this iteration of the path. When all
segments have been visited, return kDone_Verb.
@param pts The points representing the current verb and/or segment
@return The verb for the current segment
*/
Verb next(SkPoint pts[4]);
private:
const SkPoint* fPts;
const uint8_t* fVerbs;
const uint8_t* fVerbStop;
SkPoint fMoveTo;
SkPoint fLastPt;
};
void dump(bool forceClose, const char title[] = NULL) const;
@ -646,7 +707,7 @@ public:
void flatten(SkWriter32&) const;
void unflatten(SkReader32&);
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
uint32_t getGenerationID() const;
#endif
@ -660,7 +721,7 @@ private:
uint8_t fSegmentMask;
mutable uint8_t fBoundsIsDirty;
mutable uint8_t fConvexity;
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
uint32_t fGenerationID;
#endif
@ -688,4 +749,3 @@ private:
};
#endif

View File

@ -34,6 +34,7 @@ public:
*/
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) = 0;
SK_DECLARE_FLATTENABLE_REGISTRAR()
private:
// illegal
SkPathEffect(const SkPathEffect&);

View File

@ -10,10 +10,10 @@
#ifndef SkPixelRef_DEFINED
#define SkPixelRef_DEFINED
#include "SkBitmap.h"
#include "SkRefCnt.h"
#include "SkString.h"
class SkBitmap;
class SkColorTable;
struct SkIRect;
class SkMutex;
@ -23,6 +23,25 @@ class SkFlattenableWriteBuffer;
// this is an opaque class, not interpreted by skia
class SkGpuTexture;
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
#define SK_DECLARE_PIXEL_REF_REGISTRAR()
#define SK_DEFINE_PIXEL_REF_REGISTRAR(pixelRef) \
static SkPixelRef::Registrar g##pixelRef##Reg(#pixelRef, \
pixelRef::Create);
#else
#define SK_DECLARE_PIXEL_REF_REGISTRAR() static void Init();
#define SK_DEFINE_PIXEL_REF_REGISTRAR(pixelRef) \
void pixelRef::Init() { \
SkPixelRef::Registrar(#pixelRef, Create); \
}
#endif
/** \class SkPixelRef
This class is the smart container for pixel memory, and is used with
@ -117,6 +136,12 @@ public:
bool readPixels(SkBitmap* dst, const SkIRect* subset = NULL);
/** Makes a deep copy of this PixelRef, respecting the requested config.
Returns NULL if either there is an error (e.g. the destination could
not be created with the given config), or this PixelRef does not
support deep copies. */
virtual SkPixelRef* deepCopy(SkBitmap::Config config) { return NULL; }
// serialization
typedef SkPixelRef* (*Factory)(SkFlattenableReadBuffer&);
@ -124,7 +149,7 @@ public:
virtual Factory getFactory() const { return NULL; }
virtual void flatten(SkFlattenableWriteBuffer&) const;
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
/**
* Acquire a "global" ref on this object.
* The default implementation just calls ref(), but subclasses can override
@ -181,6 +206,10 @@ protected:
SkPixelRef(SkFlattenableReadBuffer&, SkMutex*);
private:
#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
static void InitializeFlattenables();
#endif
SkMutex* fMutex; // must remain in scope for the life of this object
void* fPixels;
SkColorTable* fColorTable; // we do not track ownership, subclass does
@ -192,6 +221,8 @@ private:
// can go from false to true, but never from true to false
bool fIsImmutable;
friend class SkGraphics;
};
#endif

View File

@ -315,6 +315,13 @@ struct SK_API SkPoint {
return a.fX != b.fX || a.fY != b.fY;
}
/** Return true if this and the given point are componentwise within tol.
*/
bool equalsWithinTolerance(const SkPoint& v, SkScalar tol) const {
return SkScalarNearlyZero(fX - v.fX, tol)
&& SkScalarNearlyZero(fY - v.fY, tol);
}
/** Returns a new point whose coordinates are the difference between
a's and b's (a - b)
*/

View File

@ -56,6 +56,32 @@
#endif
#endif
#if !defined(SK_HAS_COMPILER_FEATURE)
#if defined(__has_feature)
#define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
#else
#define SK_HAS_COMPILER_FEATURE(x) 0
#endif
#endif
/**
* The clang static analyzer likes to know that when the program is not
* expected to continue (crash, assertion failure, etc). It will notice that
* some combination of parameters lead to a function call that does not return.
* It can then make appropriate assumptions about the parameters in code
* executed only if the non-returning function was *not* called.
*/
#if !defined(SkNO_RETURN_HINT)
#if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
namespace {
inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
void SkNO_RETURN_HINT() {}
}
#else
#define SkNO_RETURN_HINT() do {} while (false)
#endif
#endif
///////////////////////////////////////////////////////////////////////////////
#ifndef SkNEW
@ -68,9 +94,9 @@
#ifndef SK_CRASH
#if 1 // set to 0 for infinite loop, which can help connecting gdb
#define SK_CRASH() *(int *)(uintptr_t)0xbbadbeef = 0
#define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
#else
#define SK_CRASH() do {} while (true)
#define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
#endif
#endif
@ -100,7 +126,7 @@
#endif
#ifndef SK_DEBUGBREAK
#define SK_DEBUGBREAK(cond) do { if (!(cond)) __debugbreak(); } while (false)
#define SK_DEBUGBREAK(cond) do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
#endif
#ifndef SK_A32_SHIFT
@ -265,3 +291,8 @@
#endif
#endif
//////////////////////////////////////////////////////////////////////
#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
#define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
#endif

View File

@ -16,7 +16,7 @@
//////////////////////////////////////////////////////////////////////
#if !defined(SK_BUILD_FOR_ANDROID_NDK) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_PALM) && !defined(SK_BUILD_FOR_WINCE) && !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_SYMBIAN) && !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_SDL) && !defined(SK_BUILD_FOR_BREW)
#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_PALM) && !defined(SK_BUILD_FOR_WINCE) && !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_SYMBIAN) && !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_SDL) && !defined(SK_BUILD_FOR_BREW)
#ifdef __APPLE__
#include "TargetConditionals.h"
@ -30,13 +30,14 @@
#define SK_BUILD_FOR_WIN32
#elif defined(__SYMBIAN32__)
#define SK_BUILD_FOR_WIN32
#elif defined(linux) || defined(__OpenBSD_)
#elif defined(linux) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
defined(__sun) || defined(__NetBSD__) || defined(__DragonFly__)
#define SK_BUILD_FOR_UNIX
#elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
#define SK_BUILD_FOR_IOS
#elif defined(ANDROID_NDK)
#define SK_BUILD_FOR_ANDROID_NDK
#elif defined(ANROID)
#elif defined(ANDROID)
#define SK_BUILD_FOR_ANDROID
#else
#define SK_BUILD_FOR_MAC
@ -44,6 +45,15 @@
#endif
/* Even if the user only defined the NDK variant we still need to build
* the default Android code. Therefore, when attempting to include/exclude
* something from the NDK variant check first that we are building for
* Android then check the status of the NDK define.
*/
#if defined(SK_BUILD_FOR_ANDROID_NDK) && !defined(SK_BUILD_FOR_ANDROID)
#define SK_BUILD_FOR_ANDROID
#endif
//////////////////////////////////////////////////////////////////////
#if !defined(SK_DEBUG) && !defined(SK_RELEASE)

View File

@ -335,10 +335,34 @@ struct SK_API SkRect {
return r;
}
/** Return true if the rectangle's width or height are <= 0
*/
bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
bool hasValidCoordinates() const;
/**
* Return true if the rectangle's width or height are <= 0
*/
bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
/**
* Returns true iff all values in the rect are finite. If any are
* infinite or NaN (or SK_FixedNaN when SkScalar is fixed) then this
* returns false.
*/
bool isFinite() const {
#ifdef SK_SCALAR_IS_FLOAT
// x * 0 will be NaN iff x is infinity or NaN.
// a + b will be NaN iff either a or b is NaN.
float value = fLeft * 0 + fTop * 0 + fRight * 0 + fBottom * 0;
// value is either NaN or it is finite (zero).
// value==value will be true iff value is not NaN
return value == value;
#else
// use bit-or for speed, since we don't care about short-circuting the
// tests, and we expect the common case will be that we need to check all.
int isNaN = (SK_FixedNaN == fLeft) | (SK_FixedNaN == fTop) |
(SK_FixedNaN == fRight) | (SK_FixedNaN == fBottom);
return !isNaN;
#endif
}
SkScalar left() const { return fLeft; }
SkScalar top() const { return fTop; }
SkScalar right() const { return fRight; }

View File

@ -86,9 +86,9 @@ public:
const SkIRect& getBounds() const { return fBounds; }
/**
* Returns true if the region is non-empty, and if so, sets the specified
* path to the boundary(s) of the region. If the region is empty, then
* this returns false, and path is left unmodified.
* Returns true if the region is non-empty, and if so, appends the
* boundary(s) of the region to the specified path.
* If the region is empty, returns false, and path is left unmodified.
*/
bool getBoundaryPath(SkPath* path) const;
@ -283,7 +283,7 @@ public:
*/
bool op(const SkRegion& rgna, const SkRegion& rgnb, Op op);
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
/** Returns a new char* containing the list of rectangles in this region
*/
char* toString();

View File

@ -92,7 +92,7 @@
*
* Either way, it's not good.
*/
SkASSERT(!"looks like you passed an SkScalar into SkIntToScalar");
SkDEBUGFAIL("looks like you passed an SkScalar into SkIntToScalar");
return (float)0;
}
#else // not SK_DEBUG
@ -119,7 +119,7 @@
#define SkScalarFloorToScalar(x) sk_float_floor(x)
#define SkScalarCeilToScalar(x) sk_float_ceil(x)
#define SkScalarRoundToScalar(x) sk_float_round(x)
#define SkScalarRoundToScalar(x) sk_float_floor((x) + 0.5f)
#define SkScalarFloorToInt(x) sk_float_floor2int(x)
#define SkScalarCeilToInt(x) sk_float_ceil2int(x)

View File

@ -157,33 +157,36 @@ struct SkGlyph {
class SkScalerContext {
public:
enum Flags {
kFrameAndFill_Flag = 0x01,
kDevKernText_Flag = 0x02,
kGammaForBlack_Flag = 0x04, // illegal to set both Gamma flags
kGammaForWhite_Flag = 0x08, // illegal to set both Gamma flags
kFrameAndFill_Flag = 0x0001,
kDevKernText_Flag = 0x0002,
kEmbeddedBitmapText_Flag = 0x0004,
kEmbolden_Flag = 0x0008,
kSubpixelPositioning_Flag = 0x0010,
kAutohinting_Flag = 0x0020,
kVertical_Flag = 0x0040,
// together, these two flags resulting in a two bit value which matches
// up with the SkPaint::Hinting enum.
kHintingBit1_Flag = 0x10,
kHintingBit2_Flag = 0x20,
kEmbeddedBitmapText_Flag = 0x40,
kEmbolden_Flag = 0x80,
kSubpixelPositioning_Flag = 0x100,
kAutohinting_Flag = 0x200,
kHinting_Shift = 7, // to shift into the other flags above
kHintingBit1_Flag = 0x0080,
kHintingBit2_Flag = 0x0100,
// these should only ever be set if fMaskFormat is LCD16 or LCD32
kLCD_Vertical_Flag = 0x400, // else Horizontal
kLCD_BGROrder_Flag = 0x800, // else RGB order
kLCD_Vertical_Flag = 0x0200, // else Horizontal
kLCD_BGROrder_Flag = 0x0400, // else RGB order
// experimental
kForceAA_Flag = 0x1000
// luminance : 0 for black text, kLuminance_Max for white text
kLuminance_Shift = 11, // to shift into the other flags above
kLuminance_Bits = 3, // ensure Flags doesn't exceed 16bits
};
private:
// computed values
enum {
kHintingMask = kHintingBit1_Flag | kHintingBit2_Flag
kHinting_Mask = kHintingBit1_Flag | kHintingBit2_Flag,
kLuminance_Max = (1 << kLuminance_Bits) - 1,
kLuminance_Mask = kLuminance_Max << kLuminance_Shift,
};
public:
struct Rec {
uint32_t fOrigFontID;
uint32_t fFontID;
@ -203,11 +206,29 @@ public:
void getSingleMatrix(SkMatrix*) const;
SkPaint::Hinting getHinting() const {
return static_cast<SkPaint::Hinting>((fFlags & kHintingMask) >> 4);
unsigned hint = (fFlags & kHinting_Mask) >> kHinting_Shift;
return static_cast<SkPaint::Hinting>(hint);
}
void setHinting(SkPaint::Hinting hinting) {
fFlags = (fFlags & ~kHintingMask) | (hinting << 4);
fFlags = (fFlags & ~kHinting_Mask) | (hinting << kHinting_Shift);
}
unsigned getLuminanceBits() const {
return (fFlags & kLuminance_Mask) >> kLuminance_Shift;
}
void setLuminanceBits(unsigned lum) {
SkASSERT(lum <= kLuminance_Max);
fFlags = (fFlags & ~kLuminance_Mask) | (lum << kLuminance_Shift);
}
U8CPU getLuminanceByte() const {
SkASSERT(3 == kLuminance_Bits);
unsigned lum = this->getLuminanceBits();
lum |= (lum << kLuminance_Bits);
lum |= (lum << kLuminance_Bits*2);
return lum >> (4*kLuminance_Bits - 8);
}
SkMask::Format getFormat() const {
@ -222,6 +243,10 @@ public:
return (SkMask::Format)fRec.fMaskFormat;
}
bool isSubpixel() const {
return SkToBool(fRec.fFlags & kSubpixelPositioning_Flag);
}
// remember our glyph offset/base
void setBaseGlyphCount(unsigned baseGlyphCount) {
fBaseGlyphCount = baseGlyphCount;
@ -232,7 +257,7 @@ public:
fact correspond to a different font/context. In that case, we use the
base-glyph-count to know how to translate back into local glyph space.
*/
uint16_t charToGlyphID(SkUnichar uni);
uint16_t charToGlyphID(SkUnichar uni);
/** Map the glyphID to its glyph index, and then to its char code. Unmapped
glyphs return zero.

View File

@ -96,6 +96,15 @@ public:
*/
virtual uint32_t getFlags() { return 0; }
/**
* Returns true if the shader is guaranteed to produce only opaque
* colors, subject to the SkPaint using the shader to apply an opaque
* alpha value. Subclasses should override this to allow some
* optimizations. isOpaque() can be called at any time, unlike getFlags,
* which only works properly when the context is set.
*/
virtual bool isOpaque() const { return false; }
/**
* Return the alpha associated with the data returned by shadeSpan16(). If
* kHasSpan16_Flag is not set, this value is meaningless.

View File

@ -38,6 +38,8 @@ public:
// public for Registrar
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
virtual void onDraw(SkCanvas*);

View File

@ -299,8 +299,8 @@ protected:
void init(const T* array, int count,
void* preAllocStorage, int preAllocOrReserveCount) {
GrAssert(count >= 0);
GrAssert(preAllocOrReserveCount >= 0);
SkASSERT(count >= 0);
SkASSERT(preAllocOrReserveCount >= 0);
fCount = count;
fReserveCount = (preAllocOrReserveCount > 0) ?
preAllocOrReserveCount :
@ -311,8 +311,8 @@ protected:
fAllocCount = fReserveCount;
fMemArray = preAllocStorage;
} else {
fAllocCount = GrMax(fCount, fReserveCount);
fMemArray = GrMalloc(fAllocCount * sizeof(T));
fAllocCount = SkMax32(fCount, fReserveCount);
fMemArray = sk_malloc_throw(fAllocCount * sizeof(T));
}
SkTArrayExt::copy(this, array);

View File

@ -91,7 +91,17 @@ public:
}
bool isEmpty() const { return fCount == 0; }
/**
* Return the number of elements in the array
*/
int count() const { return fCount; }
/**
* return the number of bytes in the array: count * sizeof(T)
*/
size_t bytes() const { return fCount * sizeof(T); }
T* begin() const { return fArray; }
T* end() const { return fArray ? fArray + fCount : NULL; }
T& operator[](int index) const {

View File

@ -21,7 +21,7 @@ public:
typedef T (*Factory)(P);
SkTRegistry(Factory fact) {
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
// work-around for double-initialization bug
{
SkTRegistry* reg = gHead;

View File

@ -10,7 +10,7 @@
#ifndef SkThread_platform_DEFINED
#define SkThread_platform_DEFINED
#if defined(ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
#include <utils/threads.h>
#include <utils/Atomic.h>

View File

@ -93,6 +93,7 @@ inline void operator delete(void* p) {
#ifdef SK_DEBUG
#define SkASSERT(cond) SK_DEBUGBREAK(cond)
#define SkDEBUGFAIL(message) SkASSERT(false && message)
#define SkDEBUGCODE(code) code
#define SkDECLAREPARAM(type, var) , type var
#define SkPARAM(var) , var
@ -101,6 +102,7 @@ inline void operator delete(void* p) {
#define SkAssertResult(cond) SkASSERT(cond)
#else
#define SkASSERT(cond)
#define SkDEBUGFAIL(message)
#define SkDEBUGCODE(code)
#define SkDEBUGF(args)
#define SkDECLAREPARAM(type, var)
@ -216,6 +218,8 @@ static inline bool SkIsU16(long x) {
*/
#define SkAlign4(x) (((x) + 3) >> 2 << 2)
#define SkIsAlign4(x) (((x) & 3) == 0)
typedef uint32_t SkFourByteTag;
#define SkSetFourByteTag(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))

View File

@ -32,7 +32,7 @@ void sk_memset32_portable(uint32_t dst[], uint32_t value, int count);
typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count);
SkMemset32Proc SkMemset32GetPlatformProc();
#if defined(ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
#include "cutils/memory.h"
#define sk_memset16(dst, value, count) android_memset16(dst, value, (count) << 1)
@ -91,6 +91,21 @@ size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL);
size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues,
char utf8[] = NULL);
inline bool SkUnichar_IsVariationSelector(SkUnichar uni) {
/* The 'true' ranges are:
* 0x180B <= uni <= 0x180D
* 0xFE00 <= uni <= 0xFE0F
* 0xE0100 <= uni <= 0xE01EF
*/
if (uni < 0x180B || uni > 0xE01EF) {
return false;
}
if ((uni > 0x180D && uni < 0xFE00) || (uni > 0xFE0F && uni < 0xE0100)) {
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
class SkAutoTrace {

View File

@ -131,6 +131,18 @@ public:
*/
static bool AsMode(SkXfermode*, Mode* mode);
/**
* Returns true if the xfermode claims to be the specified Mode. This works
* correctly even if the xfermode is NULL (which equates to kSrcOver.) Thus
* you can say this without checking for a null...
*
* If (SkXfermode::IsMode(paint.getXfermode(),
* SkXfermode::kDstOver_Mode)) {
* ...
* }
*/
static bool IsMode(SkXfermode* xfer, Mode mode);
/** Return an SkXfermode object for the specified mode.
*/
static SkXfermode* Create(Mode mode);
@ -160,6 +172,7 @@ public:
return AsMode(xfer, mode);
}
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkXfermode(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {}

View File

@ -57,21 +57,23 @@ public:
SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
// override from SkPathEffect
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
virtual bool filterPath(SkPath*, const SkPath&, SkScalar* width) SK_OVERRIDE;
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkPath1DPathEffect, (buffer));
}
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkPath1DPathEffect(SkFlattenableReadBuffer& buffer);
// overrides from Sk1DPathEffect
virtual SkScalar begin(SkScalar contourLength);
virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&);
virtual SkScalar begin(SkScalar contourLength) SK_OVERRIDE;
virtual SkScalar next(SkPath*, SkScalar distance, SkPathMeasure&) SK_OVERRIDE;
// overrides from SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer& );
virtual Factory getFactory() { return CreateProc; }
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE { return CreateProc; }
private:
SkPath fPath; // copied from constructor

View File

@ -19,11 +19,11 @@ public:
Sk2DPathEffect(const SkMatrix& mat);
// overrides
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
virtual bool filterPath(SkPath*, const SkPath&, SkScalar* width) SK_OVERRIDE;
// overrides from SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer&);
virtual Factory getFactory();
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE;
protected:
/** New virtual, to be overridden by subclasses.
@ -47,6 +47,8 @@ protected:
// protected so that subclasses can call this during unflattening
Sk2DPathEffect(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
private:
SkMatrix fMatrix, fInverse;
// illegal
@ -69,12 +71,14 @@ public:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkPath2DPathEffect(SkFlattenableReadBuffer& buffer);
virtual void flatten(SkFlattenableWriteBuffer&);
virtual Factory getFactory();
virtual void next(const SkPoint& loc, int u, int v, SkPath* dst);
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE;
virtual void next(const SkPoint&, int u, int v, SkPath* dst) SK_OVERRIDE;
private:
SkPath fPath;

View File

@ -0,0 +1,30 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkArithmeticMode_DEFINED
#define SkArithmeticMode_DEFINED
#include "SkXfermode.h"
class SkArithmeticMode : public SkXfermode {
public:
/**
* result = clamp[k1 * src * dst + k2 * src + k3 * dst + k4]
*
* src and dst are treated as being [0.0 .. 1.0]. The polynomial is
* evaluated on their unpremultiplied components.
*
* k1=k2=k3=0, k4=1.0 results in returning opaque white
* k1=k3=k4=0, k2=1.0 results in returning the src
* k1=k2=k4=0, k3=1.0 results in returning the dst
*/
static SkXfermode* Create(SkScalar k1, SkScalar k2,
SkScalar k3, SkScalar k4);
};
#endif

View File

@ -43,22 +43,24 @@ public:
// overrides from SkXfermode
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
const SkAlpha aa[]) SK_OVERRIDE;
virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
const SkAlpha aa[]) SK_OVERRIDE;
virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
const SkAlpha aa[]) SK_OVERRIDE;
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
const SkAlpha aa[]) SK_OVERRIDE;
// overrides from SkFlattenable
virtual Factory getFactory();
virtual void flatten(SkFlattenableWriteBuffer&);
virtual Factory getFactory() SK_OVERRIDE;
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkAvoidXfermode, (buffer));
}
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkAvoidXfermode(SkFlattenableReadBuffer&);

View File

@ -48,6 +48,7 @@ public:
return SkNEW_ARGS(SkBlurDrawLooper, (buffer));
}
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkBlurDrawLooper(SkFlattenableReadBuffer&);

View File

@ -0,0 +1,40 @@
/*
* Copyright 2011 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBlurImageFilter_DEFINED
#define SkBlurImageFilter_DEFINED
#include "SkImageFilter.h"
class SK_API SkBlurImageFilter : public SkImageFilter {
public:
SkBlurImageFilter(SkScalar sigmaX, SkScalar sigmaY);
virtual bool asABlur(SkSize* sigma) const SK_OVERRIDE;
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkBlurImageFilter, (buffer));
}
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
explicit SkBlurImageFilter(SkFlattenableReadBuffer& buffer);
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
virtual void flatten(SkFlattenableWriteBuffer& buffer) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE { return CreateProc; }
private:
SkSize fSigma;
typedef SkImageFilter INHERITED;
};
#endif

View File

@ -55,6 +55,8 @@ public:
SkScalar ambient, SkScalar specular,
SkScalar blurRadius);
SK_DECLARE_FLATTENABLE_REGISTRAR()
private:
SkBlurMaskFilter(); // can't be instantiated
};

View File

@ -23,12 +23,13 @@ public:
void setArray(const SkScalar array[20]);
// overrides from SkColorFilter
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]);
virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]);
virtual uint32_t getFlags();
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) SK_OVERRIDE;
virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]) SK_OVERRIDE;
virtual uint32_t getFlags() SK_OVERRIDE;
virtual bool asColorMatrix(SkScalar matrix[20]) SK_OVERRIDE;
// overrides for SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer& buffer);
virtual void flatten(SkFlattenableWriteBuffer& buffer) SK_OVERRIDE;
struct State {
int32_t fArray[20];
@ -38,6 +39,8 @@ public:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
// overrides for SkFlattenable
virtual Factory getFactory();

View File

@ -37,6 +37,8 @@ public:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkCornerPathEffect(SkFlattenableReadBuffer&);

View File

@ -39,6 +39,8 @@ public:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkDashPathEffect(SkFlattenableReadBuffer&);

View File

@ -36,6 +36,8 @@ public:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkDiscretePathEffect(SkFlattenableReadBuffer&);

View File

@ -0,0 +1,16 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkEffects_DEFINED
#define SkEffects_DEFINED
class SkEffects {
public:
static void Init();
};
#endif

View File

@ -41,6 +41,8 @@ public:
// This method is not exported to java.
virtual void flatten(SkFlattenableWriteBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkEmbossMaskFilter(SkFlattenableReadBuffer&);

View File

@ -112,6 +112,8 @@ public:
static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
const SkColor colors[], const SkScalar pos[],
int count, SkUnitMapper* mapper = NULL);
SK_DECLARE_FLATTENABLE_REGISTRAR()
};
#endif

View File

@ -138,6 +138,8 @@ public:
// public for Registrar
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
// overrides
virtual void onDraw(SkCanvas*);

View File

@ -22,7 +22,8 @@ public:
* Bits specifies which aspects of the layer's paint should replace the
* corresponding aspects on the draw's paint.
* kEntirePaint_Bits means use the layer's paint completely.
* 0 means ignore the layer's paint.
* 0 means ignore the layer's paint... except that LayerInfo's fFlagsMask
* and fColorMode are always applied.
*/
enum Bits {
kStyle_Bit = 1 << 0, //!< use this layer's Style/stroke settings
@ -33,7 +34,15 @@ public:
kColorFilter_Bit = 1 << 5, //!< use this layer's colorfilter
kXfermode_Bit = 1 << 6, //!< use this layer's xfermode
kEntirePaint_Bits = -1, //!< use this layer's paint entirely
/**
* Use the layer's paint entirely, with these exceptions:
* - We never override the draw's paint's text_encoding, since that is
* used to interpret the text/len parameters in draw[Pos]Text.
* - Flags and Color are always computed using the LayerInfo's
* fFlagsMask and fColorMode.
*/
kEntirePaint_Bits = -1,
};
typedef int32_t BitFlags;
@ -97,6 +106,8 @@ public:
return SkNEW_ARGS(SkLayerDrawLooper, (buffer));
}
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkLayerDrawLooper(SkFlattenableReadBuffer&);

View File

@ -38,6 +38,8 @@ public:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkLayerRasterizer(SkFlattenableReadBuffer&);

View File

@ -29,6 +29,8 @@ public:
return SkNEW_ARGS(SkPixelXorXfermode, (buffer));
}
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
// override from SkXfermode
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst);

View File

@ -45,7 +45,7 @@ public:
kMultiply_Mode, //!< [Sa * Da, Sc * Dc]
kScreen_Mode, //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
kAdd_Mode, //!< Saturate(S + D)
#ifdef ANDROID
#ifdef SK_BUILD_FOR_ANDROID
kOverlay_Mode,
#endif

View File

@ -47,6 +47,8 @@ public:
// public for Registrar
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkRectShape(SkFlattenableReadBuffer&);

View File

@ -0,0 +1,34 @@
#ifndef SkTableColorFilter_DEFINED
#define SkTableColorFilter_DEFINED
#include "SkColorFilter.h"
class SkTableColorFilter {
public:
/**
* Create a table colorfilter, copying the table into the filter, and
* applying it to all 4 components.
* a' = table[a];
* r' = table[r];
* g' = table[g];
* b' = table[b];
* Compoents are operated on in unpremultiplied space. If the incomming
* colors are premultiplied, they are temporarily unpremultiplied, then
* the table is applied, and then the result is remultiplied.
*/
static SkColorFilter* Create(const uint8_t table[256]);
/**
* Create a table colorfilter, with a different table for each
* component [A, R, G, B]. If a given table is NULL, then it is
* treated as identity, with the component left unchanged. If a table
* is not null, then its contents are copied into the filter.
*/
static SkColorFilter* CreateARGB(const uint8_t tableA[256],
const uint8_t tableR[256],
const uint8_t tableG[256],
const uint8_t tableB[256]);
};
#endif

View File

@ -0,0 +1,157 @@
#ifndef _SkTestImageFilters_h
#define _SkTestImageFilters_h
#include "SkImageFilter.h"
class SkOffsetImageFilter : public SkImageFilter {
public:
SkOffsetImageFilter(SkScalar dx, SkScalar dy) {
fOffset.set(dx, dy);
}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkOffsetImageFilter, (buffer));
}
protected:
SkOffsetImageFilter(SkFlattenableReadBuffer& buffer);
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) SK_OVERRIDE;
// overrides from SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE;
private:
SkVector fOffset;
typedef SkImageFilter INHERITED;
};
class SkComposeImageFilter : public SkImageFilter {
public:
SkComposeImageFilter(SkImageFilter* outer, SkImageFilter* inner) {
fOuter = outer;
fInner = inner;
SkSafeRef(outer);
SkSafeRef(inner);
}
virtual ~SkComposeImageFilter();
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkComposeImageFilter, (buffer));
}
protected:
SkComposeImageFilter(SkFlattenableReadBuffer& buffer);
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) SK_OVERRIDE;
// overrides from SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE;
private:
SkImageFilter* fOuter;
SkImageFilter* fInner;
typedef SkImageFilter INHERITED;
};
#include "SkXfermode.h"
class SkMergeImageFilter : public SkImageFilter {
public:
SkMergeImageFilter(SkImageFilter* first, SkImageFilter* second,
SkXfermode::Mode = SkXfermode::kSrcOver_Mode);
SkMergeImageFilter(SkImageFilter* const filters[], int count,
const SkXfermode::Mode modes[] = NULL);
virtual ~SkMergeImageFilter();
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkMergeImageFilter, (buffer));
}
protected:
SkMergeImageFilter(SkFlattenableReadBuffer& buffer);
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) SK_OVERRIDE;
// overrides from SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE;
private:
SkImageFilter** fFilters;
uint8_t* fModes; // SkXfermode::Mode
int fCount;
// private storage, to avoid dynamically allocating storage for our copy
// of the filters and modes (unless fCount is so large we can't fit).
intptr_t fStorage[16];
void initAlloc(int count, bool hasModes);
void init(SkImageFilter* const [], int count, const SkXfermode::Mode []);
typedef SkImageFilter INHERITED;
};
class SkColorFilter;
class SkColorFilterImageFilter : public SkImageFilter {
public:
SkColorFilterImageFilter(SkColorFilter* cf) : fColorFilter(cf) {
SkSafeRef(cf);
}
virtual ~SkColorFilterImageFilter();
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkColorFilterImageFilter, (buffer));
}
protected:
SkColorFilterImageFilter(SkFlattenableReadBuffer& buffer);
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
// overrides from SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE;
private:
SkColorFilter* fColorFilter;
typedef SkImageFilter INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
// Fun mode that scales down (only) and then scales back up to look pixelated
class SkDownSampleImageFilter : public SkImageFilter {
public:
SkDownSampleImageFilter(SkScalar scale) : fScale(scale) {}
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkDownSampleImageFilter, (buffer));
}
protected:
SkDownSampleImageFilter(SkFlattenableReadBuffer& buffer);
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
// overrides from SkFlattenable
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
virtual Factory getFactory() SK_OVERRIDE;
private:
SkScalar fScale;
typedef SkImageFilter INHERITED;
};
#endif

View File

@ -15,19 +15,18 @@
class SkTransparentShader : public SkShader {
public:
SkTransparentShader() {}
virtual uint32_t getFlags();
virtual uint32_t getFlags() SK_OVERRIDE;
virtual bool setContext( const SkBitmap& device,
const SkPaint& paint,
const SkMatrix& matrix);
virtual void shadeSpan(int x, int y, SkPMColor[], int count);
virtual void shadeSpan16(int x, int y, uint16_t span[], int count);
const SkMatrix& matrix) SK_OVERRIDE;
virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
// overrides for SkFlattenable
virtual Factory getFactory() { return Create; }
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
}
virtual Factory getFactory() SK_OVERRIDE;
virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
private:
// these are a cache from the call to setContext()
const SkBitmap* fDevice;

View File

@ -19,15 +19,12 @@
*/
typedef uint32_t GrColor;
// indices for address a GrColor as an array of bytes
#define GrColor_INDEX_R 0
#define GrColor_INDEX_G 1
#define GrColor_INDEX_B 2
#define GrColor_INDEX_A 3
// shfit amount to assign a component to a GrColor int
// shift amount to assign a component to a GrColor int
// These shift values are chosen for compatibility with GL attrib arrays
// ES doesn't allow BGRA vertex attrib order so if they were not in this order
// we'd have to swizzle in shaders. Note the assumption that the cpu is little
// endian.
#define GrColor_SHIFT_R 0
#define GrColor_SHIFT_G 8
#define GrColor_SHIFT_B 16

View File

@ -61,7 +61,7 @@
#undef GR_IOS_BUILD
#define GR_IOS_BUILD 1
// #error "IOS"
#elif (defined(ANDROID_NDK) && ANDROID_NDK) || defined(ANDROID)
#elif defined(SK_BUILD_FOR_ANDROID)
#undef GR_ANDROID_BUILD
#define GR_ANDROID_BUILD 1
// #error "ANDROID"
@ -220,12 +220,12 @@ extern GR_API void GrPrintf(const char format[], ...);
*/
#if !defined(GR_ALWAYSBREAK)
#if GR_WIN32_BUILD
#define GR_ALWAYSBREAK __debugbreak()
#define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
#else
// TODO: do other platforms really not have continuable breakpoints?
// sign extend for 64bit architectures to be sure this is
// in the high address range
#define GR_ALWAYSBREAK *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
#define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
#endif
#endif
@ -351,7 +351,7 @@ inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); }
* program.
*/
#if !defined(GR_AGGRESSIVE_SHADER_OPTS)
#define GR_AGGRESSIVE_SHADER_OPTS 0
#define GR_AGGRESSIVE_SHADER_OPTS 1
#endif
/**
@ -380,6 +380,7 @@ inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); }
#define GR_MAX_OFFSCREEN_AA_SIZE 256
#endif
///////////////////////////////////////////////////////////////////////////////
// tail section:
//

View File

@ -39,11 +39,6 @@ public:
static GrContext* Create(GrEngine engine,
GrPlatform3DContext context3D);
/**
* Helper to create a opengl-shader based context
*/
static GrContext* CreateGLShaderContext();
virtual ~GrContext();
/**
@ -112,24 +107,62 @@ public:
*/
typedef uint64_t TextureKey;
/**
* Create a new entry, based on the specified key and texture, and return
* its "locked" entry. Must call be balanced with an unlockTexture() call.
*
* @param key A client-generated key that identifies the contents
* of the texture. Respecified to findAndLockTexture
* for subsequent uses of the texture.
* @param sampler The sampler state used to draw a texture may be used
* to determine how to store the pixel data in the texture
* cache. (e.g. different versions may exist for different
* wrap modes on GPUs with limited or no NPOT texture
* support). Only the wrap and filter fields are used. NULL
* implies clamp wrap modes and nearest filtering.
* @param desc Description of the texture properties.
* @param srcData Pointer to the pixel values.
* @param rowBytes The number of bytes between rows of the texture. Zero
* implies tightly packed rows.
*/
TextureCacheEntry createAndLockTexture(TextureKey key,
const GrSamplerState* sampler,
const GrTextureDesc& desc,
void* srcData, size_t rowBytes);
/**
* Search for an entry based on key and dimensions. If found, "lock" it and
* return it. The entry's texture() function will return NULL if not found.
* Must call be balanced with an unlockTexture() call.
* Must be balanced with an unlockTexture() call.
*
* @param key A client-generated key that identifies the contents
* of the texture.
* @param width The width of the texture in pixels as specifed in
* the GrTextureDesc originally passed to
* createAndLockTexture
* @param width The height of the texture in pixels as specifed in
* the GrTextureDesc originally passed to
* createAndLockTexture
* @param sampler The sampler state used to draw a texture may be used
* to determine the cache entry used. (e.g. different
* versions may exist for different wrap modes on GPUs with
* limited or no NPOT texture support). Only the wrap and
* filter fields are used. NULL implies clamp wrap modes
* and nearest filtering.
*/
TextureCacheEntry findAndLockTexture(TextureKey key,
int width,
int height,
const GrSamplerState&);
const GrSamplerState* sampler);
/**
* Create a new entry, based on the specified key and texture, and return
* its "locked" entry. Must call be balanced with an unlockTexture() call.
* Determines whether a texture is in the cache. If the texture is found it
* will not be locked or returned. This call does not affect the priority of
* the texture for deletion.
*/
TextureCacheEntry createAndLockTexture(TextureKey key,
const GrSamplerState&,
const GrTextureDesc&,
void* srcData, size_t rowBytes);
bool isTextureInCache(TextureKey key,
int width,
int height,
const GrSamplerState*) const;
/**
* Enum that determines how closely a returned scratch texture must match
@ -182,7 +215,7 @@ public:
/**
* Returns true if the specified use of an indexed texture is supported.
*/
bool supportsIndex8PixelConfig(const GrSamplerState&,
bool supportsIndex8PixelConfig(const GrSamplerState*,
int width,
int height) const;
@ -238,6 +271,35 @@ public:
// Platform Surfaces
/**
* Wraps an existing texture with a GrTexture object.
*
* OpenGL: if the object is a texture Gr may change its GL texture params
* when it is drawn.
*
* @param desc description of the object to create.
*
* @return GrTexture object or NULL on failure.
*/
GrTexture* createPlatformTexture(const GrPlatformTextureDesc& desc);
/**
* Wraps an existing render target with a GrRenderTarget object. It is
* similar to createPlatformTexture but can be used to draw into surfaces
* that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
* the client will resolve to a texture).
*
* @param desc description of the object to create.
*
* @return GrTexture object or NULL on failure.
*/
GrRenderTarget* createPlatformRenderTarget(
const GrPlatformRenderTargetDesc& desc);
/**
* This interface is depracted and will be removed in a future revision.
* Callers should use createPlatformTexture or createPlatformRenderTarget
* instead.
*
* Wraps an existing 3D API surface in a GrObject. desc.fFlags determines
* the type of object returned. If kIsTexture is set the returned object
* will be a GrTexture*. Otherwise, it will be a GrRenderTarget*. If both
@ -421,10 +483,10 @@ public:
* FlushBits.
*/
void flush(int flagsBitfield = 0);
/**
* Reads a rectangle of pixels from a render target.
* @param renderTarget the render target to read from. NULL means the
* @param target the render target to read from. NULL means the
* current render target.
* @param left left edge of the rectangle to read (inclusive)
* @param top top edge of the rectangle to read (inclusive)
@ -432,39 +494,94 @@ public:
* @param height height of rectangle to read in pixels.
* @param config the pixel config of the destination buffer
* @param buffer memory to read the rectangle into.
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*
* @return true if the read succeeded, false if not. The read can fail
* because of a unsupported pixel config or because no render
* because of an unsupported pixel config or because no render
* target is currently set.
*/
bool readRenderTargetPixels(GrRenderTarget* target,
int left, int top, int width, int height,
GrPixelConfig config, void* buffer);
GrPixelConfig config, void* buffer,
size_t rowBytes) {
return this->internalReadRenderTargetPixels(target, left, top,
width, height,
config, buffer,
rowBytes, 0);
}
/**
* Copy the src pixels [buffer, rowbytes, pixelconfig] into a render target
* at the specified rectangle.
* @param target the render target to write into. NULL means the
* current render target.
* @param left left edge of the rectangle to write (inclusive)
* @param top top edge of the rectangle to write (inclusive)
* @param width width of rectangle to write in pixels.
* @param height height of rectangle to write in pixels.
* @param config the pixel config of the source buffer
* @param buffer memory to read the rectangle from.
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*/
void writeRenderTargetPixels(GrRenderTarget* target,
int left, int top, int width, int height,
GrPixelConfig config, const void* buffer,
size_t rowBytes) {
this->internalWriteRenderTargetPixels(target, left, top, width, height,
config, buffer, rowBytes, 0);
}
/**
* Reads a rectangle of pixels from a texture.
* @param texture the render target to read from.
* @param texture the texture to read from.
* @param left left edge of the rectangle to read (inclusive)
* @param top top edge of the rectangle to read (inclusive)
* @param width width of rectangle to read in pixels.
* @param height height of rectangle to read in pixels.
* @param config the pixel config of the destination buffer
* @param buffer memory to read the rectangle into.
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*
* @return true if the read succeeded, false if not. The read can fail
* because of a unsupported pixel config.
* because of an unsupported pixel config.
*/
bool readTexturePixels(GrTexture* target,
bool readTexturePixels(GrTexture* texture,
int left, int top, int width, int height,
GrPixelConfig config, void* buffer);
GrPixelConfig config, void* buffer,
size_t rowBytes) {
return this->internalReadTexturePixels(texture, left, top,
width, height,
config, buffer, rowBytes, 0);
}
/**
* Copy the src pixels [buffer, stride, pixelconfig] into the current
* render-target at the specified rectangle.
* Writes a rectangle of pixels to a texture.
* @param texture the render target to read from.
* @param left left edge of the rectangle to write (inclusive)
* @param top top edge of the rectangle to write (inclusive)
* @param width width of rectangle to write in pixels.
* @param height height of rectangle to write in pixels.
* @param config the pixel config of the source buffer
* @param buffer memory to read pixels from
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*/
void writePixels(int left, int top, int width, int height,
GrPixelConfig, const void* buffer, size_t stride);
void writeTexturePixels(GrTexture* texture,
int left, int top, int width, int height,
GrPixelConfig config, const void* buffer,
size_t rowBytes) {
this->internalWriteTexturePixels(texture, left, top, width, height,
config, buffer, rowBytes, 0);
}
/**
* Copies all texels from one texture to another.
* @param src the texture to copy from.
* @param dst the render target to copy to.
*/
void copyTexture(GrTexture* src, GrRenderTarget* dst);
/**
* Applies a 1D convolution kernel in the X direction to a rectangle of
* pixels from a given texture.
@ -581,7 +698,7 @@ private:
void flushDrawBuffer();
static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
void setPaint(const GrPaint& paint, GrDrawTarget* target);
GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
@ -627,7 +744,43 @@ private:
float imageIncrement[2],
const float* kernel,
int kernelWidth);
/**
* Flags to the internal read/write pixels funcs
*/
enum PixelOpsFlags {
kDontFlush_PixelOpsFlag = 0x1,
};
bool internalReadRenderTargetPixels(GrRenderTarget* target,
int left, int top,
int width, int height,
GrPixelConfig config, void* buffer,
size_t rowBytes, uint32_t flags);
void internalWriteRenderTargetPixels(GrRenderTarget* target,
int left, int top,
int width, int height,
GrPixelConfig, const void* buffer,
size_t rowBytes, uint32_t flags);
bool internalReadTexturePixels(GrTexture* texture,
int left, int top,
int width, int height,
GrPixelConfig config, void* buffer,
size_t rowBytes, uint32_t flags);
void internalWriteTexturePixels(GrTexture* texture,
int left, int top,
int width, int height,
GrPixelConfig config, const void* buffer,
size_t rowBytes, uint32_t flags);
// needed for access to internalWriteTexturePixels. TODO: make GrContext
// be a facade for an internal class. Then functions that are public on the
// internal class would have only be callable in src/gpu. The facade would
// only have to functions necessary for clients.
friend class GrAtlas;
// computes vertex layout bits based on the paint. If paint expresses
// a texture for a stage, the stage coords will be bound to postitions
// unless hasTexCoords[s]==true in which case stage s's input coords

View File

@ -77,6 +77,15 @@
* It is not extern "C".
* The GrGLInterface field fCallback specifies the function ptr and there is an
* additional field fCallbackData of type intptr_t for client data.
*
* GR_GL_RGBA_8888_PIXEL_OPS_SLOW: Set this to 1 if it is known that performing
* glReadPixels / glTex(Sub)Image with format=GL_RGBA, type=GL_UNISIGNED_BYTE is
* significantly slower than format=GL_BGRA, type=GL_UNISIGNED_BYTE.
*
* GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL: Set this to 1 if calling
* glReadPixels to read the entire framebuffer is faster than calling it with
* the same sized rectangle but with a framebuffer bound that is larger than
* the rectangle read.
*/
#if !defined(GR_GL_LOG_CALLS)
@ -111,24 +120,20 @@
#define GR_GL_PER_GL_FUNC_CALLBACK 0
#endif
#if !defined(GR_GL_RGBA_8888_PIXEL_OPS_SLOW)
#define GR_GL_RGBA_8888_PIXEL_OPS_SLOW 0
#endif
#if !defined(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL)
#define GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL 0
#endif
#if(GR_GL_NO_CONSTANT_ATTRIBUTES) && (GR_GL_ATTRIBUTE_MATRICES)
#error "Cannot combine GR_GL_NO_CONSTANT_ATTRIBUTES and GR_GL_ATTRIBUTE_MATRICES"
#endif
////////////////////////////////////////////////////////////////////////////////
/**
* The following macros are used to staticlly configure the default
* GrGLInterface, but should not be used outside of the GrGLInterface
* scaffolding. Undefine here to prevent accidental use.
*/
#undef GR_SUPPORT_GLDESKTOP
#undef GR_SUPPORT_GLES1
#undef GR_SUPPORT_GLES2
#undef GR_SUPPORT_GLES
////////////////////////////////////////////////////////////////////////////////
#if GR_SCALAR_IS_FIXED
#define GrGLType GL_FIXED
#elif GR_SCALAR_IS_FLOAT
@ -150,16 +155,6 @@
#error "unknown GR_TEXT_SCALAR type"
#endif
// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on
// Windows where we match GDI's order).
#ifndef GR_GL_32BPP_COLOR_FORMAT
#if GR_WIN32_BUILD || GR_LINUX_BUILD
#define GR_GL_32BPP_COLOR_FORMAT GR_GL_BGRA
#else
#define GR_GL_32BPP_COLOR_FORMAT GR_GL_RGBA
#endif
#endif
////////////////////////////////////////////////////////////////////////////////
struct GrGLInterface;
@ -224,14 +219,6 @@ extern void GrGLClearErr(const GrGLInterface* gl);
////////////////////////////////////////////////////////////////////////////////
/**
* GrGLResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
* this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
*/
extern void GrGLResetRowLength(const GrGLInterface*);
////////////////////////////////////////////////////////////////////////////////
/**
* Some drivers want the var-int arg to be zero-initialized on input.
*/

View File

@ -8,15 +8,18 @@
#ifndef GrGLConfig_chrome_DEFINED
#define GrGLConfig_chrome_DEFINED
// chrome always assumes BGRA
#define GR_GL_32BPP_COLOR_FORMAT GR_GL_BGRA
// glGetError() forces a sync with gpu process on chrome
#define GR_GL_CHECK_ERROR_START 0
// ANGLE creates a temp VB for vertex attributes not specified per-vertex.
#define GR_GL_NO_CONSTANT_ATTRIBUTES GR_WIN32_BUILD
// For RGBA teximage/readpixels ANGLE will sw-convert to/from BGRA.
#define GR_GL_RGBA_8888_PIXEL_OPS_SLOW GR_WIN32_BUILD
// ANGLE can go faster if the entire fbo is read rather than a subrect
#define GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL GR_WIN32_BUILD
// cmd buffer allocates memory and memsets it to zero when it sees glBufferData
// with NULL.
#define GR_GL_USE_BUFFER_DATA_NULL_HINT 0

View File

@ -174,7 +174,9 @@
#define GR_GL_COLOR_CLEAR_VALUE 0x0C22
#define GR_GL_COLOR_WRITEMASK 0x0C23
#define GR_GL_UNPACK_ALIGNMENT 0x0CF5
#define GR_GL_UNPACK_FLIP_Y 0x9240
#define GR_GL_PACK_ALIGNMENT 0x0D05
#define GR_GL_PACK_REVERSE_ROW_ORDER 0x93A4
#define GR_GL_MAX_TEXTURE_SIZE 0x0D33
#define GR_GL_MAX_VIEWPORT_DIMS 0x0D3A
#define GR_GL_SUBPIXEL_BITS 0x0D50
@ -282,6 +284,9 @@
/* PixelFormat */
#define GR_GL_DEPTH_COMPONENT 0x1902
#define GR_GL_RED 0x1903
#define GR_GL_GREEN 0x1904
#define GR_GL_BLUE 0x1905
#define GR_GL_ALPHA 0x1906
#define GR_GL_RGB 0x1907
#define GR_GL_RGBA 0x1908
@ -289,6 +294,7 @@
#define GR_GL_LUMINANCE 0x1909
#define GR_GL_LUMINANCE_ALPHA 0x190A
#define GR_GL_PALETTE8_RGBA8 0x8B96
#define GR_GL_ALPHA8 0x803C
/* PixelType */
/* GL_UNSIGNED_BYTE */
@ -348,7 +354,9 @@
#define GR_GL_EXTENSIONS 0x1F03
/* Pixel Mode / Transfer */
#define GR_GL_UNPACK_ROW_LENGTH 0x0CF2
#define GR_GL_UNPACK_ROW_LENGTH 0x0CF2
#define GR_GL_PACK_ROW_LENGTH 0x0D02
/* TextureMagFilter */
#define GR_GL_NEAREST 0x2600
@ -362,11 +370,15 @@
#define GR_GL_NEAREST_MIPMAP_LINEAR 0x2702
#define GR_GL_LINEAR_MIPMAP_LINEAR 0x2703
/* TextureUsage */
#define GR_GL_FRAMEBUFFER_ATTACHMENT 0x93A3
/* TextureParameterName */
#define GR_GL_TEXTURE_MAG_FILTER 0x2800
#define GR_GL_TEXTURE_MIN_FILTER 0x2801
#define GR_GL_TEXTURE_WRAP_S 0x2802
#define GR_GL_TEXTURE_WRAP_T 0x2803
#define GR_GL_TEXTURE_USAGE 0x93A2
/* TextureTarget */
/* GL_TEXTURE_2D */
@ -422,10 +434,17 @@
#define GR_GL_CLAMP_TO_EDGE 0x812F
#define GR_GL_MIRRORED_REPEAT 0x8370
/* Texture Swizzle */
#define GR_GL_TEXTURE_SWIZZLE_R 0x8E42
#define GR_GL_TEXTURE_SWIZZLE_G 0x8E43
#define GR_GL_TEXTURE_SWIZZLE_B 0x8E44
#define GR_GL_TEXTURE_SWIZZLE_A 0x8E45
#define GR_GL_TEXTURE_SWIZZLE_RGBA 0x8E46
/* Texture mapping */
#define GR_GL_TEXTURE_ENV 0x2300
#define GR_GL_TEXTURE_ENV_MODE 0x2200
#define GR_GL_TEXTURE_1D 0x0DE0
#define GR_GL_TEXTURE_ENV 0x2300
#define GR_GL_TEXTURE_ENV_MODE 0x2200
#define GR_GL_TEXTURE_1D 0x0DE0
/* GL_TEXTURE_2D */
/* GL_TEXTURE_WRAP_S */
/* GL_TEXTURE_WRAP_T */
@ -614,6 +633,7 @@
#define GR_GL_RGB565 0x8D62
#define GR_GL_RGBA8 0x8058
#define GR_GL_RGB8 0x8051
#define GR_GL_BGRA8 0x93A1
#define GR_GL_SRGB 0x8C40
#define GR_GL_SRGB8 0x8C41
#define GR_GL_SRGB_ALPHA 0x8C42

View File

@ -111,8 +111,7 @@ typedef long GrGLsizeiptr;
enum GrGLBinding {
kDesktop_GrGLBinding = 0x01,
kES1_GrGLBinding = 0x02,
kES2_GrGLBinding = 0x04
kES2_GrGLBinding = 0x02
};
extern "C" {
@ -130,8 +129,6 @@ extern "C" {
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GrGLbitfield mask);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GrGLint s);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClientActiveTextureProc)(GrGLenum texture);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColor4ubProc)(GrGLubyte red, GrGLubyte green, GrGLubyte blue, GrGLubyte alpha);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GrGLuint shader);
@ -146,14 +143,12 @@ extern "C" {
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GrGLsizei n, const GrGLuint* textures);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GrGLboolean flag);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GrGLenum cap);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableClientStateProc)(GrGLenum array);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GrGLuint index);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBufferProc)(GrGLenum mode);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBuffersProc)(GrGLsizei n, const GrGLenum* bufs);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GrGLenum cap);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableClientStateProc)(GrGLenum cap);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GrGLuint index);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEndQueryProc)(GrGLenum target);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFinishProc)();
@ -179,15 +174,11 @@ extern "C" {
typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLoadMatrixfProc)(const GrGLfloat* m);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLMatrixModeProc)(GrGLenum mode);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPointSizeProc)(GrGLfloat size);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLQueryCounterProc)(GrGLuint id, GrGLenum target);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadBufferProc)(GrGLenum src);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShadeModelProc)(GrGLenum mode);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GrGLenum func, GrGLint ref, GrGLuint mask);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask);
@ -195,10 +186,9 @@ extern "C" {
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GrGLenum face, GrGLuint mask);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexCoordPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexEnviProc)(GrGLenum target, GrGLenum pname, GrGLint param);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexImage2DProc)(GrGLenum target, GrGLint level, GrGLint internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLenum format, GrGLenum type, const GrGLvoid* pixels);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexStorage2DProc)(GrGLenum target, GrGLsizei levels, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexSubImage2DProc)(GrGLenum target, GrGLint level, GrGLint xoffset, GrGLint yoffset, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, const GrGLvoid* pixels);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fProc)(GrGLint location, GrGLfloat v0);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GrGLint location, GrGLint v0);
@ -222,7 +212,6 @@ extern "C" {
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GrGLuint program);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
// FBO Extension Functions
@ -278,35 +267,18 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLInterface();
bool validate(GrEngine engine) const;
bool validate() const;
bool supportsDesktop() const {
return 0 != (kDesktop_GrGLBinding & fBindingsExported);
}
bool supportsES1() const {
return 0 != (kES1_GrGLBinding & fBindingsExported);
}
bool supportsES2() const {
return 0 != (kES2_GrGLBinding & fBindingsExported);
}
bool supportsES() const {
return 0 != ((kES1_GrGLBinding | kES2_GrGLBinding) &
fBindingsExported);
}
// Indicator variable specifying the type of GL implementation
// exported: GLES{1|2} or Desktop.
GrGLBinding fBindingsExported;
/// Does this GL support NPOT textures on FBOs?
/// boolean value, or kProbe_GrGLCapability to probe (slowly) at context creation.
int fNPOTRenderTargetSupport;
/// Some GL implementations (PowerVR SGX devices like the iPhone 4)
/// have restrictions on the size of small render targets.
/// kProbe_GrGLCapability to probe (slowly) at context creation.
int fMinRenderTargetHeight;
int fMinRenderTargetWidth;
GrGLActiveTextureProc fActiveTexture;
GrGLAttachShaderProc fAttachShader;
GrGLBeginQueryProc fBeginQuery;
@ -321,8 +293,6 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLClearProc fClear;
GrGLClearColorProc fClearColor;
GrGLClearStencilProc fClearStencil;
GrGLClientActiveTextureProc fClientActiveTexture;
GrGLColor4ubProc fColor4ub;
GrGLColorMaskProc fColorMask;
GrGLColorPointerProc fColorPointer;
GrGLCompileShaderProc fCompileShader;
@ -337,14 +307,12 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLDeleteTexturesProc fDeleteTextures;
GrGLDepthMaskProc fDepthMask;
GrGLDisableProc fDisable;
GrGLDisableClientStateProc fDisableClientState;
GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
GrGLDrawArraysProc fDrawArrays;
GrGLDrawBufferProc fDrawBuffer;
GrGLDrawBuffersProc fDrawBuffers;
GrGLDrawElementsProc fDrawElements;
GrGLEnableProc fEnable;
GrGLEnableClientStateProc fEnableClientState;
GrGLEnableVertexAttribArrayProc fEnableVertexAttribArray;
GrGLEndQueryProc fEndQuery;
GrGLFinishProc fFinish;
@ -370,15 +338,11 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLGetUniformLocationProc fGetUniformLocation;
GrGLLineWidthProc fLineWidth;
GrGLLinkProgramProc fLinkProgram;
GrGLLoadMatrixfProc fLoadMatrixf;
GrGLMatrixModeProc fMatrixMode;
GrGLPixelStoreiProc fPixelStorei;
GrGLPointSizeProc fPointSize;
GrGLQueryCounterProc fQueryCounter;
GrGLReadBufferProc fReadBuffer;
GrGLReadPixelsProc fReadPixels;
GrGLScissorProc fScissor;
GrGLShadeModelProc fShadeModel;
GrGLShaderSourceProc fShaderSource;
GrGLStencilFuncProc fStencilFunc;
GrGLStencilFuncSeparateProc fStencilFuncSeparate;
@ -386,11 +350,10 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLStencilMaskSeparateProc fStencilMaskSeparate;
GrGLStencilOpProc fStencilOp;
GrGLStencilOpSeparateProc fStencilOpSeparate;
GrGLTexCoordPointerProc fTexCoordPointer;
GrGLTexEnviProc fTexEnvi;
GrGLTexImage2DProc fTexImage2D;
GrGLTexParameteriProc fTexParameteri;
GrGLTexSubImage2DProc fTexSubImage2D;
GrGLTexStorage2DProc fTexStorage2D;
GrGLUniform1fProc fUniform1f;
GrGLUniform1iProc fUniform1i;
GrGLUniform1fvProc fUniform1fv;
@ -413,7 +376,6 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLUseProgramProc fUseProgram;
GrGLVertexAttrib4fvProc fVertexAttrib4fv;
GrGLVertexAttribPointerProc fVertexAttribPointer;
GrGLVertexPointerProc fVertexPointer;
GrGLViewportProc fViewport;
// FBO Extension Functions
@ -451,9 +413,6 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLInterfaceCallbackData fCallbackData;
#endif
private:
bool validateShaderFunctions() const;
bool validateFixedFunctions() const;
};
#endif

View File

@ -33,11 +33,13 @@ public:
GrBlendCoeff fDstBlendCoeff;
bool fAntiAlias;
bool fDither;
bool fColorMatrixEnabled;
GrColor fColor;
GrColor fColorFilterColor;
SkXfermode::Mode fColorFilterXfermode;
float fColorMatrix[20];
void setTexture(int i, GrTexture* texture) {
GrAssert((unsigned)i < kMaxTextures);
@ -51,14 +53,14 @@ public:
return fTextures[i];
}
GrSamplerState* getTextureSampler(int i) {
GrSamplerState* textureSampler(int i) {
GrAssert((unsigned)i < kMaxTextures);
return fTextureSamplers + i;
}
const GrSamplerState* getTextureSampler(int i) const {
const GrSamplerState& getTextureSampler(int i) const {
GrAssert((unsigned)i < kMaxTextures);
return fTextureSamplers + i;
return fTextureSamplers[i];
}
// The mask can be alpha-only or per channel. It is applied
@ -77,14 +79,14 @@ public:
// mask's sampler matrix is always applied to the positions
// (i.e. no explicit texture coordinates)
GrSamplerState* getMaskSampler(int i) {
GrSamplerState* maskSampler(int i) {
GrAssert((unsigned)i < kMaxMasks);
return fMaskSamplers + i;
}
const GrSamplerState* getMaskSampler(int i) const {
const GrSamplerState& getMaskSampler(int i) const {
GrAssert((unsigned)i < kMaxMasks);
return fMaskSamplers + i;
return fMaskSamplers[i];
}
// pre-concats sampler matrices for non-NULL textures and masks
@ -127,6 +129,8 @@ public:
fColorFilterColor = paint.fColorFilterColor;
fColorFilterXfermode = paint.fColorFilterXfermode;
memcpy(fColorMatrix, paint.fColorMatrix, sizeof(fColorMatrix));
fColorMatrixEnabled = paint.fColorMatrixEnabled;
for (int i = 0; i < kMaxTextures; ++i) {
GrSafeUnref(fTextures[i]);
@ -165,6 +169,8 @@ public:
void resetColorFilter() {
fColorFilterXfermode = SkXfermode::kDst_Mode;
fColorFilterColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
memset(fColorMatrix, 0, sizeof(fColorMatrix));
fColorMatrixEnabled = false;
}
bool hasTexture() const {
@ -239,14 +245,14 @@ private:
void resetTextures() {
for (int i = 0; i < kMaxTextures; ++i) {
this->setTexture(i, NULL);
fTextureSamplers[i].setClampNoFilter();
fTextureSamplers[i].reset();
}
}
void resetMasks() {
for (int i = 0; i < kMaxMasks; ++i) {
this->setMask(i, NULL);
fMaskSamplers[i].setClampNoFilter();
fMaskSamplers[i].reset();
}
}
};

View File

@ -43,20 +43,6 @@ public:
*/
int height() const { return fHeight; }
/**
* Retrieves the allocated width. It may differ from width for
* NPOT or min-RT size reasons.
* @return allocated width in pixels
*/
int allocatedWidth() const { return fAllocatedWidth; }
/**
* Retrieves the allocated height. It may differ from height for
* NPOT or min-RT size reasons.
* @return allocated height in pixels
*/
int allocatedHeight() const { return fAllocatedHeight; }
/**
* @return the pixel config. Can be kUnknown_GrPixelConfig
* if client asked us to render to a target that has a pixel
@ -137,12 +123,29 @@ public:
* @param height height of rectangle to read in pixels.
* @param config the pixel config of the destination buffer
* @param buffer memory to read the rectangle into.
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*
* @return true if the read succeeded, false if not. The read can fail
* because of a unsupported pixel config.
* because of an unsupported pixel config.
*/
bool readPixels(int left, int top, int width, int height,
GrPixelConfig config, void* buffer);
GrPixelConfig config, void* buffer, size_t rowBytes);
/**
* Copy the src pixels [buffer, rowbytes, pixelconfig] into the render
* target at the specified rectangle.
* @param left left edge of the rectangle to write (inclusive)
* @param top top edge of the rectangle to write (inclusive)
* @param width width of rectangle to write in pixels.
* @param height height of rectangle to write in pixels.
* @param config the pixel config of the source buffer
* @param buffer memory to read the rectangle from.
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*/
void writePixels(int left, int top, int width, int height,
GrPixelConfig config, const void* buffer, size_t rowBytes);
// a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
// 0 in GL), or be unresolvable because the client didn't give us the
@ -165,8 +168,6 @@ protected:
GrTexture* texture,
int width,
int height,
int allocatedWidth,
int allocatedHeight,
GrPixelConfig config,
int sampleCnt)
: INHERITED(gpu)
@ -174,8 +175,6 @@ protected:
, fTexture(texture)
, fWidth(width)
, fHeight(height)
, fAllocatedWidth(allocatedWidth)
, fAllocatedHeight(allocatedHeight)
, fConfig(config)
, fSampleCnt(sampleCnt) {
fResolveRect.setLargestInverted();
@ -197,8 +196,6 @@ private:
GrTexture* fTexture; // not ref'ed
int fWidth;
int fHeight;
int fAllocatedWidth;
int fAllocatedHeight;
GrPixelConfig fConfig;
int fSampleCnt;
GrIRect fResolveRect;

View File

@ -13,6 +13,7 @@
#include "GrRefCnt.h"
class GrGpu;
class GrContext;
class GrResource : public GrRefCnt {
public:
@ -55,6 +56,15 @@ public:
*/
virtual size_t sizeInBytes() const = 0;
/**
* Retrieves the context that owns the resource. Note that it is possible
* for this to return NULL. When resources have been release()ed or
* abandon()ed they no longer have an unknowning context. Destroying a
* GrContext automatically releases all its resources.
*/
const GrContext* getContext() const;
GrContext* getContext();
protected:
virtual void onRelease() = 0;

View File

@ -38,7 +38,9 @@ public:
/**
* Apply a separable convolution kernel.
*/
kConvolution_Filter
kConvolution_Filter,
kDefault_Filter = kNearest_Filter
};
/**
@ -68,6 +70,8 @@ public:
kRadial_SampleMode, //!< treat as radial gradient
kRadial2_SampleMode, //!< treat as 2-point radial gradient
kSweep_SampleMode, //!< treat as sweep gradient
kDefault_SampleMode = kNormal_SampleMode
};
/**
@ -77,7 +81,9 @@ public:
enum WrapMode {
kClamp_WrapMode,
kRepeat_WrapMode,
kMirror_WrapMode
kMirror_WrapMode,
kDefault_WrapMode = kClamp_WrapMode
};
/**
@ -88,57 +94,7 @@ public:
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
this->setClampNoFilter();
}
explicit GrSamplerState(Filter filter)
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
fWrapX = kClamp_WrapMode;
fWrapY = kClamp_WrapMode;
fSampleMode = kNormal_SampleMode;
fFilter = filter;
fMatrix.setIdentity();
fTextureDomain.setEmpty();
}
GrSamplerState(WrapMode wx, WrapMode wy, Filter filter)
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
fWrapX = wx;
fWrapY = wy;
fSampleMode = kNormal_SampleMode;
fFilter = filter;
fMatrix.setIdentity();
fTextureDomain.setEmpty();
}
GrSamplerState(WrapMode wx, WrapMode wy,
const GrMatrix& matrix, Filter filter)
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
fWrapX = wx;
fWrapY = wy;
fSampleMode = kNormal_SampleMode;
fFilter = filter;
fMatrix = matrix;
fTextureDomain.setEmpty();
}
GrSamplerState(WrapMode wx, WrapMode wy, SampleMode sample,
const GrMatrix& matrix, Filter filter)
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
fWrapX = wx;
fWrapY = wy;
fSampleMode = sample;
fMatrix = matrix;
fFilter = filter;
fTextureDomain.setEmpty();
this->reset();
}
WrapMode getWrapX() const { return fWrapX; }
@ -151,6 +107,7 @@ public:
int getKernelWidth() const { return fKernelWidth; }
const float* getKernel() const { return fKernel; }
const float* getImageIncrement() const { return fImageIncrement; }
bool swapsRAndB() const { return fSwapRAndB; }
bool isGradient() const {
return kRadial_SampleMode == fSampleMode ||
@ -163,12 +120,11 @@ public:
void setSampleMode(SampleMode mode) { fSampleMode = mode; }
/**
* Sets the sampler's matrix. See SampleMode for explanation of
* Access the sampler's matrix. See SampleMode for explanation of
* relationship between the matrix and sample mode.
* @param matrix the matrix to set
*/
void setMatrix(const GrMatrix& matrix) { fMatrix = matrix; }
GrMatrix* matrix() { return &fMatrix; }
/**
* Sets the sampler's texture coordinate domain to a
* custom rectangle, rather than the default (0,1).
@ -176,6 +132,12 @@ public:
*/
void setTextureDomain(const GrRect& textureDomain) { fTextureDomain = textureDomain; }
/**
* Swaps the R and B components when reading from the texture. Has no effect
* if the texture is alpha only.
*/
void setRAndBSwap(bool swap) { fSwapRAndB = swap; }
/**
* Multiplies the current sampler matrix a matrix
*
@ -194,18 +156,31 @@ public:
*/
void setFilter(Filter filter) { fFilter = filter; }
void setClampNoFilter() {
fWrapX = kClamp_WrapMode;
fWrapY = kClamp_WrapMode;
fSampleMode = kNormal_SampleMode;
fFilter = kNearest_Filter;
fMatrix.setIdentity();
void reset(WrapMode wrapXAndY,
Filter filter,
const GrMatrix& matrix) {
fWrapX = wrapXAndY;
fWrapY = wrapXAndY;
fSampleMode = kDefault_SampleMode;
fFilter = filter;
fMatrix = matrix;
fTextureDomain.setEmpty();
fSwapRAndB = false;
}
void reset(WrapMode wrapXAndY,
Filter filter) {
this->reset(wrapXAndY, filter, GrMatrix::I());
}
void reset(const GrMatrix& matrix) {
this->reset(kDefault_WrapMode, kDefault_Filter, matrix);
}
void reset() {
this->reset(kDefault_WrapMode, kDefault_Filter, GrMatrix::I());
}
GrScalar getRadial2CenterX1() const { return fRadial2CenterX1; }
GrScalar getRadial2Radius0() const { return fRadial2Radius0; }
bool isRadial2PosRoot() const { return fRadial2PosRoot; }
bool isRadial2PosRoot() const { return SkToBool(fRadial2PosRoot); }
// do the radial gradient params lead to a linear (rather than quadratic)
// equation.
bool radial2IsDegenerate() const { return GR_Scalar1 == fRadial2CenterX1; }
@ -236,29 +211,24 @@ public:
}
}
static const GrSamplerState& ClampNoFilter() {
return gClampNoFilter;
}
private:
WrapMode fWrapX;
WrapMode fWrapY;
SampleMode fSampleMode;
Filter fFilter;
WrapMode fWrapX : 8;
WrapMode fWrapY : 8;
SampleMode fSampleMode : 8;
Filter fFilter : 8;
GrMatrix fMatrix;
bool fSwapRAndB;
GrRect fTextureDomain;
// these are undefined unless fSampleMode == kRadial2_SampleMode
GrScalar fRadial2CenterX1;
GrScalar fRadial2Radius0;
bool fRadial2PosRoot;
SkBool8 fRadial2PosRoot;
// These are undefined unless fFilter == kConvolution_Filter
int fKernelWidth;
float fKernel[MAX_KERNEL_WIDTH];
uint8_t fKernelWidth;
float fImageIncrement[2];
static const GrSamplerState gClampNoFilter;
float fKernel[MAX_KERNEL_WIDTH];
};
#endif

View File

@ -32,20 +32,6 @@ public:
*/
int height() const { return fHeight; }
/**
* Retrieves the allocated width. It may differ from width for
* NPOT or min-RT size reasons.
* @return allocated width in texels
*/
int allocatedWidth() const { return fAllocatedWidth; }
/**
* Retrieves the allocated height. It may differ from height for
* NPOT or min-RT size reasons.
* @return allocated height in texels
*/
int allocatedHeight() const { return fAllocatedHeight; }
/**
* Convert from texels to normalized texture coords for POT textures
* only.
@ -64,44 +50,41 @@ public:
* Approximate number of bytes used by the texture
*/
virtual size_t sizeInBytes() const {
return (size_t) fAllocatedWidth *
fAllocatedHeight *
GrBytesPerPixel(fConfig);
return (size_t) fWidth * fHeight * GrBytesPerPixel(fConfig);
}
/**
* Updates a subrectangle of texels in the texture.
*
* @param x left edge of rectangle to update
* @param y top edge of rectangle to update
* @param width width of rectangle to update
* @param height height of rectangle to update
* @param srcData width*height texels of data in same format that was
* used at texture creation.
* @param rowBytes number of bytes per row in srcData, 0 means rows are
* packed
*/
virtual void uploadTextureData(int x,
int y,
int width,
int height,
const void* srcData,
size_t rowBytes) = 0;
/**
* Reads a rectangle of pixels from the texture.
* Read a rectangle of pixels from the texture.
* @param left left edge of the rectangle to read (inclusive)
* @param top top edge of the rectangle to read (inclusive)
* @param width width of rectangle to read in pixels.
* @param height height of rectangle to read in pixels.
* @param config the pixel config of the destination buffer
* @param buffer memory to read the rectangle into.
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*
* @return true if the read succeeded, false if not. The read can fail
* because of a unsupported pixel config.
*/
bool readPixels(int left, int top, int width, int height,
GrPixelConfig config, void* buffer);
GrPixelConfig config, void* buffer,
size_t rowBytes);
/**
* Writes a rectangle of pixels to the texture.
* @param left left edge of the rectangle to write (inclusive)
* @param top top edge of the rectangle to write (inclusive)
* @param width width of rectangle to write in pixels.
* @param height height of rectangle to write in pixels.
* @param config the pixel config of the source buffer
* @param buffer memory to read pixels from
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*/
void writePixels(int left, int top, int width, int height,
GrPixelConfig config, const void* buffer,
size_t rowBytes);
/**
* Retrieves the render target underlying this texture that can be passed to
@ -141,15 +124,11 @@ protected:
GrTexture(GrGpu* gpu,
int width,
int height,
int allocatedWidth,
int allocatedHeight,
GrPixelConfig config)
: INHERITED(gpu)
, fRenderTarget(NULL)
, fWidth(width)
, fHeight(height)
, fAllocatedWidth(allocatedWidth)
, fAllocatedHeight(allocatedHeight)
, fConfig(config) {
// only make sense if alloc size is pow2
fShiftFixedX = 31 - Gr_clz(fWidth);
@ -166,8 +145,6 @@ protected:
private:
int fWidth;
int fHeight;
int fAllocatedWidth;
int fAllocatedHeight;
// these two shift a fixed-point value into normalized coordinates
// for this texture if the texture is power of two sized.

View File

@ -55,7 +55,7 @@
* n is already a multiple of 4
*/
#define GrALIGN4(n) SkAlign4(n)
#define GrIsALIGN4(n) (((n) & 3) == 0)
#define GrIsALIGN4(n) SkIsAlign4(n)
template <typename T> const T& GrMin(const T& a, const T& b) {
return (a < b) ? a : b;
@ -268,17 +268,116 @@ static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
/**
* Pixel configurations.
*
* Unpremultiplied configs are intended for converting pixel data in and out
* from skia. Surfaces with these configs have limited support. As an input
* (GrPaint texture) the corresponding GrSamplerState must have its filter set
* to kNearest_Filter. Otherwise, the draw will fail. When the render target
* has an unpremultiplied config draws must use blend coeffs 1,0 (AKA src-mode).
* Other coeffs will cause the draw to fail.
*/
enum GrPixelConfig {
kUnknown_GrPixelConfig,
kAlpha_8_GrPixelConfig,
kIndex_8_GrPixelConfig,
kRGB_565_GrPixelConfig,
kRGBA_4444_GrPixelConfig, //!< premultiplied
kRGBA_8888_GrPixelConfig, //!< premultiplied
kRGBX_8888_GrPixelConfig, //!< treat the alpha channel as opaque
/**
* Premultiplied
*/
kRGBA_4444_GrPixelConfig,
/**
* Premultiplied. Byte order is r,g,b,a
*/
kRGBA_8888_PM_GrPixelConfig,
/**
* Unpremultiplied. Byte order is r,g,b,a
*/
kRGBA_8888_UPM_GrPixelConfig,
/**
* Premultiplied. Byte order is b,g,r,a
*/
kBGRA_8888_PM_GrPixelConfig,
/**
* Unpremultiplied. Byte order is b,g,r,a
*/
kBGRA_8888_UPM_GrPixelConfig,
};
// Aliases for pixel configs that match skia's byte order
#ifndef SK_CPU_LENDIAN
#error "Skia gpu currently assumes little endian"
#endif
#if 24 == SK_A32_SHIFT && 16 == SK_R32_SHIFT && \
8 == SK_G32_SHIFT && 0 == SK_B32_SHIFT
static const GrPixelConfig kSkia8888_PM_GrPixelConfig = kBGRA_8888_PM_GrPixelConfig;
static const GrPixelConfig kSkia8888_UPM_GrPixelConfig = kBGRA_8888_UPM_GrPixelConfig;
#elif 24 == SK_A32_SHIFT && 16 == SK_B32_SHIFT && \
8 == SK_G32_SHIFT && 0 == SK_R32_SHIFT
static const GrPixelConfig kSkia8888_PM_GrPixelConfig = kRGBA_8888_PM_GrPixelConfig;
static const GrPixelConfig kSkia8888_UPM_GrPixelConfig = kRGBA_8888_UPM_GrPixelConfig;
#else
#error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format."
#endif
// WebKit is relying on this old name for the native skia PM config. This will
// be deleted ASAP because it is so similar to kRGBA_PM_8888_GrPixelConfig but
// has a different interpretation when skia is compiled BGRA.
static const GrPixelConfig kRGBA_8888_GrPixelConfig = kSkia8888_PM_GrPixelConfig;
// Returns true if the pixel config has 8bit r,g,b,a components in that byte
// order
static inline bool GrPixelConfigIsRGBA8888(GrPixelConfig config) {
switch (config) {
case kRGBA_8888_PM_GrPixelConfig:
case kRGBA_8888_UPM_GrPixelConfig:
return true;
default:
return false;
}
}
// Returns true if the pixel config has 8bit b,g,r,a components in that byte
// order
static inline bool GrPixelConfigIsBGRA8888(GrPixelConfig config) {
switch (config) {
case kBGRA_8888_PM_GrPixelConfig:
case kBGRA_8888_UPM_GrPixelConfig:
return true;
default:
return false;
}
}
// Returns true if the pixel config is 32 bits per pixel
static inline bool GrPixelConfigIs32Bit(GrPixelConfig config) {
switch (config) {
case kRGBA_8888_PM_GrPixelConfig:
case kRGBA_8888_UPM_GrPixelConfig:
case kBGRA_8888_PM_GrPixelConfig:
case kBGRA_8888_UPM_GrPixelConfig:
return true;
default:
return false;
}
}
// Takes a config and returns the equivalent config with the R and B order
// swapped if such a config exists. Otherwise, kUnknown_GrPixelConfig
static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
switch (config) {
case kBGRA_8888_PM_GrPixelConfig:
return kRGBA_8888_PM_GrPixelConfig;
case kBGRA_8888_UPM_GrPixelConfig:
return kRGBA_8888_UPM_GrPixelConfig;
case kRGBA_8888_PM_GrPixelConfig:
return kBGRA_8888_PM_GrPixelConfig;
case kRGBA_8888_UPM_GrPixelConfig:
return kBGRA_8888_UPM_GrPixelConfig;
default:
return kUnknown_GrPixelConfig;
}
}
static inline size_t GrBytesPerPixel(GrPixelConfig config) {
switch (config) {
case kAlpha_8_GrPixelConfig:
@ -287,8 +386,10 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
return 2;
case kRGBA_8888_GrPixelConfig:
case kRGBX_8888_GrPixelConfig:
case kRGBA_8888_PM_GrPixelConfig:
case kRGBA_8888_UPM_GrPixelConfig:
case kBGRA_8888_PM_GrPixelConfig:
case kBGRA_8888_UPM_GrPixelConfig:
return 4;
default:
return 0;
@ -298,7 +399,20 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
switch (config) {
case kRGB_565_GrPixelConfig:
case kRGBX_8888_GrPixelConfig:
return true;
default:
return false;
}
}
/**
* Premultiplied alpha is the usual for skia. Therefore, configs that are
* ambiguous (alpha-only or color-only) are considered premultiplied.
*/
static inline bool GrPixelConfigIsUnpremultiplied(GrPixelConfig config) {
switch (config) {
case kRGBA_8888_UPM_GrPixelConfig:
case kBGRA_8888_UPM_GrPixelConfig:
return true;
default:
return false;
@ -376,7 +490,7 @@ struct GrTextureDesc {
* Format of source data of the texture. Not guaraunteed to be the same as
* internal format used by 3D API.
*/
GrPixelConfig fFormat;
GrPixelConfig fConfig;
};
/**
@ -499,6 +613,99 @@ enum GrConvexHint {
///////////////////////////////////////////////////////////////////////////////
// opaque type for 3D API object handles
typedef intptr_t GrPlatform3DObject;
/**
* Gr can wrap an existing texture created by the client with a GrTexture
* object. The client is responsible for ensuring that the texture lives at
* least as long as the GrTexture object wrapping it. We require the client to
* explicitly provide information about the texture, such as width, height,
* and pixel config, rather than querying the 3D APIfor these values. We expect
* these to be immutable even if the 3D API doesn't require this (OpenGL).
*
* Textures that are also render targets are supported as well. Gr will manage
* any ancillary 3D API (stencil buffer, FBO id, etc) objects necessary for
* Gr to draw into the render target. To access the render target object
* call GrTexture::asRenderTarget().
*
* If in addition to the render target flag, the caller also specifies a sample
* count Gr will create an MSAA buffer that resolves into the texture. Gr auto-
* resolves when it reads from the texture. The client can explictly resolve
* using the GrRenderTarget interface.
*/
enum GrPlatformTextureFlags {
/**
* No flags enabled
*/
kNone_GrPlatformTextureFlag = 0x0,
/**
* Indicates that the texture is also a render target, and thus should have
* a GrRenderTarget object.
*
* D3D (future): client must have created the texture with flags that allow
* it to be used as a render target.
*/
kRenderTarget_GrPlatformTextureFlag = 0x1,
};
GR_MAKE_BITFIELD_OPS(GrPlatformTextureFlags)
struct GrPlatformTextureDesc {
GrPlatformTextureDesc() { memset(this, 0, sizeof(*this)); }
GrPlatformTextureFlags fFlags;
int fWidth; //<! width in pixels
int fHeight; //<! height in pixels
GrPixelConfig fConfig; //<! color format
/**
* If the render target flag is set and sample count is greater than 0
* then Gr will create an MSAA buffer that resolves to the texture.
*/
int fSampleCnt;
/**
* Handle to the 3D API object.
* OpenGL: Texture ID.
*/
GrPlatform3DObject fTextureHandle;
};
///////////////////////////////////////////////////////////////////////////////
/**
* Gr can wrap an existing render target created by the client in the 3D API
* with a GrRenderTarget object. The client is responsible for ensuring that the
* underlying 3D API object lives at least as long as the GrRenderTarget object
* wrapping it. We require the client to explicitly provide information about
* the target, such as width, height, and pixel config rather than querying the
* 3D API for these values. We expect these properties to be immutable even if
* the 3D API doesn't require this (OpenGL).
*/
struct GrPlatformRenderTargetDesc {
GrPlatformRenderTargetDesc() { memset(this, 0, sizeof(*this)); }
int fWidth; //<! width in pixels
int fHeight; //<! height in pixels
GrPixelConfig fConfig; //<! color format
/**
* The number of samples per pixel. Gr uses this to influence decisions
* about applying other forms of antialiasing.
*/
int fSampleCnt;
/**
* Number of bits of stencil per-pixel.
*/
int fStencilBits;
/**
* Handle to the 3D API object.
* OpenGL: FBO ID
*/
GrPlatform3DObject fRenderTargetHandle;
};
///////////////////////////////////////////////////////////////////////////////
// DEPRECATED. createPlatformSurface is replaced by createPlatformTexture
// and createPlatformRenderTarget. These enums and structs will be removed.
enum GrPlatformSurfaceType {
/**
* Specifies that the object being created is a render target.
@ -532,12 +739,6 @@ enum GrPlatformRenderTargetFlags {
GR_MAKE_BITFIELD_OPS(GrPlatformRenderTargetFlags)
// opaque type for 3D API object handles
typedef intptr_t GrPlatform3DObject;
/**
* Description of platform surface to create. See below for GL example.
*/
struct GrPlatformSurfaceDesc {
GrPlatformSurfaceType fSurfaceType; // type of surface to create
/**
@ -618,7 +819,7 @@ struct GrPlatformSurfaceDesc {
* renderTargetTextureDesc.fRenderTargetFlags = kGrCanResolve_GrPlatformRenderTargetFlagBit;
* renderTargetTextureDesc.fWidth = W;
* renderTargetTextureDesc.fHeight = H;
* renderTargetTextureDesc.fConfig = kRGBA_8888_GrPixelConfig
* renderTargetTextureDesc.fConfig = kSkia8888_PM_GrPixelConfig
* renderTargetTextureDesc.fStencilBits = 8;
* renderTargetTextureDesc.fSampleCnt = S;
* renderTargetTextureDesc.fPlatformTexture = textureID;

Some files were not shown because too many files have changed in this diff Show More