merge mozilla-inbound to mozilla-central a=merge

This commit is contained in:
Carsten "Tomcat" Book 2014-09-15 14:03:22 +02:00
Родитель b42a6fc06c 0ec9b2b3b4
Коммит 1ba9103be9
84 изменённых файлов: 9957 добавлений и 8420 удалений

Просмотреть файл

@ -21,7 +21,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "notificationStorage",
"@mozilla.org/notificationStorage;1",
"nsINotificationStorage");
XPCOMUtils.defineLazyGetter(this, "cpmm", function() {
return Cc["@mozilla.org/childprocessmessagemanager;1"]
.getService(Ci.nsIMessageSender);
@ -162,13 +161,13 @@ AlertsService.prototype = {
);
}
}
if (topic === kTopicAlertFinished && listener.dbId) {
notificationStorage.delete(listener.manifestURL, listener.dbId);
}
}
// we're done with this notification
if (topic === kTopicAlertFinished) {
if (listener.dbId) {
notificationStorage.delete(listener.manifestURL, listener.dbId);
}
delete this._listeners[data.uid];
}
},

Просмотреть файл

@ -1636,11 +1636,6 @@ pref("dom.debug.propagate_gesture_events_through_content", false);
// The request URL of the GeoLocation backend.
pref("geo.wifi.uri", "https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY%");
#ifdef RELEASE_BUILD
pref("geo.wifi.logging.enabled", false);
#else
pref("geo.wifi.logging.enabled", true);
#endif
// Necko IPC security checks only needed for app isolation for cookies/cache/etc:
// currently irrelevant for desktop e10s

Просмотреть файл

@ -646,6 +646,8 @@ public:
}
bool HasAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName) const;
Element* Closest(const nsAString& aSelector,
ErrorResult& aResult);
bool Matches(const nsAString& aSelector,
ErrorResult& aError);
already_AddRefed<nsIHTMLCollection>

Просмотреть файл

@ -2747,6 +2747,33 @@ Element::SetTokenList(nsIAtom* aAtom, nsIVariant* aValue)
return rv.ErrorCode();
}
Element*
Element::Closest(const nsAString& aSelector, ErrorResult& aResult)
{
nsCSSSelectorList* selectorList = ParseSelectorList(aSelector, aResult);
if (!selectorList) {
// Either we failed (and aResult already has the exception), or this
// is a pseudo-element-only selector that matches nothing.
return nullptr;
}
OwnerDoc()->FlushPendingLinkUpdates();
TreeMatchContext matchingContext(false,
nsRuleWalker::eRelevantLinkUnvisited,
OwnerDoc(),
TreeMatchContext::eNeverMatchVisited);
matchingContext.SetHasSpecifiedScope();
matchingContext.AddScopeElement(this);
for (nsINode* node = this; node; node = node->GetParentNode()) {
if (node->IsElement() &&
nsCSSRuleProcessor::SelectorListMatches(node->AsElement(),
matchingContext,
selectorList)) {
return node->AsElement();
}
}
return nullptr;
}
bool
Element::Matches(const nsAString& aSelector, ErrorResult& aError)
{

Просмотреть файл

@ -1260,6 +1260,8 @@ GK_ATOM(clip_rule, "clip-rule")
GK_ATOM(clipPath, "clipPath")
GK_ATOM(clipPathUnits, "clipPathUnits")
GK_ATOM(cm, "cm")
GK_ATOM(colorBurn, "color-burn")
GK_ATOM(colorDodge, "color-dodge")
GK_ATOM(colorInterpolation, "color-interpolation")
GK_ATOM(colorInterpolationFilters, "color-interpolation-filters")
GK_ATOM(colorProfile, "color-profile")
@ -1288,6 +1290,7 @@ GK_ATOM(elevation, "elevation")
GK_ATOM(erode, "erode")
GK_ATOM(ex, "ex")
GK_ATOM(exact, "exact")
GK_ATOM(exclusion, "exclusion")
GK_ATOM(exponent, "exponent")
GK_ATOM(feBlend, "feBlend")
GK_ATOM(feColorMatrix, "feColorMatrix")
@ -1352,7 +1355,9 @@ GK_ATOM(glyph_orientation_vertical, "glyph-orientation-vertical")
GK_ATOM(grad, "grad")
GK_ATOM(gradientTransform, "gradientTransform")
GK_ATOM(gradientUnits, "gradientUnits")
GK_ATOM(hardLight, "hard-light")
GK_ATOM(hkern, "hkern")
GK_ATOM(hue, "hue")
GK_ATOM(hueRotate, "hueRotate")
GK_ATOM(identity, "identity")
GK_ATOM(image_rendering, "image-rendering")
@ -1376,6 +1381,7 @@ GK_ATOM(linearGradient, "linearGradient")
GK_ATOM(linearRGB, "linearRGB")
GK_ATOM(list_style_type, "list-style-type")
GK_ATOM(luminanceToAlpha, "luminanceToAlpha")
GK_ATOM(luminosity, "luminosity")
GK_ATOM(magnify, "magnify")
GK_ATOM(marker, "marker")
GK_ATOM(marker_end, "marker-end")
@ -1441,6 +1447,7 @@ GK_ATOM(rotate, "rotate")
GK_ATOM(rx, "rx")
GK_ATOM(ry, "ry")
GK_ATOM(saturate, "saturate")
GK_ATOM(saturation, "saturation")
GK_ATOM(set, "set")
GK_ATOM(seed, "seed")
GK_ATOM(shadow, "shadow")
@ -1448,6 +1455,7 @@ GK_ATOM(shape_rendering, "shape-rendering")
GK_ATOM(skewX, "skewX")
GK_ATOM(skewY, "skewY")
GK_ATOM(slope, "slope")
GK_ATOM(softLight, "soft-light")
GK_ATOM(spacing, "spacing")
GK_ATOM(spacingAndGlyphs, "spacingAndGlyphs")
GK_ATOM(specularConstant, "specularConstant")

Просмотреть файл

@ -574,6 +574,7 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 904183 # b2g(bug 904183
[test_domparser_null_char.html]
[test_domparsing.html]
[test_elementTraversal.html]
[test_element_closest.html]
[test_encodeToStringWithMaxLength.html]
[test_fileapi.html]
skip-if = e10s

Просмотреть файл

@ -0,0 +1,84 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1055533
-->
<head>
<title>Test for Bug 1055533</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body id="body">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1055533">Mozilla Bug 1055533</a>
<div id="test8" class="div3">
<div id="test7" class="div2">
<div id="test6" class="div1">
<form id="test10" class="form2"></form>
<form id="test5" class="form1" name="form-a">
<input id="test1" class="input1" required>
<fieldset class="fieldset2" id="test2">
<select id="test3" class="select1" required>
<option default id="test4" value="">Test4</option>
<option selected id="test11">Test11</option>
<option id="test12">Test12</option>
<option id="test13">Test13</option>
</select>
<input id="test9" type="text" required>
</fieldset>
</form>
</div>
</div>
</div>
<script class="testbody" type="text/javascript">
test("select" , "test12", "test3");
test("fieldset" , "test13", "test2");
test("div" , "test13", "test6");
test("body" , "test3" , "body");
test("[default]" , "test4" , "test4");
test("[selected]" , "test4" , "");
test("[selected]" , "test11", "test11");
test('[name="form-a"]' , "test12", "test5");
test('form[name="form-a"]' , "test13", "test5");
test("input[required]" , "test9" , "test9");
test("select[required]" , "test9" , "");
test("div:not(.div1)" , "test13", "test7");
test("div.div3" , "test6" , "test8");
test("div#test7" , "test1" , "test7");
test(".div3 > .div2" , "test12", "test7");
test(".div3 > .div1" , "test12", "");
test("form > input[required]" , "test9" , "");
test("fieldset > select[required]", "test12", "test3");
test("input + fieldset" , "test6" , "");
test("form + form" , "test3" , "test5");
test("form + form" , "test5" , "test5");
test(":empty" , "test10", "test10");
test(":last-child" , "test11", "test2");
test(":first-child" , "test12", "test3");
test(":invalid" , "test11", "test2");
test(":scope" , "test4", "test4");
test("select > :scope" , "test4", "test4");
test("div > :scope" , "test4", "");
try {
test(":has(> :scope)" , "test4", "test3");
} catch(e) {
todo(false, ":has(> :scope) [:has is not implemented yet]");
}
function test(aSelector, aElementId, aTargetId) {
var el = document.getElementById(aElementId).closest(aSelector);
if (el === null) {
is("", aTargetId, aSelector);
} else {
is(el.id, aTargetId, aSelector);
}
}
</script>
</body>
</html>

Просмотреть файл

@ -539,6 +539,8 @@ public:
bool aCompileEventHandlers) MOZ_OVERRIDE;
virtual void UnbindFromTree(bool aDeep = true,
bool aNullParent = true) MOZ_OVERRIDE;
MOZ_ALWAYS_INLINE // Avoid a crashy hook from Avast 10 Beta
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, bool aNotify)
{

Просмотреть файл

@ -294,13 +294,7 @@ AudioSink::PlayFromAudioQueue()
AssertOnAudioThread();
NS_ASSERTION(!mAudioStream->IsPaused(), "Don't play when paused");
nsAutoPtr<AudioData> audio(AudioQueue().PopFront());
{
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
NS_WARN_IF_FALSE(mPlaying, "Should be playing");
// Awaken the decode loop if it's waiting for space to free up in the
// audio queue.
GetReentrantMonitor().NotifyAll();
}
SINK_LOG_V("playing %u frames of audio at time %lld",
audio->mFrames, audio->mTime);
mAudioStream->Write(audio->mAudioData, audio->mFrames);

Просмотреть файл

@ -95,6 +95,7 @@ OmxVideoTrackEncoder::GetEncodedTrack(EncodedFrameContainer& aData)
segment.AppendFrom(&mRawSegment);
}
nsresult rv;
// Start queuing raw frames to the input buffers of OMXCodecWrapper.
VideoSegment::ChunkIterator iter(segment);
while (!iter.IsEnded()) {
@ -105,7 +106,8 @@ OmxVideoTrackEncoder::GetEncodedTrack(EncodedFrameContainer& aData)
uint64_t totalDurationUs = mTotalFrameDuration * USECS_PER_S / mTrackRate;
layers::Image* img = (chunk.IsNull() || chunk.mFrame.GetForceBlack()) ?
nullptr : chunk.mFrame.GetImage();
mEncoder->Encode(img, mFrameWidth, mFrameHeight, totalDurationUs);
rv = mEncoder->Encode(img, mFrameWidth, mFrameHeight, totalDurationUs);
NS_ENSURE_SUCCESS(rv, rv);
}
mLastFrame.TakeFrom(&chunk.mFrame);
@ -119,22 +121,21 @@ OmxVideoTrackEncoder::GetEncodedTrack(EncodedFrameContainer& aData)
uint64_t totalDurationUs = mTotalFrameDuration * USECS_PER_S / mTrackRate;
layers::Image* img = (!mLastFrame.GetImage() || mLastFrame.GetForceBlack())
? nullptr : mLastFrame.GetImage();
nsresult result = mEncoder->Encode(img, mFrameWidth, mFrameHeight,
totalDurationUs,
OMXCodecWrapper::BUFFER_EOS);
rv = mEncoder->Encode(img, mFrameWidth, mFrameHeight, totalDurationUs,
OMXCodecWrapper::BUFFER_EOS);
NS_ENSURE_SUCCESS(rv, rv);
// Keep sending EOS signal until OMXVideoEncoder gets it.
if (result == NS_OK) {
mEosSetInEncoder = true;
}
mEosSetInEncoder = true;
}
// Dequeue an encoded frame from the output buffers of OMXCodecWrapper.
nsresult rv;
nsTArray<uint8_t> buffer;
int outFlags = 0;
int64_t outTimeStampUs = 0;
mEncoder->GetNextEncodedFrame(&buffer, &outTimeStampUs, &outFlags,
GET_ENCODED_VIDEO_FRAME_TIMEOUT);
rv = mEncoder->GetNextEncodedFrame(&buffer, &outTimeStampUs, &outFlags,
GET_ENCODED_VIDEO_FRAME_TIMEOUT);
NS_ENSURE_SUCCESS(rv, rv);
if (!buffer.IsEmpty()) {
nsRefPtr<EncodedFrame> videoData = new EncodedFrame();
if (outFlags & OMXCodecWrapper::BUFFER_CODEC_CONFIG) {

Просмотреть файл

@ -199,14 +199,6 @@ VideoTrackEncoder::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph,
if (!chunk.IsNull()) {
gfx::IntSize imgsize = chunk.mFrame.GetImage()->GetSize();
gfxIntSize intrinsicSize = chunk.mFrame.GetIntrinsicSize();
#ifdef MOZ_WIDGET_GONK
// Block the video frames come from video source.
if (chunk.mFrame.GetImage()->GetFormat() != ImageFormat::PLANAR_YCBCR) {
LOG("Can't encode this ImageFormat %x", chunk.mFrame.GetImage()->GetFormat());
NotifyCancel();
break;
}
#endif
nsresult rv = Init(imgsize.width, imgsize.height,
intrinsicSize.width, intrinsicSize.height,
aTrackRate);

Просмотреть файл

@ -299,9 +299,10 @@ ConvertPlanarYCbCrToNV12(const PlanarYCbCrData* aSource, uint8_t* aDestination)
// Convert pixels in graphic buffer to NV12 format. aSource is the layer image
// containing source graphic buffer, and aDestination is the destination of
// conversion. Currently only 2 source format are supported:
// conversion. Currently 3 source format are supported:
// - NV21/HAL_PIXEL_FORMAT_YCrCb_420_SP (from camera preview window).
// - YV12/HAL_PIXEL_FORMAT_YV12 (from video decoder).
// - QCOM proprietary/HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS (from Flame HW video decoder)
static void
ConvertGrallocImageToNV12(GrallocImage* aSource, uint8_t* aDestination)
{
@ -309,9 +310,6 @@ ConvertGrallocImageToNV12(GrallocImage* aSource, uint8_t* aDestination)
sp<GraphicBuffer> graphicBuffer = aSource->GetGraphicBuffer();
int pixelFormat = graphicBuffer->getPixelFormat();
// Only support NV21 (from camera) or YV12 (from HW decoder output) for now.
NS_ENSURE_TRUE_VOID(pixelFormat == HAL_PIXEL_FORMAT_YCrCb_420_SP ||
pixelFormat == HAL_PIXEL_FORMAT_YV12);
void* imgPtr = nullptr;
graphicBuffer->lock(GraphicBuffer::USAGE_SW_READ_MASK, &imgPtr);
@ -353,6 +351,26 @@ ConvertGrallocImageToNV12(GrallocImage* aSource, uint8_t* aDestination)
yuv.mCbSkip = 0;
ConvertPlanarYCbCrToNV12(&yuv, aDestination);
break;
// From QCOM video decoder on Flame. See bug 997593.
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
// Venus formats are doucmented in kernel/include/media/msm_media_info.h:
yuv.mYChannel = static_cast<uint8_t*>(imgPtr);
yuv.mYSkip = 0;
yuv.mYSize.width = graphicBuffer->getWidth();
yuv.mYSize.height = graphicBuffer->getHeight();
// - Y & UV Width aligned to 128
yuv.mYStride = (yuv.mYSize.width + 127) & ~127;
yuv.mCbCrSize.width = yuv.mYSize.width / 2;
yuv.mCbCrSize.height = yuv.mYSize.height / 2;
// - Y height aligned to 32
yuv.mCbChannel = yuv.mYChannel + (yuv.mYStride * ((yuv.mYSize.height + 31) & ~31));
// Interleaved VU plane.
yuv.mCbSkip = 1;
yuv.mCrChannel = yuv.mCbChannel + 1;
yuv.mCrSkip = 1;
yuv.mCbCrStride = yuv.mYStride;
ConvertPlanarYCbCrToNV12(&yuv, aDestination);
break;
default:
NS_ERROR("Unsupported input gralloc image type. Should never be here.");
}
@ -369,11 +387,40 @@ OMXVideoEncoder::Encode(const Image* aImage, int aWidth, int aHeight,
NS_ENSURE_TRUE(aWidth == mWidth && aHeight == mHeight && aTimestamp >= 0,
NS_ERROR_INVALID_ARG);
Image* img = const_cast<Image*>(aImage);
ImageFormat format = ImageFormat::PLANAR_YCBCR;
if (img) {
format = img->GetFormat();
gfx::IntSize size = img->GetSize();
// Validate input image.
NS_ENSURE_TRUE(aWidth == size.width, NS_ERROR_INVALID_ARG);
NS_ENSURE_TRUE(aHeight == size.height, NS_ERROR_INVALID_ARG);
if (format == ImageFormat::PLANAR_YCBCR) {
NS_ENSURE_TRUE(static_cast<PlanarYCbCrImage*>(img)->IsValid(),
NS_ERROR_INVALID_ARG);
} else if (format == ImageFormat::GRALLOC_PLANAR_YCBCR) {
// Reject unsupported gralloc-ed buffers.
int halFormat = static_cast<GrallocImage*>(img)->GetGraphicBuffer()->getPixelFormat();
NS_ENSURE_TRUE(halFormat == HAL_PIXEL_FORMAT_YCrCb_420_SP ||
halFormat == HAL_PIXEL_FORMAT_YV12 ||
halFormat == GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS,
NS_ERROR_INVALID_ARG);
} else {
// TODO: support RGB to YUV color conversion.
NS_ERROR("Unsupported input image type.");
return NS_ERROR_INVALID_ARG;
}
}
status_t result;
// Dequeue an input buffer.
uint32_t index;
result = mCodec->dequeueInputBuffer(&index, INPUT_BUFFER_TIMEOUT_US);
if (result == -EAGAIN) {
// Drop the frame when out of input buffer.
return NS_OK;
}
NS_ENSURE_TRUE(result == OK, NS_ERROR_FAILURE);
const sp<ABuffer>& inBuf = mInputBufs.itemAt(index);
@ -385,30 +432,20 @@ OMXVideoEncoder::Encode(const Image* aImage, int aWidth, int aHeight,
// Buffer should be large enough to hold input image data.
MOZ_ASSERT(dstSize >= yLen + uvLen);
inBuf->setRange(0, yLen + uvLen);
if (!aImage) {
dstSize = yLen + uvLen;
inBuf->setRange(0, dstSize);
if (!img) {
// Generate muted/black image directly in buffer.
dstSize = yLen + uvLen;
// Fill Y plane.
memset(dst, 0x10, yLen);
// Fill UV plane.
memset(dst + yLen, 0x80, uvLen);
} else {
Image* img = const_cast<Image*>(aImage);
ImageFormat format = img->GetFormat();
MOZ_ASSERT(aWidth == img->GetSize().width &&
aHeight == img->GetSize().height);
if (format == ImageFormat::GRALLOC_PLANAR_YCBCR) {
ConvertGrallocImageToNV12(static_cast<GrallocImage*>(img), dst);
} else if (format == ImageFormat::PLANAR_YCBCR) {
ConvertPlanarYCbCrToNV12(static_cast<PlanarYCbCrImage*>(img)->GetData(),
dst);
} else {
// TODO: support RGB to YUV color conversion.
NS_ERROR("Unsupported input image type.");
dst);
}
}

Просмотреть файл

@ -197,6 +197,7 @@ public:
void StopImpl();
void SnapshotImpl();
void RotateImage(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);
uint32_t ConvertPixexFormatToFOURCC(int aFormat);
void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration);
nsresult TakePhoto(PhotoCallback* aCallback) MOZ_OVERRIDE;

Просмотреть файл

@ -968,6 +968,22 @@ MediaEngineWebRTCVideoSource::OnTakePictureComplete(uint8_t* aData, uint32_t aLe
}
}
uint32_t
MediaEngineWebRTCVideoSource::ConvertPixexFormatToFOURCC(int aFormat)
{
switch (aFormat) {
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
return libyuv::FOURCC_NV21;
case HAL_PIXEL_FORMAT_YV12:
return libyuv::FOURCC_YV12;
default: {
LOG((" xxxxx Unknown pixel format %d", aFormat));
MOZ_ASSERT(false, "Unknown pixel format.");
return libyuv::FOURCC_ANY;
}
}
}
void
MediaEngineWebRTCVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight) {
layers::GrallocImage *nativeImage = static_cast<layers::GrallocImage*>(aImage);
@ -1003,7 +1019,7 @@ MediaEngineWebRTCVideoSource::RotateImage(layers::Image* aImage, uint32_t aWidth
aWidth, aHeight,
aWidth, aHeight,
static_cast<libyuv::RotationMode>(mRotation),
libyuv::FOURCC_NV21);
ConvertPixexFormatToFOURCC(graphicBuffer->getPixelFormat()));
graphicBuffer->unlock();
const uint8_t lumaBpp = 8;

Просмотреть файл

@ -26,6 +26,17 @@ nsSVGEnumMapping SVGFEBlendElement::sModeMap[] = {
{&nsGkAtoms::screen, SVG_FEBLEND_MODE_SCREEN},
{&nsGkAtoms::darken, SVG_FEBLEND_MODE_DARKEN},
{&nsGkAtoms::lighten, SVG_FEBLEND_MODE_LIGHTEN},
{&nsGkAtoms::overlay, SVG_FEBLEND_MODE_OVERLAY},
{&nsGkAtoms::colorDodge, SVG_FEBLEND_MODE_COLOR_DODGE},
{&nsGkAtoms::colorBurn, SVG_FEBLEND_MODE_COLOR_BURN},
{&nsGkAtoms::hardLight, SVG_FEBLEND_MODE_HARD_LIGHT},
{&nsGkAtoms::softLight, SVG_FEBLEND_MODE_SOFT_LIGHT},
{&nsGkAtoms::difference, SVG_FEBLEND_MODE_DIFFERENCE},
{&nsGkAtoms::exclusion, SVG_FEBLEND_MODE_EXCLUSION},
{&nsGkAtoms::hue, SVG_FEBLEND_MODE_HUE},
{&nsGkAtoms::saturation, SVG_FEBLEND_MODE_SATURATION},
{&nsGkAtoms::color, SVG_FEBLEND_MODE_COLOR},
{&nsGkAtoms::luminosity, SVG_FEBLEND_MODE_LUMINOSITY},
{nullptr, 0}
};

Просмотреть файл

@ -151,7 +151,7 @@ skip-if = toolkit == 'cocoa' || toolkit == 'android' || toolkit == 'gonk'
[test_2d.gradient.radial.outside2.html]
skip-if = toolkit != 'cocoa'
[test_2d.gradient.radial.outside3.html]
skip-if = toolkit != 'cocoa'
disabled = bug 1038277
# These tests only pass on Mac OS X >= 10.5; see bug 450114
[test_2d.gradient.radial.touch1.html]
disabled = bug 450114

Просмотреть файл

@ -85,6 +85,14 @@ public:
*/
nsresult NotifyIME(widget::IMEMessage aMessage);
/**
* the offset of first composition string
*/
uint32_t NativeOffsetOfStartComposition() const
{
return mCompositionStartOffset;
}
/**
* the offset of first selected clause or start of of compositon
*/

Просмотреть файл

@ -166,9 +166,11 @@ parent:
*
* offset The starting offset of this rect
* rect The rect of first character of selected IME composition
* caretOffset The offset of caret position
* caretRect The rect of IME caret
*/
NotifyIMESelectedCompositionRect(uint32_t offset, nsIntRect rect, nsIntRect caretRect);
NotifyIMESelectedCompositionRect(uint32_t offset, nsIntRect[] rect,
uint32_t caretOffset, nsIntRect caretRect);
/**
* Notifies chrome that there has been a change in selection

Просмотреть файл

@ -1310,13 +1310,16 @@ TabParent::RecvNotifyIMETextChange(const uint32_t& aStart,
}
bool
TabParent::RecvNotifyIMESelectedCompositionRect(const uint32_t& aOffset,
const nsIntRect& aRect,
const nsIntRect& aCaretRect)
TabParent::RecvNotifyIMESelectedCompositionRect(
const uint32_t& aOffset,
const InfallibleTArray<nsIntRect>& aRects,
const uint32_t& aCaretOffset,
const nsIntRect& aCaretRect)
{
// add rect to cache for another query
mIMECompositionRectOffset = aOffset;
mIMECompositionRect = aRect;
mIMECompositionRects = aRects;
mIMECaretOffset = aCaretOffset;
mIMECaretRect = aCaretRect;
nsCOMPtr<nsIWidget> widget = GetWidget();
@ -1521,23 +1524,33 @@ TabParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent)
break;
case NS_QUERY_TEXT_RECT:
{
if (aEvent.mInput.mOffset != mIMECompositionRectOffset ||
aEvent.mInput.mLength != 1) {
if (aEvent.mInput.mOffset < mIMECompositionRectOffset ||
(aEvent.mInput.mOffset + aEvent.mInput.mLength >
mIMECompositionRectOffset + mIMECompositionRects.Length())) {
// XXX
// we doesn't have cache for this request.
break;
}
aEvent.mReply.mOffset = mIMECompositionRectOffset;
aEvent.mReply.mRect = mIMECompositionRect - GetChildProcessOffset();
uint32_t baseOffset = aEvent.mInput.mOffset - mIMECompositionRectOffset;
uint32_t endOffset = baseOffset + aEvent.mInput.mLength;
aEvent.mReply.mRect.SetEmpty();
for (uint32_t i = baseOffset; i < endOffset; i++) {
aEvent.mReply.mRect =
aEvent.mReply.mRect.Union(mIMECompositionRects[i]);
}
aEvent.mReply.mOffset = aEvent.mInput.mOffset;
aEvent.mReply.mRect = aEvent.mReply.mRect - GetChildProcessOffset();
aEvent.mSucceeded = true;
}
break;
case NS_QUERY_CARET_RECT:
{
if (aEvent.mInput.mOffset != mIMECompositionRectOffset) {
if (aEvent.mInput.mOffset != mIMECaretOffset) {
break;
}
aEvent.mReply.mOffset = mIMECompositionRectOffset;
aEvent.mReply.mOffset = mIMECaretOffset;
aEvent.mReply.mRect = mIMECaretRect - GetChildProcessOffset();
aEvent.mSucceeded = true;
}

Просмотреть файл

@ -163,9 +163,11 @@ public:
const uint32_t& aEnd,
const uint32_t& aNewEnd,
const bool& aCausedByComposition) MOZ_OVERRIDE;
virtual bool RecvNotifyIMESelectedCompositionRect(const uint32_t& aOffset,
const nsIntRect& aRect,
const nsIntRect& aCaretRect) MOZ_OVERRIDE;
virtual bool RecvNotifyIMESelectedCompositionRect(
const uint32_t& aOffset,
const InfallibleTArray<nsIntRect>& aRects,
const uint32_t& aCaretOffset,
const nsIntRect& aCaretRect) MOZ_OVERRIDE;
virtual bool RecvNotifyIMESelection(const uint32_t& aSeqno,
const uint32_t& aAnchor,
const uint32_t& aFocus,
@ -376,7 +378,8 @@ protected:
uint32_t mIMESeqno;
uint32_t mIMECompositionRectOffset;
nsIntRect mIMECompositionRect;
InfallibleTArray<nsIntRect> mIMECompositionRects;
uint32_t mIMECaretOffset;
nsIntRect mIMECaretRect;
// The number of event series we're currently capturing.

Просмотреть файл

@ -81,6 +81,8 @@ public:
return rv.ErrorCode();
}
notification->SetStoredState(true);
JSAutoCompartment ac(aCx, mGlobal);
JS::Rooted<JSObject*> element(aCx, notification->WrapObject(aCx));
NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
@ -369,6 +371,18 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
}
mNotification->DispatchTrustedEvent(NS_LITERAL_STRING("click"));
} else if (!strcmp("alertfinished", aTopic)) {
nsCOMPtr<nsINotificationStorage> notificationStorage =
do_GetService(NS_NOTIFICATION_STORAGE_CONTRACTID);
if (notificationStorage && mNotification->IsStored()) {
nsString origin;
nsresult rv = Notification::GetOrigin(mNotification->GetOwner(), origin);
if (NS_SUCCEEDED(rv)) {
nsString id;
mNotification->GetID(id);
notificationStorage->Delete(origin, id);
}
mNotification->SetStoredState(false);
}
mNotification->mIsClosed = true;
mNotification->DispatchTrustedEvent(NS_LITERAL_STRING("close"));
} else if (!strcmp("alertshow", aTopic)) {
@ -384,7 +398,7 @@ Notification::Notification(const nsAString& aID, const nsAString& aTitle, const
nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow),
mID(aID), mTitle(aTitle), mBody(aBody), mDir(aDir), mLang(aLang),
mTag(aTag), mIconUrl(aIconUrl), mIsClosed(false)
mTag(aTag), mIconUrl(aIconUrl), mIsClosed(false), mIsStored(false)
{
nsAutoString alertName;
DebugOnly<nsresult> rv = GetOrigin(GetOwner(), alertName);
@ -475,6 +489,8 @@ Notification::Constructor(const GlobalObject& aGlobal,
return nullptr;
}
notification->SetStoredState(true);
return notification.forget();
}
@ -781,7 +797,7 @@ Notification::Close()
void
Notification::CloseInternal()
{
if (!mIsClosed) {
if (mIsStored) {
// Don't bail out if notification storage fails, since we still
// want to send the close event through the alert service.
nsCOMPtr<nsINotificationStorage> notificationStorage =
@ -793,7 +809,9 @@ Notification::CloseInternal()
notificationStorage->Delete(origin, mID);
}
}
SetStoredState(false);
}
if (!mIsClosed) {
nsCOMPtr<nsIAlertsService> alertService =
do_GetService(NS_ALERTSERVICE_CONTRACTID);
if (alertService) {

Просмотреть файл

@ -77,6 +77,16 @@ public:
aRetval = mIconUrl;
}
void SetStoredState(bool val)
{
mIsStored = val;
}
bool IsStored()
{
return mIsStored;
}
nsIStructuredCloneContainer* GetDataCloneContainer();
static void RequestPermission(const GlobalObject& aGlobal,
@ -167,6 +177,12 @@ protected:
bool mIsClosed;
// We need to make a distinction between the notification being closed i.e.
// removed from any pending or active lists, and the notification being
// removed from the database. NotificationDB might fail when trying to remove
// the notification.
bool mIsStored;
static uint32_t sCount;
private:

Просмотреть файл

@ -16,13 +16,26 @@ var MockServices = (function () {
var activeAppNotifications = Object.create(null);
window.addEventListener('mock-notification-close-event', function(e) {
for (var alertName in activeAlertNotifications) {
var notif = activeAlertNotifications[alertName];
if (notif.title === e.detail.title) {
notif.listener.observe(null, "alertfinished", null);
delete activeAlertNotifications[alertName];
delete activeAppNotifications[alertName];
return;
}
}
});
var mockAlertsService = {
showAlertNotification: function(imageUrl, title, text, textClickable,
cookie, alertListener, name) {
var listener = SpecialPowers.wrap(alertListener);
activeAlertNotifications[name] = {
listener: listener,
cookie: cookie
cookie: cookie,
title: title
};
// fake async alert show event
@ -105,6 +118,7 @@ var MockServices = (function () {
},
activeAlertNotifications: activeAlertNotifications,
activeAppNotifications: activeAppNotifications,
};
})();

Просмотреть файл

@ -96,6 +96,14 @@ var NotificationTest = (function () {
// TODO: how??
},
fireCloseEvent: function (title) {
window.dispatchEvent(new CustomEvent("mock-notification-close-event", {
detail: {
title: title
}
}));
},
info: info,
customDataMatches: function(dataObj) {

Просмотреть файл

@ -119,10 +119,27 @@
promise.then(function (notifications) {
is(notifications.length, 3, "should return 3 notifications");
done();
n1.close();
n2.close();
n3.close();
});
},
deleteAllNotifications
deleteAllNotifications,
function (done) {
info("Testing 'alertfinished' removes the notification from DB");
var n = new Notification("test-title" + Math.random());
n.onclose = function() {
Notification.get().then(function(notifications) {
is(notifications.length, 0, "should return 0 notifications");
done();
});
}
window.setTimeout(function() {
NotificationTest.fireCloseEvent(n.title);
}, 100);
}
];
MockServices.register();

Просмотреть файл

@ -52,6 +52,9 @@ interface Element : Node {
[Pure]
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
[Throws, Pure]
Element? closest(DOMString selector);
[Throws, Pure]
boolean matches(DOMString selector);

Просмотреть файл

@ -19,7 +19,17 @@ interface SVGFEBlendElement : SVGElement {
const unsigned short SVG_FEBLEND_MODE_SCREEN = 3;
const unsigned short SVG_FEBLEND_MODE_DARKEN = 4;
const unsigned short SVG_FEBLEND_MODE_LIGHTEN = 5;
const unsigned short SVG_FEBLEND_MODE_OVERLAY = 6;
const unsigned short SVG_FEBLEND_MODE_COLOR_DODGE = 7;
const unsigned short SVG_FEBLEND_MODE_COLOR_BURN = 8;
const unsigned short SVG_FEBLEND_MODE_HARD_LIGHT = 9;
const unsigned short SVG_FEBLEND_MODE_SOFT_LIGHT = 10;
const unsigned short SVG_FEBLEND_MODE_DIFFERENCE = 11;
const unsigned short SVG_FEBLEND_MODE_EXCLUSION = 12;
const unsigned short SVG_FEBLEND_MODE_HUE = 13;
const unsigned short SVG_FEBLEND_MODE_SATURATION = 14;
const unsigned short SVG_FEBLEND_MODE_COLOR = 15;
const unsigned short SVG_FEBLEND_MODE_LUMINOSITY = 16;
readonly attribute SVGAnimatedString in1;
readonly attribute SVGAnimatedString in2;
readonly attribute SVGAnimatedEnumeration mode;

Просмотреть файл

@ -37,6 +37,7 @@ typedef _cairo_scaled_font cairo_scaled_font_t;
struct ID3D10Device1;
struct ID3D10Texture2D;
struct ID3D11Texture2D;
struct ID3D11Device;
struct ID2D1Device;
struct IDWriteRenderingParams;
@ -1190,9 +1191,12 @@ public:
static void SetDirect3D10Device(ID3D10Device1 *aDevice);
static ID3D10Device1 *GetDirect3D10Device();
#ifdef USE_D2D1_1
static TemporaryRef<DrawTarget> CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat);
static void SetDirect3D11Device(ID3D11Device *aDevice);
static ID3D11Device *GetDirect3D11Device();
static ID2D1Device *GetD2D1Device();
static bool SupportsD2D1();
#endif
static TemporaryRef<GlyphRenderingOptions>

Просмотреть файл

@ -333,13 +333,8 @@ DrawTargetD2D::GetImageForSurface(SourceSurface *aSurface)
{
RefPtr<ID2D1Image> image;
if (aSurface->GetType() == SurfaceType::D2D1_1_IMAGE) {
image = static_cast<SourceSurfaceD2D1*>(aSurface)->GetImage();
static_cast<SourceSurfaceD2D1*>(aSurface)->EnsureIndependent();
} else {
Rect r(Point(), Size(aSurface->GetSize()));
image = GetBitmapForSurface(aSurface, r);
}
Rect r(Point(), Size(aSurface->GetSize()));
image = GetBitmapForSurface(aSurface, r);
return image;
}
@ -2692,6 +2687,7 @@ DrawTargetD2D::factory()
#else
options.debugLevel = D2D1_DEBUG_LEVEL_NONE;
#endif
//options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
HRESULT hr = createD2DFactory(D2D1_FACTORY_TYPE_MULTI_THREADED,
__uuidof(ID2D1Factory),

Просмотреть файл

@ -39,7 +39,30 @@ DrawTargetD2D1::~DrawTargetD2D1()
{
PopAllClips();
if (mSnapshot) {
// We may hold the only reference. MarkIndependent will clear mSnapshot;
// keep the snapshot object alive so it doesn't get destroyed while
// MarkIndependent is running.
RefPtr<SourceSurfaceD2D1> deathGrip = mSnapshot;
// mSnapshot can be treated as independent of this DrawTarget since we know
// this DrawTarget won't change again.
deathGrip->MarkIndependent();
// mSnapshot will be cleared now.
}
mDC->EndDraw();
// Targets depending on us can break that dependency, since we're obviously not going to
// be modified in the future.
for (auto iter = mDependentTargets.begin();
iter != mDependentTargets.end(); iter++) {
(*iter)->mDependingOnTargets.erase(this);
}
// Our dependencies on other targets no longer matter.
for (TargetSet::iterator iter = mDependingOnTargets.begin();
iter != mDependingOnTargets.end(); iter++) {
(*iter)->mDependentTargets.erase(this);
}
}
TemporaryRef<SourceSurface>
@ -61,6 +84,13 @@ void
DrawTargetD2D1::Flush()
{
mDC->Flush();
// We no longer depend on any target.
for (TargetSet::iterator iter = mDependingOnTargets.begin();
iter != mDependingOnTargets.end(); iter++) {
(*iter)->mDependentTargets.erase(this);
}
mDependingOnTargets.clear();
}
void
@ -70,13 +100,6 @@ DrawTargetD2D1::DrawSurface(SourceSurface *aSurface,
const DrawSurfaceOptions &aSurfOptions,
const DrawOptions &aOptions)
{
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, ExtendMode::CLAMP);
if (!image) {
gfxWarning() << *this << ": Unable to get D2D image for surface.";
return;
}
PrepareForDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
D2D1_RECT_F samplingBounds;
@ -95,10 +118,21 @@ DrawTargetD2D1::DrawSurface(SourceSurface *aSurface,
// Here we scale the source pattern up to the size and position where we want
// it to be.
Matrix transform;
transform.PreTranslate(aDest.x, aDest.y);
transform.PreTranslate(aDest.x - aSource.x * xScale, aDest.y - aSource.y * yScale);
transform.PreScale(xScale, yScale);
mDC->CreateImageBrush(image, D2D1::ImageBrushProperties(samplingBounds),
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, transform, ExtendMode::CLAMP);
if (!image) {
gfxWarning() << *this << ": Unable to get D2D image for surface.";
return;
}
mDC->CreateImageBrush(image,
D2D1::ImageBrushProperties(samplingBounds,
D2D1_EXTEND_MODE_CLAMP,
D2D1_EXTEND_MODE_CLAMP,
D2DInterpolationMode(aSurfOptions.mFilter)),
D2D1::BrushProperties(aOptions.mAlpha, D2DMatrix(transform)),
byRef(brush));
mDC->FillRectangle(D2DRect(aDest), brush);
@ -119,7 +153,11 @@ DrawTargetD2D1::DrawFilter(FilterNode *aNode,
PrepareForDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
mDC->DrawImage(static_cast<FilterNodeD2D1*>(aNode)->OutputEffect(), D2DPoint(aDestPoint), D2DRect(aSourceRect));
FinalizeDrawing(aOptions.mCompositionOp, ColorPattern(Color()));
}
void
@ -150,22 +188,11 @@ DrawTargetD2D1::DrawSurfaceWithShadow(SourceSurface *aSurface,
D2D1_VECTOR_4F color = { aColor.r, aColor.g, aColor.b, aColor.a };
shadowEffect->SetValue(D2D1_SHADOW_PROP_COLOR, color);
// Step 2, move the shadow effect into place.
RefPtr<ID2D1Effect> affineTransformEffect;
mDC->CreateEffect(CLSID_D2D12DAffineTransform, byRef(affineTransformEffect));
affineTransformEffect->SetInputEffect(0, shadowEffect);
D2D1_MATRIX_3X2_F matrix = D2D1::Matrix3x2F::Translation(aOffset.x, aOffset.y);
affineTransformEffect->SetValue(D2D1_2DAFFINETRANSFORM_PROP_TRANSFORM_MATRIX, matrix);
D2D1_POINT_2F shadowPoint = D2DPoint(aDest + aOffset);
mDC->DrawImage(shadowEffect, &shadowPoint, nullptr, D2D1_INTERPOLATION_MODE_LINEAR, D2DCompositionMode(aOperator));
// Step 3, create an effect that combines shadow and bitmap in one image.
RefPtr<ID2D1Effect> compositeEffect;
mDC->CreateEffect(CLSID_D2D1Composite, byRef(compositeEffect));
compositeEffect->SetInputEffect(0, affineTransformEffect);
compositeEffect->SetInput(1, image);
compositeEffect->SetValue(D2D1_COMPOSITE_PROP_MODE, D2DCompositionMode(aOperator));
D2D1_POINT_2F surfPoint = D2DPoint(aDest);
mDC->DrawImage(compositeEffect, &surfPoint, nullptr, D2D1_INTERPOLATION_MODE_LINEAR, D2DCompositionMode(aOperator));
D2D1_POINT_2F imgPoint = D2DPoint(aDest);
mDC->DrawImage(image, &imgPoint, nullptr, D2D1_INTERPOLATION_MODE_LINEAR, D2DCompositionMode(aOperator));
}
void
@ -173,9 +200,46 @@ DrawTargetD2D1::ClearRect(const Rect &aRect)
{
MarkChanged();
mDC->PushAxisAlignedClip(D2DRect(aRect), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
PopAllClips();
PushClipRect(aRect);
if (mTransformDirty ||
!mTransform.IsIdentity()) {
mDC->SetTransform(D2D1::IdentityMatrix());
mTransformDirty = true;
}
D2D1_RECT_F clipRect;
bool isPixelAligned;
if (mTransform.IsRectilinear() &&
GetDeviceSpaceClipRect(clipRect, isPixelAligned)) {
mDC->PushAxisAlignedClip(clipRect, isPixelAligned ? D2D1_ANTIALIAS_MODE_ALIASED : D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
mDC->Clear();
mDC->PopAxisAlignedClip();
PopClip();
return;
}
mDC->SetTarget(mTempBitmap);
mDC->Clear();
IntRect addClipRect;
RefPtr<ID2D1Geometry> geom = GetClippedGeometry(&addClipRect);
RefPtr<ID2D1SolidColorBrush> brush;
mDC->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), byRef(brush));
mDC->PushAxisAlignedClip(D2D1::RectF(addClipRect.x, addClipRect.y, addClipRect.XMost(), addClipRect.YMost()), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
mDC->FillGeometry(geom, brush);
mDC->PopAxisAlignedClip();
mDC->SetTarget(mBitmap);
mDC->DrawImage(mTempBitmap, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_DESTINATION_OUT);
PopClip();
return;
}
void
@ -184,12 +248,12 @@ DrawTargetD2D1::MaskSurface(const Pattern &aSource,
Point aOffset,
const DrawOptions &aOptions)
{
PrepareForDrawing(aOptions.mCompositionOp, aSource);
RefPtr<ID2D1Bitmap> bitmap;
RefPtr<ID2D1Image> image = GetImageForSurface(aMask, ExtendMode::CLAMP);
PrepareForDrawing(aOptions.mCompositionOp, aSource);
// FillOpacityMask only works if the antialias mode is MODE_ALIASED
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
@ -217,6 +281,8 @@ DrawTargetD2D1::CopySurface(SourceSurface *aSurface,
{
MarkChanged();
PopAllClips();
mDC->SetTransform(D2D1::IdentityMatrix());
mTransformDirty = true;
@ -228,6 +294,26 @@ DrawTargetD2D1::CopySurface(SourceSurface *aSurface,
return;
}
if (mFormat == SurfaceFormat::A8) {
RefPtr<ID2D1Bitmap> bitmap;
image->QueryInterface((ID2D1Bitmap**)byRef(bitmap));
mDC->PushAxisAlignedClip(D2D1::RectF(aDestination.x, aDestination.y,
aDestination.x + aSourceRect.width,
aDestination.y + aSourceRect.height),
D2D1_ANTIALIAS_MODE_ALIASED);
mDC->Clear();
mDC->PopAxisAlignedClip();
RefPtr<ID2D1SolidColorBrush> brush;
mDC->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White),
D2D1::BrushProperties(), byRef(brush));
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
mDC->FillOpacityMask(bitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS);
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
return;
}
mDC->DrawImage(image, D2D1::Point2F(Float(aDestination.x), Float(aDestination.y)),
D2D1::RectF(Float(aSourceRect.x), Float(aSourceRect.y),
Float(aSourceRect.XMost()), Float(aSourceRect.YMost())),
@ -241,6 +327,8 @@ DrawTargetD2D1::FillRect(const Rect &aRect,
{
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
mDC->FillRectangle(D2DRect(aRect), brush);
@ -255,6 +343,8 @@ DrawTargetD2D1::StrokeRect(const Rect &aRect,
{
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
@ -272,6 +362,8 @@ DrawTargetD2D1::StrokeLine(const Point &aStart,
{
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
@ -294,6 +386,8 @@ DrawTargetD2D1::Stroke(const Path *aPath,
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
@ -315,6 +409,8 @@ DrawTargetD2D1::Fill(const Path *aPath,
PrepareForDrawing(aOptions.mCompositionOp, aPattern);
mDC->SetAntialiasMode(D2DAAMode(aOptions.mAntialiasMode));
RefPtr<ID2D1Brush> brush = CreateBrushForPattern(aPattern, aOptions.mAlpha);
mDC->FillGeometry(d2dPath->mGeometry, brush);
@ -436,6 +532,8 @@ DrawTargetD2D1::PushClip(const Path *aPath)
return;
}
mCurrentClippedGeometry = nullptr;
RefPtr<PathD2D> pathD2D = static_cast<PathD2D*>(const_cast<Path*>(aPath));
PushedClip clip;
@ -474,6 +572,8 @@ DrawTargetD2D1::PushClipRect(const Rect &aRect)
return PushClip(path);
}
mCurrentClippedGeometry = nullptr;
PushedClip clip;
Rect rect = mTransform.TransformBounds(aRect);
IntRect intRect;
@ -495,6 +595,8 @@ DrawTargetD2D1::PushClipRect(const Rect &aRect)
void
DrawTargetD2D1::PopClip()
{
mCurrentClippedGeometry = nullptr;
if (mClipsArePushed) {
if (mPushedClips.back().mPath) {
mDC->PopLayer();
@ -564,6 +666,11 @@ DrawTargetD2D1::CreatePathBuilder(FillRule aFillRule) const
TemporaryRef<GradientStops>
DrawTargetD2D1::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops, ExtendMode aExtendMode) const
{
if (aNumStops == 0) {
gfxWarning() << *this << ": Failed to create GradientStopCollection with no stops.";
return nullptr;
}
D2D1_GRADIENT_STOP *stops = new D2D1_GRADIENT_STOP[aNumStops];
for (uint32_t i = 0; i < aNumStops; i++) {
@ -594,10 +701,10 @@ DrawTargetD2D1::CreateFilter(FilterType aType)
}
bool
DrawTargetD2D1::Init(const IntSize &aSize, SurfaceFormat aFormat)
DrawTargetD2D1::Init(ID3D11Texture2D* aTexture, SurfaceFormat aFormat)
{
HRESULT hr;
hr = Factory::GetD2D1Device()->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, byRef(mDC));
if (FAILED(hr)) {
@ -605,6 +712,62 @@ DrawTargetD2D1::Init(const IntSize &aSize, SurfaceFormat aFormat)
return false;
}
RefPtr<IDXGISurface> dxgiSurface;
aTexture->QueryInterface(__uuidof(IDXGISurface),
(void**)((IDXGISurface**)byRef(dxgiSurface)));
if (!dxgiSurface) {
return false;
}
D2D1_BITMAP_PROPERTIES1 props;
props.dpiX = 96;
props.dpiY = 96;
props.pixelFormat = D2DPixelFormat(aFormat);
props.colorContext = nullptr;
props.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
hr = mDC->CreateBitmapFromDxgiSurface(dxgiSurface, props, (ID2D1Bitmap1**)byRef(mBitmap));
if (FAILED(hr)) {
gfxWarning() << *this << ": Error " << hr << " failed to create new bitmap.";
return false;
}
mFormat = aFormat;
D3D11_TEXTURE2D_DESC desc;
aTexture->GetDesc(&desc);
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
mSize.width = desc.Width;
mSize.height = desc.Height;
props.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
props.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
mDC->CreateBitmap(D2DIntSize(mSize), nullptr, 0, props, (ID2D1Bitmap1**)byRef(mTempBitmap));
mDC->SetTarget(mBitmap);
mDC->BeginDraw();
return true;
}
bool
DrawTargetD2D1::Init(const IntSize &aSize, SurfaceFormat aFormat)
{
HRESULT hr;
hr = Factory::GetD2D1Device()->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, byRef(mDC));
if (FAILED(hr)) {
gfxWarning() << *this << ": Error " << hr << " failed to initialize new DeviceContext.";
return false;
}
if (mDC->GetMaximumBitmapSize() < UINT32(aSize.width) ||
mDC->GetMaximumBitmapSize() < UINT32(aSize.height)) {
// This is 'ok'
gfxDebug() << *this << ": Attempt to use unsupported surface size for D2D 1.1.";
return false;
}
D2D1_BITMAP_PROPERTIES1 props;
props.dpiX = 96;
props.dpiY = 96;
@ -618,12 +781,17 @@ DrawTargetD2D1::Init(const IntSize &aSize, SurfaceFormat aFormat)
return false;
}
props.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
props.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
mDC->CreateBitmap(D2DIntSize(aSize), nullptr, 0, props, (ID2D1Bitmap1**)byRef(mTempBitmap));
mDC->SetTarget(mBitmap);
mDC->BeginDraw();
mDC->Clear();
mFormat = aFormat;
mSize = aSize;
@ -718,14 +886,42 @@ DrawTargetD2D1::FinalizeDrawing(CompositionOp aOp, const Pattern &aPattern)
mDC->SetTarget(mBitmap);
if (patternSupported) {
mDC->DrawImage(image, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2DCompositionMode(aOp));
return;
}
mDC->SetTransform(D2D1::IdentityMatrix());
mTransformDirty = true;
if (patternSupported) {
if (D2DSupportsCompositeMode(aOp)) {
mDC->DrawImage(image, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2DCompositionMode(aOp));
return;
}
if (!mBlendEffect) {
mDC->CreateEffect(CLSID_D2D1Blend, byRef(mBlendEffect));
if (!mBlendEffect) {
gfxWarning() << "Failed to create blend effect!";
return;
}
}
RefPtr<ID2D1Bitmap> tmpBitmap;
mDC->CreateBitmap(D2DIntSize(mSize), D2D1::BitmapProperties(D2DPixelFormat(mFormat)), byRef(tmpBitmap));
// This flush is important since the copy method will not know about the context drawing to the surface.
mDC->Flush();
// We need to use a copy here because affects don't accept a surface on
// both their in- and outputs.
tmpBitmap->CopyFromBitmap(nullptr, mBitmap, nullptr);
mBlendEffect->SetInput(0, tmpBitmap);
mBlendEffect->SetInput(1, mTempBitmap);
mBlendEffect->SetValue(D2D1_BLEND_PROP_MODE, D2DBlendMode(aOp));
mDC->DrawImage(mBlendEffect, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
return;
}
RefPtr<ID2D1Effect> radialGradientEffect;
mDC->CreateEffect(CLSID_RadialGradientEffect, byRef(radialGradientEffect));
@ -753,6 +949,128 @@ DrawTargetD2D1::AddDependencyOnSource(SourceSurfaceD2D1* aSource)
}
}
static D2D1_RECT_F
IntersectRect(const D2D1_RECT_F& aRect1, const D2D1_RECT_F& aRect2)
{
D2D1_RECT_F result;
result.left = max(aRect1.left, aRect2.left);
result.top = max(aRect1.top, aRect2.top);
result.right = min(aRect1.right, aRect2.right);
result.bottom = min(aRect1.bottom, aRect2.bottom);
result.right = max(result.right, result.left);
result.bottom = max(result.bottom, result.top);
return result;
}
bool
DrawTargetD2D1::GetDeviceSpaceClipRect(D2D1_RECT_F& aClipRect, bool& aIsPixelAligned)
{
if (!mPushedClips.size()) {
return false;
}
aClipRect = D2D1::RectF(0, 0, mSize.width, mSize.height);
for (auto iter = mPushedClips.begin();iter != mPushedClips.end(); iter++) {
if (iter->mPath) {
return false;
}
aClipRect = IntersectRect(aClipRect, iter->mBounds);
if (!iter->mIsPixelAligned) {
aIsPixelAligned = false;
}
}
return true;
}
TemporaryRef<ID2D1Geometry>
DrawTargetD2D1::GetClippedGeometry(IntRect *aClipBounds)
{
if (mCurrentClippedGeometry) {
*aClipBounds = mCurrentClipBounds;
return mCurrentClippedGeometry;
}
mCurrentClipBounds = IntRect(IntPoint(0, 0), mSize);
// if pathGeom is null then pathRect represents the path.
RefPtr<ID2D1Geometry> pathGeom;
D2D1_RECT_F pathRect;
bool pathRectIsAxisAligned = false;
auto iter = mPushedClips.begin();
if (iter->mPath) {
pathGeom = GetTransformedGeometry(iter->mPath->GetGeometry(), iter->mTransform);
} else {
pathRect = iter->mBounds;
pathRectIsAxisAligned = iter->mIsPixelAligned;
}
iter++;
for (;iter != mPushedClips.end(); iter++) {
// Do nothing but add it to the current clip bounds.
if (!iter->mPath && iter->mIsPixelAligned) {
mCurrentClipBounds.IntersectRect(mCurrentClipBounds,
IntRect(int32_t(iter->mBounds.left), int32_t(iter->mBounds.top),
int32_t(iter->mBounds.right - iter->mBounds.left),
int32_t(iter->mBounds.bottom - iter->mBounds.top)));
continue;
}
if (!pathGeom) {
if (pathRectIsAxisAligned) {
mCurrentClipBounds.IntersectRect(mCurrentClipBounds,
IntRect(int32_t(pathRect.left), int32_t(pathRect.top),
int32_t(pathRect.right - pathRect.left),
int32_t(pathRect.bottom - pathRect.top)));
}
if (iter->mPath) {
// See if pathRect needs to go into the path geometry.
if (!pathRectIsAxisAligned) {
pathGeom = ConvertRectToGeometry(pathRect);
} else {
pathGeom = GetTransformedGeometry(iter->mPath->GetGeometry(), iter->mTransform);
}
} else {
pathRect = IntersectRect(pathRect, iter->mBounds);
pathRectIsAxisAligned = false;
continue;
}
}
RefPtr<ID2D1PathGeometry> newGeom;
factory()->CreatePathGeometry(byRef(newGeom));
RefPtr<ID2D1GeometrySink> currentSink;
newGeom->Open(byRef(currentSink));
if (iter->mPath) {
pathGeom->CombineWithGeometry(iter->mPath->GetGeometry(), D2D1_COMBINE_MODE_INTERSECT,
iter->mTransform, currentSink);
} else {
RefPtr<ID2D1Geometry> rectGeom = ConvertRectToGeometry(iter->mBounds);
pathGeom->CombineWithGeometry(rectGeom, D2D1_COMBINE_MODE_INTERSECT,
D2D1::IdentityMatrix(), currentSink);
}
currentSink->Close();
pathGeom = newGeom.forget();
}
// For now we need mCurrentClippedGeometry to always be non-nullptr. This
// method might seem a little strange but it is just fine, if pathGeom is
// nullptr pathRect will always still contain 1 clip unaccounted for
// regardless of mCurrentClipBounds.
if (!pathGeom) {
pathGeom = ConvertRectToGeometry(pathRect);
}
mCurrentClippedGeometry = pathGeom.forget();
*aClipBounds = mCurrentClipBounds;
return mCurrentClippedGeometry;
}
void
DrawTargetD2D1::PopAllClips()
{
@ -791,6 +1109,14 @@ DrawTargetD2D1::PopClipsFromDC(ID2D1DeviceContext *aDC)
}
}
TemporaryRef<ID2D1Brush>
DrawTargetD2D1::CreateTransparentBlackBrush()
{
RefPtr<ID2D1SolidColorBrush> brush;
mDC->CreateSolidColorBrush(D2D1::ColorF(0, 0), byRef(brush));
return brush;
}
TemporaryRef<ID2D1Brush>
DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
{
@ -818,7 +1144,7 @@ DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
if (!stops) {
gfxDebug() << "No stops specified for gradient pattern.";
return nullptr;
return CreateTransparentBlackBrush();
}
if (pat->mBegin == pat->mEnd) {
@ -848,7 +1174,7 @@ DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
if (!stops) {
gfxDebug() << "No stops specified for gradient pattern.";
return nullptr;
return CreateTransparentBlackBrush();
}
// This will not be a complex radial gradient brush.
@ -868,7 +1194,7 @@ DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
if (!pat->mSurface) {
gfxDebug() << "No source surface specified for surface pattern";
return nullptr;
return CreateTransparentBlackBrush();
}
D2D1_RECT_F samplingBounds;
@ -895,7 +1221,7 @@ DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
}
gfxWarning() << "Invalid pattern type detected.";
return nullptr;
return CreateTransparentBlackBrush();
}
TemporaryRef<ID2D1Image>

Просмотреть файл

@ -125,6 +125,7 @@ public:
virtual void *GetNativeSurface(NativeSurfaceType aType) { return nullptr; }
bool Init(const IntSize &aSize, SurfaceFormat aFormat);
bool Init(ID3D11Texture2D* aTexture, SurfaceFormat aFormat);
uint32_t GetByteSize() const;
TemporaryRef<ID2D1Image> GetImageForSurface(SourceSurface *aSurface, Matrix &aSourceTransform,
@ -170,10 +171,19 @@ private:
}
void AddDependencyOnSource(SourceSurfaceD2D1* aSource);
// This returns the clipped geometry, in addition it returns aClipBounds which
// represents the intersection of all pixel-aligned rectangular clips that
// are currently set. The returned clipped geometry must be clipped by these
// bounds to correctly reflect the total clip. This is in device space.
TemporaryRef<ID2D1Geometry> GetClippedGeometry(IntRect *aClipBounds);
bool GetDeviceSpaceClipRect(D2D1_RECT_F& aClipRect, bool& aIsPixelAligned);
void PopAllClips();
void PushClipsToDC(ID2D1DeviceContext *aDC);
void PopClipsFromDC(ID2D1DeviceContext *aDC);
TemporaryRef<ID2D1Brush> CreateTransparentBlackBrush();
TemporaryRef<ID2D1Brush> CreateBrushForPattern(const Pattern &aPattern, Float aAlpha = 1.0f);
void PushD2DLayer(ID2D1DeviceContext *aDC, ID2D1Geometry *aGeometry, const D2D1_MATRIX_3X2_F &aTransform);
@ -182,6 +192,7 @@ private:
RefPtr<ID3D11Device> mDevice;
RefPtr<ID3D11Texture2D> mTexture;
RefPtr<ID2D1Geometry> mCurrentClippedGeometry;
// This is only valid if mCurrentClippedGeometry is non-null. And will
// only be the intersection of all pixel-aligned retangular clips. This is in
// device space.
@ -189,6 +200,7 @@ private:
mutable RefPtr<ID2D1DeviceContext> mDC;
RefPtr<ID2D1Bitmap1> mBitmap;
RefPtr<ID2D1Bitmap1> mTempBitmap;
RefPtr<ID2D1Effect> mBlendEffect;
// We store this to prevent excessive SetTextRenderingParams calls.
RefPtr<IDWriteRenderingParams> mTextRenderingParams;

Просмотреть файл

@ -548,6 +548,7 @@ Factory::SetDirect3D10Device(ID3D10Device1 *aDevice)
ID3D10Device1*
Factory::GetDirect3D10Device()
{
#ifdef DEBUG
UINT mode = mD3D10Device->GetExceptionMode();
@ -557,6 +558,28 @@ Factory::GetDirect3D10Device()
}
#ifdef USE_D2D1_1
TemporaryRef<DrawTarget>
Factory::CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat)
{
RefPtr<DrawTargetD2D1> newTarget;
newTarget = new DrawTargetD2D1();
if (newTarget->Init(aTexture, aFormat)) {
RefPtr<DrawTarget> retVal = newTarget;
if (mRecorder) {
retVal = new DrawTargetRecording(mRecorder, retVal, true);
}
return retVal;
}
gfxWarning() << "Failed to create draw target for D3D10 texture.";
// Failed
return nullptr;
}
void
Factory::SetDirect3D11Device(ID3D11Device *aDevice)
{
@ -580,6 +603,12 @@ Factory::GetD2D1Device()
{
return mD2D1Device;
}
bool
Factory::SupportsD2D1()
{
return !!D2DFactory1();
}
#endif
TemporaryRef<GlyphRenderingOptions>

Просмотреть файл

@ -57,6 +57,29 @@ D2D1_BLEND_MODE D2DBlendMode(uint32_t aMode)
return D2D1_BLEND_MODE_MULTIPLY;
case BLEND_MODE_SCREEN:
return D2D1_BLEND_MODE_SCREEN;
case BLEND_MODE_OVERLAY:
return D2D1_BLEND_MODE_OVERLAY;
case BLEND_MODE_COLOR_DODGE:
return D2D1_BLEND_MODE_COLOR_DODGE;
case BLEND_MODE_COLOR_BURN:
return D2D1_BLEND_MODE_COLOR_BURN;
case BLEND_MODE_HARD_LIGHT:
return D2D1_BLEND_MODE_HARD_LIGHT;
case BLEND_MODE_SOFT_LIGHT:
return D2D1_BLEND_MODE_SOFT_LIGHT;
case BLEND_MODE_DIFFERENCE:
return D2D1_BLEND_MODE_DIFFERENCE;
case BLEND_MODE_EXCLUSION:
return D2D1_BLEND_MODE_EXCLUSION;
case BLEND_MODE_HUE:
return D2D1_BLEND_MODE_HUE;
case BLEND_MODE_SATURATION:
return D2D1_BLEND_MODE_SATURATION;
case BLEND_MODE_COLOR:
return D2D1_BLEND_MODE_COLOR;
case BLEND_MODE_LUMINOSITY:
return D2D1_BLEND_MODE_LUMINOSITY;
default:
MOZ_CRASH("Unknown enum value!");
}

Просмотреть файл

@ -994,6 +994,46 @@ FilterNodeBlendSoftware::SetAttribute(uint32_t aIndex, uint32_t aBlendMode)
Invalidate();
}
static CompositionOp ToBlendOp(BlendMode aOp)
{
switch (aOp) {
case BLEND_MODE_MULTIPLY:
return CompositionOp::OP_MULTIPLY;
case BLEND_MODE_SCREEN:
return CompositionOp::OP_SCREEN;
case BLEND_MODE_OVERLAY:
return CompositionOp::OP_OVERLAY;
case BLEND_MODE_DARKEN:
return CompositionOp::OP_DARKEN;
case BLEND_MODE_LIGHTEN:
return CompositionOp::OP_LIGHTEN;
case BLEND_MODE_COLOR_DODGE:
return CompositionOp::OP_COLOR_DODGE;
case BLEND_MODE_COLOR_BURN:
return CompositionOp::OP_COLOR_BURN;
case BLEND_MODE_HARD_LIGHT:
return CompositionOp::OP_HARD_LIGHT;
case BLEND_MODE_SOFT_LIGHT:
return CompositionOp::OP_SOFT_LIGHT;
case BLEND_MODE_DIFFERENCE:
return CompositionOp::OP_DIFFERENCE;
case BLEND_MODE_EXCLUSION:
return CompositionOp::OP_EXCLUSION;
case BLEND_MODE_HUE:
return CompositionOp::OP_HUE;
case BLEND_MODE_SATURATION:
return CompositionOp::OP_SATURATION;
case BLEND_MODE_COLOR:
return CompositionOp::OP_COLOR;
case BLEND_MODE_LUMINOSITY:
return CompositionOp::OP_LUMINOSITY;
default:
return CompositionOp::OP_OVER;
}
return CompositionOp::OP_OVER;
}
TemporaryRef<DataSourceSurface>
FilterNodeBlendSoftware::Render(const IntRect& aRect)
{
@ -1010,14 +1050,38 @@ FilterNodeBlendSoftware::Render(const IntRect& aRect)
return nullptr;
}
// Second case: both are non-transparent.
if (input1 && input2) {
// Apply normal filtering.
return FilterProcessing::ApplyBlending(input1, input2, mBlendMode);
// Second case: one of them is transparent. Return the non-transparent one.
if (!input1 || !input2) {
return input1 ? input1.forget() : input2.forget();
}
// Third case: one of them is transparent. Return the non-transparent one.
return input1 ? input1.forget() : input2.forget();
// Third case: both are non-transparent.
// Apply normal filtering.
RefPtr<DataSourceSurface> target = FilterProcessing::ApplyBlending(input1, input2, mBlendMode);
if (target != nullptr) {
return target.forget();
}
IntSize size = input1->GetSize();
target =
Factory::CreateDataSourceSurface(size, SurfaceFormat::B8G8R8A8);
if (MOZ2D_WARN_IF(!target)) {
return nullptr;
}
CopyRect(input1, target, IntRect(IntPoint(), size), IntPoint());
RefPtr<DrawTarget> dt =
Factory::CreateDrawTargetForData(BackendType::CAIRO,
target->GetData(),
target->GetSize(),
target->Stride(),
target->GetFormat());
Rect r(0, 0, size.width, size.height);
dt->DrawSurface(input2, r, r, DrawSurfaceOptions(), DrawOptions(1.0f, ToBlendOp(mBlendMode)));
dt->Flush();
return target.forget();
}
void

Просмотреть файл

@ -53,7 +53,7 @@ FilterProcessing::ApplyBlending(DataSourceSurface* aInput1, DataSourceSurface* a
return ApplyBlending_SSE2(aInput1, aInput2, aBlendMode);
#endif
}
return ApplyBlending_Scalar(aInput1, aInput2, aBlendMode);
return nullptr;
}
void

Просмотреть файл

@ -67,7 +67,6 @@ public:
protected:
static void ExtractAlpha_Scalar(const IntSize& size, uint8_t* sourceData, int32_t sourceStride, uint8_t* alphaData, int32_t alphaStride);
static TemporaryRef<DataSourceSurface> ConvertToB8G8R8A8_Scalar(SourceSurface* aSurface);
static TemporaryRef<DataSourceSurface> ApplyBlending_Scalar(DataSourceSurface* aInput1, DataSourceSurface* aInput2, BlendMode aBlendMode);
static void ApplyMorphologyHorizontal_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
uint8_t* aDestData, int32_t aDestStride,
const IntRect& aDestRect, int32_t aRadius,

Просмотреть файл

@ -29,84 +29,6 @@ FilterProcessing::ConvertToB8G8R8A8_Scalar(SourceSurface* aSurface)
return ConvertToB8G8R8A8_SIMD<simd::Scalaru8x16_t>(aSurface);
}
template<BlendMode aBlendMode>
static TemporaryRef<DataSourceSurface>
ApplyBlending_Scalar(DataSourceSurface* aInput1, DataSourceSurface* aInput2)
{
IntSize size = aInput1->GetSize();
RefPtr<DataSourceSurface> target =
Factory::CreateDataSourceSurface(size, SurfaceFormat::B8G8R8A8);
if (MOZ2D_WARN_IF(!target)) {
return nullptr;
}
uint8_t* source1Data = aInput1->GetData();
uint8_t* source2Data = aInput2->GetData();
uint8_t* targetData = target->GetData();
uint32_t targetStride = target->Stride();
uint32_t source1Stride = aInput1->Stride();
uint32_t source2Stride = aInput2->Stride();
for (int32_t y = 0; y < size.height; y++) {
for (int32_t x = 0; x < size.width; x++) {
uint32_t targetIndex = y * targetStride + 4 * x;
uint32_t source1Index = y * source1Stride + 4 * x;
uint32_t source2Index = y * source2Stride + 4 * x;
uint32_t qa = source1Data[source1Index + B8G8R8A8_COMPONENT_BYTEOFFSET_A];
uint32_t qb = source2Data[source2Index + B8G8R8A8_COMPONENT_BYTEOFFSET_A];
for (int32_t i = std::min(B8G8R8A8_COMPONENT_BYTEOFFSET_B, B8G8R8A8_COMPONENT_BYTEOFFSET_R);
i <= std::max(B8G8R8A8_COMPONENT_BYTEOFFSET_B, B8G8R8A8_COMPONENT_BYTEOFFSET_R); i++) {
uint32_t ca = source1Data[source1Index + i];
uint32_t cb = source2Data[source2Index + i];
uint32_t val;
switch (aBlendMode) {
case BLEND_MODE_MULTIPLY:
val = ((255 - qa) * cb + (255 - qb + cb) * ca);
break;
case BLEND_MODE_SCREEN:
val = 255 * (cb + ca) - ca * cb;
break;
case BLEND_MODE_DARKEN:
val = umin((255 - qa) * cb + 255 * ca,
(255 - qb) * ca + 255 * cb);
break;
case BLEND_MODE_LIGHTEN:
val = umax((255 - qa) * cb + 255 * ca,
(255 - qb) * ca + 255 * cb);
break;
default:
MOZ_CRASH();
}
val = umin(FilterProcessing::FastDivideBy255<unsigned>(val), 255U);
targetData[targetIndex + i] = static_cast<uint8_t>(val);
}
uint32_t alpha = 255 * 255 - (255 - qa) * (255 - qb);
targetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_A] =
FilterProcessing::FastDivideBy255<uint8_t>(alpha);
}
}
return target.forget();
}
TemporaryRef<DataSourceSurface>
FilterProcessing::ApplyBlending_Scalar(DataSourceSurface* aInput1, DataSourceSurface* aInput2,
BlendMode aBlendMode)
{
switch (aBlendMode) {
case BLEND_MODE_MULTIPLY:
return gfx::ApplyBlending_Scalar<BLEND_MODE_MULTIPLY>(aInput1, aInput2);
case BLEND_MODE_SCREEN:
return gfx::ApplyBlending_Scalar<BLEND_MODE_SCREEN>(aInput1, aInput2);
case BLEND_MODE_DARKEN:
return gfx::ApplyBlending_Scalar<BLEND_MODE_DARKEN>(aInput1, aInput2);
case BLEND_MODE_LIGHTEN:
return gfx::ApplyBlending_Scalar<BLEND_MODE_LIGHTEN>(aInput1, aInput2);
default:
return nullptr;
}
}
template<MorphologyOperator Operator>
static void
ApplyMorphologyHorizontal_Scalar(uint8_t* aSourceData, int32_t aSourceStride,

Просмотреть файл

@ -45,7 +45,18 @@ enum BlendMode
BLEND_MODE_MULTIPLY = 0,
BLEND_MODE_SCREEN,
BLEND_MODE_DARKEN,
BLEND_MODE_LIGHTEN
BLEND_MODE_LIGHTEN,
BLEND_MODE_OVERLAY,
BLEND_MODE_COLOR_DODGE,
BLEND_MODE_COLOR_BURN,
BLEND_MODE_HARD_LIGHT,
BLEND_MODE_SOFT_LIGHT,
BLEND_MODE_DIFFERENCE,
BLEND_MODE_EXCLUSION,
BLEND_MODE_HUE,
BLEND_MODE_SATURATION,
BLEND_MODE_COLOR,
BLEND_MODE_LUMINOSITY
};
enum BlendFilterInputs

Просмотреть файл

@ -194,6 +194,26 @@ static inline D2D1_PIXEL_FORMAT D2DPixelFormat(SurfaceFormat aFormat)
}
#ifdef USE_D2D1_1
static inline bool D2DSupportsCompositeMode(CompositionOp aOp)
{
switch(aOp) {
case CompositionOp::OP_OVER:
case CompositionOp::OP_ADD:
case CompositionOp::OP_ATOP:
case CompositionOp::OP_OUT:
case CompositionOp::OP_IN:
case CompositionOp::OP_SOURCE:
case CompositionOp::OP_DEST_IN:
case CompositionOp::OP_DEST_OUT:
case CompositionOp::OP_DEST_OVER:
case CompositionOp::OP_DEST_ATOP:
case CompositionOp::OP_XOR:
return true;
default:
return false;
}
}
static inline D2D1_COMPOSITE_MODE D2DCompositionMode(CompositionOp aOp)
{
switch(aOp) {
@ -223,6 +243,44 @@ static inline D2D1_COMPOSITE_MODE D2DCompositionMode(CompositionOp aOp)
return D2D1_COMPOSITE_MODE_SOURCE_OVER;
}
}
static inline D2D1_BLEND_MODE D2DBlendMode(CompositionOp aOp)
{
switch (aOp) {
case CompositionOp::OP_MULTIPLY:
return D2D1_BLEND_MODE_MULTIPLY;
case CompositionOp::OP_SCREEN:
return D2D1_BLEND_MODE_SCREEN;
case CompositionOp::OP_OVERLAY:
return D2D1_BLEND_MODE_OVERLAY;
case CompositionOp::OP_DARKEN:
return D2D1_BLEND_MODE_DARKEN;
case CompositionOp::OP_LIGHTEN:
return D2D1_BLEND_MODE_LIGHTEN;
case CompositionOp::OP_COLOR_DODGE:
return D2D1_BLEND_MODE_COLOR_DODGE;
case CompositionOp::OP_COLOR_BURN:
return D2D1_BLEND_MODE_COLOR_BURN;
case CompositionOp::OP_HARD_LIGHT:
return D2D1_BLEND_MODE_HARD_LIGHT;
case CompositionOp::OP_SOFT_LIGHT:
return D2D1_BLEND_MODE_SOFT_LIGHT;
case CompositionOp::OP_DIFFERENCE:
return D2D1_BLEND_MODE_DIFFERENCE;
case CompositionOp::OP_EXCLUSION:
return D2D1_BLEND_MODE_EXCLUSION;
case CompositionOp::OP_HUE:
return D2D1_BLEND_MODE_HUE;
case CompositionOp::OP_SATURATION:
return D2D1_BLEND_MODE_SATURATION;
case CompositionOp::OP_COLOR:
return D2D1_BLEND_MODE_COLOR;
case CompositionOp::OP_LUMINOSITY:
return D2D1_BLEND_MODE_LUMINOSITY;
default:
return D2D1_BLEND_MODE_MULTIPLY;
}
}
#endif
static inline bool IsPatternSupportedByD2D(const Pattern &aPattern)

Просмотреть файл

@ -147,14 +147,18 @@ RadialGradientEffectD2D1::PrepareForRender(D2D1_CHANGE_TYPE changeType)
float A;
float radius1;
float sq_radius1;
float padding2[3];
float repeat_correct;
float allow_odd;
float padding2[1];
float transform[8];
};
PSConstantBuffer buffer = { { dc.x, dc.y, dr }, 0,
{ mCenter1.x, mCenter1.y },
A, mRadius1, mRadius1 * mRadius1,
{ 0, 0, 0 }, { mat._11, mat._21, mat._31, 0,
mStopCollection->GetExtendMode() != D2D1_EXTEND_MODE_CLAMP ? 1 : 0,
mStopCollection->GetExtendMode() == D2D1_EXTEND_MODE_MIRROR ? 1 : 0,
{ 0 }, { mat._11, mat._21, mat._31, 0,
mat._12, mat._22, mat._32, 0 } };
hr = mDrawInfo->SetPixelShaderConstantBuffer((BYTE*)&buffer, sizeof(buffer));
@ -365,13 +369,15 @@ RadialGradientEffectD2D1::CreateGradientTexture()
UINT32 width = 4096;
UINT32 stride = 4096 * 4;
D2D1_RESOURCE_TEXTURE_PROPERTIES props;
props.dimensions = 1;
props.extents = &width;
// Older shader models do not support 1D textures. So just use a width x 1 texture.
props.dimensions = 2;
UINT32 dims[] = { width, 1 };
props.extents = dims;
props.channelDepth = D2D1_CHANNEL_DEPTH_4;
props.bufferPrecision = D2D1_BUFFER_PRECISION_8BPC_UNORM;
props.filter = D2D1_FILTER_MIN_MAG_MIP_LINEAR;
D2D1_EXTEND_MODE extendMode = mStopCollection->GetExtendMode();
props.extendModes = &extendMode;
D2D1_EXTEND_MODE extendMode[] = { mStopCollection->GetExtendMode(), mStopCollection->GetExtendMode() };
props.extendModes = extendMode;
HRESULT hr = mEffectContext->CreateResourceTexture(nullptr, &props, &textureData.front(), &stride, 4096 * 4, byRef(tex));

Просмотреть файл

@ -309,7 +309,7 @@ ScaledFontDWrite::ScaledFontDWrite(uint8_t *aData, uint32_t aSize,
TemporaryRef<Path>
ScaledFontDWrite::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
{
if (aTarget->GetBackendType() != BackendType::DIRECT2D) {
if (aTarget->GetBackendType() != BackendType::DIRECT2D && aTarget->GetBackendType() != BackendType::DIRECT2D1_1) {
return ScaledFontBase::GetPathForGlyphs(aBuffer, aTarget);
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -16,6 +16,13 @@ cbuffer constants : register(b0)
float A : packoffset(c1.z);
float radius1 : packoffset(c1.w);
float sq_radius1 : packoffset(c2.x);
// The next two values are used for a hack to compensate for an apparent
// bug in D2D where the GradientSampler SamplerState doesn't get the
// correct addressing modes.
float repeat_correct : packoffset(c2.y);
float allow_odd : packoffset(c2.z);
float3x2 transform : packoffset(c3.x);
}
@ -52,7 +59,13 @@ float4 SampleRadialGradientPS(
float upper_t = lerp(t.y, t.x, isValid.x);
float4 output = GradientTexture.Sample(GradientSampler, float2(upper_t, 0.5));
// Addressing mode bug work-around.. first let's see if we should consider odd repetitions separately.
float oddeven = abs(fmod(floor(upper_t), 2)) * allow_odd;
// Now let's calculate even or odd addressing in a branchless manner.
float upper_t_repeated = ((upper_t - floor(upper_t)) * (1.0f - oddeven)) + ((ceil(upper_t) - upper_t) * oddeven);
float4 output = GradientTexture.Sample(GradientSampler, float2(upper_t * (1.0f - repeat_correct) + upper_t_repeated * repeat_correct, 0.5));
// Premultiply
output.rgb *= output.a;
// Multiply the output color by the input mask for the operation.
@ -84,7 +97,13 @@ float4 SampleRadialGradientA0PS(
float t = 0.5 * C / B;
float4 output = GradientTexture.Sample(GradientSampler, float2(t, 0.5));
// Addressing mode bug work-around.. first let's see if we should consider odd repetitions separately.
float oddeven = abs(fmod(floor(t), 2)) * allow_odd;
// Now let's calculate even or odd addressing in a branchless manner.
float t_repeated = ((t - floor(t)) * (1.0f - oddeven)) + ((ceil(t) - t) * oddeven);
float4 output = GradientTexture.Sample(GradientSampler, float2(t * (1.0f - repeat_correct) + t_repeated * repeat_correct, 0.5));
// Premultiply
output.rgb *= output.a;
// Multiply the output color by the input mask for the operation.
@ -95,3 +114,4 @@ float4 SampleRadialGradientA0PS(
// -radius1 >= t * diff.z
return output * abs(step(t * diff.z, -radius1) - 1.0f);
};

Просмотреть файл

@ -95,7 +95,6 @@ SourceSurfaceD2D1::DrawTargetWillChange()
mImage = mRealizedBitmap;
DrawTargetD2D1::mVRAMUsageSS += mSize.width * mSize.height * BytesPerPixel(mFormat);
mDrawTarget = nullptr;
// We now no longer depend on the source surface content remaining the same.
MarkIndependent();

Просмотреть файл

@ -57,7 +57,7 @@ private:
SurfaceFormat mFormat;
IntSize mSize;
RefPtr<DrawTargetD2D1> mDrawTarget;
DrawTargetD2D1* mDrawTarget;
};
class DataSourceSurfaceD2D1 : public DataSourceSurface

Просмотреть файл

@ -103,7 +103,9 @@ RotatedBuffer::DrawBufferQuadrant(gfx::DrawTarget* aTarget,
// (to avoid flickering) but direct2d is ok since it defers rendering.
// We should try abstract this logic in a helper when we have other use
// cases.
if (aTarget->GetBackendType() == BackendType::DIRECT2D && aOperator == CompositionOp::OP_SOURCE) {
if ((aTarget->GetBackendType() == BackendType::DIRECT2D ||
aTarget->GetBackendType() == BackendType::DIRECT2D1_1) &&
aOperator == CompositionOp::OP_SOURCE) {
aOperator = CompositionOp::OP_OVER;
if (snapshot->GetFormat() == SurfaceFormat::B8G8R8A8) {
aTarget->ClearRect(ToRect(fillRect));

Просмотреть файл

@ -11,6 +11,7 @@
#include "gfxWindowsPlatform.h"
#include "gfxD2DSurface.h"
#include "gfx2DGlue.h"
#include "gfxPrefs.h"
#include "ReadbackManagerD3D11.h"
namespace mozilla {
@ -172,8 +173,12 @@ TextureClientD3D11::TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags
TextureClientD3D11::~TextureClientD3D11()
{
if (mTexture && mActor) {
KeepUntilFullDeallocation(new TKeepAlive<ID3D10Texture2D>(mTexture));
if (mActor) {
if (mTexture) {
KeepUntilFullDeallocation(new TKeepAlive<ID3D10Texture2D>(mTexture10));
} else if (mTexture10) {
KeepUntilFullDeallocation(new TKeepAlive<ID3D11Texture2D>(mTexture));
}
}
#ifdef DEBUG
// An Azure DrawTarget needs to be locked when it gets nullptr'ed as this is
@ -181,11 +186,19 @@ TextureClientD3D11::~TextureClientD3D11()
// shouldn't -really- need the lock but the debug layer chokes on this.
if (mDrawTarget) {
MOZ_ASSERT(!mIsLocked);
MOZ_ASSERT(mTexture);
MOZ_ASSERT(mTexture || mTexture10);
MOZ_ASSERT(mDrawTarget->refCount() == 1);
LockD3DTexture(mTexture.get());
if (mTexture) {
LockD3DTexture(mTexture.get());
} else {
LockD3DTexture(mTexture10.get());
}
mDrawTarget = nullptr;
UnlockD3DTexture(mTexture.get());
if (mTexture) {
UnlockD3DTexture(mTexture.get());
} else {
UnlockD3DTexture(mTexture10.get());
}
}
#endif
}
@ -206,12 +219,18 @@ TextureClientD3D11::CreateSimilar(TextureFlags aFlags,
bool
TextureClientD3D11::Lock(OpenMode aMode)
{
if (!mTexture) {
if (!IsAllocated()) {
return false;
}
MOZ_ASSERT(!mIsLocked, "The Texture is already locked!");
mIsLocked = LockD3DTexture(mTexture.get());
if (mTexture) {
MOZ_ASSERT(!mTexture10);
mIsLocked = LockD3DTexture(mTexture.get());
} else {
MOZ_ASSERT(!mTexture);
mIsLocked = LockD3DTexture(mTexture10.get());
}
if (!mIsLocked) {
return false;
}
@ -254,11 +273,11 @@ TextureClientD3D11::Unlock()
mDrawTarget->Flush();
}
if (mReadbackSink) {
if (mReadbackSink && mTexture10) {
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
D3D10_TEXTURE2D_DESC desc;
mTexture->GetDesc(&desc);
mTexture10->GetDesc(&desc);
desc.BindFlags = 0;
desc.Usage = D3D10_USAGE_STAGING;
desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
@ -268,7 +287,7 @@ TextureClientD3D11::Unlock()
HRESULT hr = device->CreateTexture2D(&desc, nullptr, byRef(tex));
if (SUCCEEDED(hr)) {
device->CopyResource(tex, mTexture);
device->CopyResource(tex, mTexture10);
gfxWindowsPlatform::GetPlatform()->GetReadbackManager()->PostTask(tex, mReadbackSink);
} else {
@ -278,7 +297,11 @@ TextureClientD3D11::Unlock()
// The DrawTarget is created only once, and is only usable between calls
// to Lock and Unlock.
UnlockD3DTexture(mTexture.get());
if (mTexture) {
UnlockD3DTexture(mTexture.get());
} else {
UnlockD3DTexture(mTexture10.get());
}
mIsLocked = false;
}
@ -287,7 +310,7 @@ TextureClientD3D11::BorrowDrawTarget()
{
MOZ_ASSERT(mIsLocked, "Calling TextureClient::BorrowDrawTarget without locking :(");
if (!mTexture) {
if (!mTexture && !mTexture10) {
return nullptr;
}
@ -296,7 +319,15 @@ TextureClientD3D11::BorrowDrawTarget()
}
// This may return a null DrawTarget
mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, mFormat);
#if USE_D2D1_1
if (mTexture) {
mDrawTarget = Factory::CreateDrawTargetForD3D11Texture(mTexture, mFormat);
} else
#endif
{
MOZ_ASSERT(mTexture10);
mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture10, mFormat);
}
return mDrawTarget;
}
@ -304,15 +335,38 @@ bool
TextureClientD3D11::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags)
{
mSize = aSize;
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
HRESULT hr;
CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM,
aSize.width, aSize.height, 1, 1,
D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE);
if (mFormat == SurfaceFormat::A8) {
// Currently TextureClientD3D11 does not support A8 surfaces. Fallback.
return false;
}
newDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX;
#ifdef USE_D2D1_1
ID3D11Device* d3d11device = gfxWindowsPlatform::GetPlatform()->GetD3D11ContentDevice();
HRESULT hr = device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture));
if (gfxPrefs::Direct2DUse1_1() && d3d11device) {
CD3D11_TEXTURE2D_DESC newDesc(mFormat == SurfaceFormat::A8 ? DXGI_FORMAT_A8_UNORM : DXGI_FORMAT_B8G8R8A8_UNORM,
aSize.width, aSize.height, 1, 1,
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
hr = d3d11device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture));
} else
#endif
{
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM,
aSize.width, aSize.height, 1, 1,
D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE);
newDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX;
hr = device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture10));
}
if (FAILED(hr)) {
LOGD3D11("Error creating texture for client!");
@ -332,9 +386,13 @@ TextureClientD3D11::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
if (!IsAllocated()) {
return false;
}
RefPtr<IDXGIResource> resource;
mTexture->QueryInterface((IDXGIResource**)byRef(resource));
if (mTexture) {
mTexture->QueryInterface((IDXGIResource**)byRef(resource));
} else {
mTexture10->QueryInterface((IDXGIResource**)byRef(resource));
}
HANDLE sharedHandle;
HRESULT hr = resource->GetSharedHandle(&sharedHandle);

Просмотреть файл

@ -34,7 +34,7 @@ public:
// TextureClient
virtual bool IsAllocated() const MOZ_OVERRIDE { return !!mTexture; }
virtual bool IsAllocated() const MOZ_OVERRIDE { return mTexture || mTexture10; }
virtual bool Lock(OpenMode aOpenMode) MOZ_OVERRIDE;
@ -65,7 +65,8 @@ public:
protected:
gfx::IntSize mSize;
RefPtr<ID3D10Texture2D> mTexture;
RefPtr<ID3D10Texture2D> mTexture10;
RefPtr<ID3D11Texture2D> mTexture;
RefPtr<gfx::DrawTarget> mDrawTarget;
gfx::SurfaceFormat mFormat;
bool mIsLocked;

Просмотреть файл

@ -98,7 +98,9 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
SOURCES += [
'd3d11/CompositorD3D11.cpp',
'd3d11/ReadbackManagerD3D11.cpp',
]
]
if CONFIG['MOZ_ENABLE_DIRECT2D1_1']:
DEFINES['USE_D2D1_1'] = True
EXPORTS.gfxipc += [
'ipc/ShadowLayerUtils.h',

Просмотреть файл

@ -673,13 +673,24 @@ FilterNodeFromPrimitiveDescription(const FilterPrimitiveDescription& aDescriptio
filter->SetInput(IN_COMPOSITE_IN_START + 1, aSources[0]);
} else {
filter = aDT->CreateFilter(FilterType::BLEND);
static const uint8_t blendModes[SVG_FEBLEND_MODE_LIGHTEN + 1] = {
static const uint8_t blendModes[SVG_FEBLEND_MODE_LUMINOSITY + 1] = {
0,
0,
BLEND_MODE_MULTIPLY,
BLEND_MODE_SCREEN,
BLEND_MODE_DARKEN,
BLEND_MODE_LIGHTEN
BLEND_MODE_LIGHTEN,
BLEND_MODE_OVERLAY,
BLEND_MODE_COLOR_DODGE,
BLEND_MODE_COLOR_BURN,
BLEND_MODE_HARD_LIGHT,
BLEND_MODE_SOFT_LIGHT,
BLEND_MODE_DIFFERENCE,
BLEND_MODE_EXCLUSION,
BLEND_MODE_HUE,
BLEND_MODE_SATURATION,
BLEND_MODE_COLOR,
BLEND_MODE_LUMINOSITY
};
filter->SetAttribute(ATT_BLEND_BLENDMODE, (uint32_t)blendModes[mode]);
filter->SetInput(IN_BLEND_IN, aSources[0]);

Просмотреть файл

@ -47,6 +47,17 @@ const unsigned short SVG_FEBLEND_MODE_MULTIPLY = 2;
const unsigned short SVG_FEBLEND_MODE_SCREEN = 3;
const unsigned short SVG_FEBLEND_MODE_DARKEN = 4;
const unsigned short SVG_FEBLEND_MODE_LIGHTEN = 5;
const unsigned short SVG_FEBLEND_MODE_OVERLAY = 6;
const unsigned short SVG_FEBLEND_MODE_COLOR_DODGE = 7;
const unsigned short SVG_FEBLEND_MODE_COLOR_BURN = 8;
const unsigned short SVG_FEBLEND_MODE_HARD_LIGHT = 9;
const unsigned short SVG_FEBLEND_MODE_SOFT_LIGHT = 10;
const unsigned short SVG_FEBLEND_MODE_DIFFERENCE = 11;
const unsigned short SVG_FEBLEND_MODE_EXCLUSION = 12;
const unsigned short SVG_FEBLEND_MODE_HUE = 13;
const unsigned short SVG_FEBLEND_MODE_SATURATION = 14;
const unsigned short SVG_FEBLEND_MODE_COLOR = 15;
const unsigned short SVG_FEBLEND_MODE_LUMINOSITY = 16;
// Edge Mode Values
const unsigned short SVG_EDGEMODE_UNKNOWN = 0;

Просмотреть файл

@ -83,6 +83,10 @@ public:
virtual int GetScreenDepth() const;
virtual bool CanRenderContentToDataSurface() const MOZ_OVERRIDE {
return true;
}
virtual bool UseAcceleratedSkiaCanvas() MOZ_OVERRIDE;
#ifdef MOZ_WIDGET_GONK

Просмотреть файл

@ -244,7 +244,8 @@ TemporaryRef<Path> gfxContext::GetPath()
void gfxContext::SetPath(Path* path)
{
MOZ_ASSERT(path->GetBackendType() == mDT->GetBackendType());
MOZ_ASSERT(path->GetBackendType() == mDT->GetBackendType() ||
(mDT->GetBackendType() == BackendType::DIRECT2D1_1 && path->GetBackendType() == BackendType::DIRECT2D));
mPath = path;
mPathBuilder = nullptr;
mPathIsRect = false;

Просмотреть файл

@ -993,6 +993,8 @@ gfxPlatform::BackendTypeForName(const nsCString& aName)
return BackendType::SKIA;
if (aName.EqualsLiteral("direct2d"))
return BackendType::DIRECT2D;
if (aName.EqualsLiteral("direct2d1.1"))
return BackendType::DIRECT2D1_1;
if (aName.EqualsLiteral("cg"))
return BackendType::COREGRAPHICS;
return BackendType::NONE;
@ -1463,8 +1465,18 @@ gfxPlatform::InitBackendPrefs(uint32_t aCanvasBitmask, BackendType aCanvasDefaul
if (mPreferredCanvasBackend == BackendType::NONE) {
mPreferredCanvasBackend = aCanvasDefault;
}
mFallbackCanvasBackend =
GetCanvasBackendPref(aCanvasBitmask & ~BackendTypeBit(mPreferredCanvasBackend));
if (mPreferredCanvasBackend == BackendType::DIRECT2D1_1) {
// Falling back to D2D 1.0 won't help us here. When D2D 1.1 DT creation
// fails it means the surface was too big or there's something wrong with
// the device. D2D 1.0 will encounter a similar situation.
mFallbackCanvasBackend =
GetCanvasBackendPref(aCanvasBitmask &
~(BackendTypeBit(mPreferredCanvasBackend) | BackendTypeBit(BackendType::DIRECT2D)));
} else {
mFallbackCanvasBackend =
GetCanvasBackendPref(aCanvasBitmask & ~BackendTypeBit(mPreferredCanvasBackend));
}
mContentBackendBitmask = aContentBitmask;
mContentBackend = GetContentBackendPref(mContentBackendBitmask);

Просмотреть файл

@ -235,6 +235,16 @@ public:
CreateDrawTargetForData(unsigned char* aData, const mozilla::gfx::IntSize& aSize,
int32_t aStride, mozilla::gfx::SurfaceFormat aFormat);
/**
* Returns true if rendering to data surfaces produces the same results as
* rendering to offscreen surfaces on this platform, making it safe to
* render content to data surfaces. This is generally false on platforms
* which use different backends for each type of DrawTarget.
*/
virtual bool CanRenderContentToDataSurface() const {
return false;
}
/**
* Returns true if we should use Azure to render content with aTarget. For
* example, it is possible that we are using Direct2D for rendering and thus

Просмотреть файл

@ -64,6 +64,10 @@ public:
int32_t aRunScript,
nsTArray<const char*>& aFontList);
virtual bool CanRenderContentToDataSurface() const MOZ_OVERRIDE {
return true;
}
bool UseAcceleratedCanvas();
virtual bool UseTiling() MOZ_OVERRIDE;

Просмотреть файл

@ -192,6 +192,7 @@ private:
DECL_GFX_PREF(Once, "gfx.direct2d.disabled", Direct2DDisabled, bool, false);
DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled", Direct2DForceEnabled, bool, false);
DECL_GFX_PREF(Live, "gfx.direct2d.use1_1", Direct2DUse1_1, bool, false);
DECL_GFX_PREF(Live, "gfx.gralloc.fence-with-readpixels", GrallocFenceWithReadPixels, bool, false);
DECL_GFX_PREF(Live, "gfx.layerscope.enabled", LayerScopeEnabled, bool, false);
DECL_GFX_PREF(Live, "gfx.layerscope.port", LayerScopePort, int32_t, 23456);

Просмотреть файл

@ -709,6 +709,12 @@ static void
ClipToRegionInternal(DrawTarget* aTarget, const nsIntRegion& aRegion,
bool aSnap)
{
if (!aRegion.IsComplex()) {
nsIntRect rect = aRegion.GetBounds();
aTarget->PushClipRect(Rect(rect.x, rect.y, rect.width, rect.height));
return;
}
RefPtr<Path> path = PathFromRegionInternal(aTarget, aRegion, aSnap);
aTarget->PushClip(path);
}

Просмотреть файл

@ -312,6 +312,10 @@ gfxWindowsPlatform::gfxWindowsPlatform()
UpdateRenderMode();
if (gfxPrefs::Direct2DUse1_1()) {
InitD3D11Devices();
}
RegisterStrongMemoryReporter(new GPUAdapterReporter());
}
@ -438,7 +442,12 @@ gfxWindowsPlatform::UpdateRenderMode()
if (mRenderMode == RENDER_DIRECT2D) {
canvasMask |= BackendTypeBit(BackendType::DIRECT2D);
contentMask |= BackendTypeBit(BackendType::DIRECT2D);
defaultBackend = BackendType::DIRECT2D;
if (gfxPrefs::Direct2DUse1_1() && Factory::SupportsD2D1()) {
contentMask |= BackendTypeBit(BackendType::DIRECT2D1_1);
defaultBackend = BackendType::DIRECT2D1_1;
} else {
defaultBackend = BackendType::DIRECT2D;
}
} else {
canvasMask |= BackendTypeBit(BackendType::SKIA);
}
@ -1366,43 +1375,23 @@ gfxWindowsPlatform::GetD3D11Device()
return mD3D11Device;
}
mD3D11DeviceInitialized = true;
nsModuleHandle d3d11Module(LoadLibrarySystem32(L"d3d11.dll"));
decltype(D3D11CreateDevice)* d3d11CreateDevice = (decltype(D3D11CreateDevice)*)
GetProcAddress(d3d11Module, "D3D11CreateDevice");
if (!d3d11CreateDevice) {
return nullptr;
}
nsTArray<D3D_FEATURE_LEVEL> featureLevels;
if (IsWin8OrLater()) {
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1);
}
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
if (!adapter) {
return nullptr;
}
HRESULT hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
featureLevels.Elements(), featureLevels.Length(),
D3D11_SDK_VERSION, byRef(mD3D11Device), nullptr, nullptr);
// We leak these everywhere and we need them our entire runtime anyway, let's
// leak it here as well.
d3d11Module.disown();
InitD3D11Devices();
return mD3D11Device;
}
ID3D11Device*
gfxWindowsPlatform::GetD3D11ContentDevice()
{
if (mD3D11DeviceInitialized) {
return mD3D11ContentDevice;
}
InitD3D11Devices();
return mD3D11ContentDevice;
}
ReadbackManagerD3D11*
gfxWindowsPlatform::GetReadbackManager()
{
@ -1487,3 +1476,63 @@ gfxWindowsPlatform::GetDXGIAdapter()
return mAdapter;
}
void
gfxWindowsPlatform::InitD3D11Devices()
{
mD3D11DeviceInitialized = true;
nsModuleHandle d3d11Module(LoadLibrarySystem32(L"d3d11.dll"));
decltype(D3D11CreateDevice)* d3d11CreateDevice = (decltype(D3D11CreateDevice)*)
GetProcAddress(d3d11Module, "D3D11CreateDevice");
if (!d3d11CreateDevice) {
return;
}
nsTArray<D3D_FEATURE_LEVEL> featureLevels;
if (IsWin8OrLater()) {
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1);
}
featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0);
featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
if (!adapter) {
return;
}
HRESULT hr;
hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
featureLevels.Elements(), featureLevels.Length(),
D3D11_SDK_VERSION, byRef(mD3D11Device), nullptr, nullptr);
if (FAILED(hr)) {
return;
}
#ifdef USE_D2D1_1
if (Factory::SupportsD2D1()) {
hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
featureLevels.Elements(), featureLevels.Length(),
D3D11_SDK_VERSION, byRef(mD3D11ContentDevice), nullptr, nullptr);
if (FAILED(hr)) {
mD3D11Device = nullptr;
return;
}
Factory::SetDirect3D11Device(mD3D11ContentDevice);
}
#endif
// We leak these everywhere and we need them our entire runtime anyway, let's
// leak it here as well.
d3d11Module.disown();
}

Просмотреть файл

@ -261,6 +261,7 @@ public:
ID3D10Device1 *GetD3D10Device() { return mD2DDevice ? cairo_d2d_device_get_device(mD2DDevice) : nullptr; }
#endif
ID3D11Device *GetD3D11Device();
ID3D11Device *GetD3D11ContentDevice();
mozilla::layers::ReadbackManagerD3D11* GetReadbackManager();
@ -274,6 +275,7 @@ protected:
private:
void Init();
void InitD3D11Devices();
IDXGIAdapter1 *GetDXGIAdapter();
bool mUseDirectWrite;
@ -291,6 +293,7 @@ private:
mozilla::RefPtr<IDXGIAdapter1> mAdapter;
nsRefPtr<mozilla::layers::DeviceManagerD3D9> mDeviceManager;
mozilla::RefPtr<ID3D11Device> mD3D11Device;
mozilla::RefPtr<ID3D11Device> mD3D11ContentDevice;
bool mD3D11DeviceInitialized;
mozilla::RefPtr<mozilla::layers::ReadbackManagerD3D11> mD3D11ReadbackManager;

Просмотреть файл

@ -184,6 +184,8 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
'gfxDWriteFontList.cpp',
'gfxDWriteFonts.cpp',
]
if CONFIG['MOZ_ENABLE_DIRECT2D1_1']:
DEFINES['USE_D2D1_1'] = True
# Are we targeting x86 or x64? If so, build gfxAlphaRecoverySSE2.cpp.
if CONFIG['INTEL_ARCHITECTURE']:

Просмотреть файл

@ -11,6 +11,9 @@
#include "pixman.h"
namespace mozilla {
using namespace gfx;
namespace image {
FrameBlender::FrameBlender(FrameSequence* aSequenceToUse /* = nullptr */)
@ -258,8 +261,8 @@ FrameBlender::DoBlend(nsIntRect* aDirtyRect,
// Create the Compositing Frame
if (!mAnim->compositingFrame) {
mAnim->compositingFrame.SetFrame(new imgFrame());
nsresult rv = mAnim->compositingFrame->Init(0, 0, mSize.width, mSize.height,
gfx::SurfaceFormat::B8G8R8A8);
nsresult rv =
mAnim->compositingFrame->InitForDecoder(mSize, SurfaceFormat::B8G8R8A8);
if (NS_FAILED(rv)) {
mAnim->compositingFrame.SetFrame(nullptr);
return false;
@ -388,8 +391,9 @@ FrameBlender::DoBlend(nsIntRect* aDirtyRect,
// overwrite.
if (!mAnim->compositingPrevFrame) {
mAnim->compositingPrevFrame.SetFrame(new imgFrame());
nsresult rv = mAnim->compositingPrevFrame->Init(0, 0, mSize.width, mSize.height,
gfx::SurfaceFormat::B8G8R8A8);
nsresult rv =
mAnim->compositingPrevFrame->InitForDecoder(mSize,
SurfaceFormat::B8G8R8A8);
if (NS_FAILED(rv)) {
mAnim->compositingPrevFrame.SetFrame(nullptr);
return false;

Просмотреть файл

@ -223,8 +223,7 @@ public:
// that's what the scaler outputs.
nsRefPtr<imgFrame> tentativeDstFrame = new imgFrame();
nsresult rv =
tentativeDstFrame->Init(0, 0, dstSize.width, dstSize.height,
SurfaceFormat::B8G8R8A8);
tentativeDstFrame->InitForDecoder(dstSize, SurfaceFormat::B8G8R8A8);
if (NS_FAILED(rv)) {
return false;
}
@ -648,60 +647,68 @@ RasterImage::GetType()
}
already_AddRefed<imgFrame>
RasterImage::GetImgFrameNoDecode(uint32_t framenum)
RasterImage::GetFrameNoDecode(uint32_t aFrameNum)
{
if (!mAnim) {
NS_ASSERTION(framenum == 0, "Don't ask for a frame > 0 if we're not animated!");
NS_ASSERTION(aFrameNum == 0, "Don't ask for a frame > 0 if we're not animated!");
return mFrameBlender.GetFrame(0);
}
return mFrameBlender.GetFrame(framenum);
return mFrameBlender.GetFrame(aFrameNum);
}
already_AddRefed<imgFrame>
RasterImage::GetImgFrame(uint32_t framenum)
DrawableFrameRef
RasterImage::GetFrame(uint32_t aFrameNum)
{
nsresult rv = WantDecodedFrames();
CONTAINER_ENSURE_TRUE(NS_SUCCEEDED(rv), nullptr);
return GetImgFrameNoDecode(framenum);
}
already_AddRefed<imgFrame>
RasterImage::GetDrawableImgFrame(uint32_t framenum)
{
nsRefPtr<imgFrame> frame;
if (mMultipart && framenum == GetCurrentImgFrameIndex()) {
if (mMultipart &&
aFrameNum == GetCurrentFrameIndex() &&
mMultipartDecodedFrame) {
// In the multipart case we prefer to use mMultipartDecodedFrame, which is
// the most recent one we completely decoded, rather than display the real
// current frame and risk severe tearing.
frame = mMultipartDecodedFrame;
return mMultipartDecodedFrame->DrawableRef();
}
// Try our best to start decoding if it's necessary.
nsresult rv = WantDecodedFrames();
CONTAINER_ENSURE_TRUE(NS_SUCCEEDED(rv), DrawableFrameRef());
nsRefPtr<imgFrame> frame = GetFrameNoDecode(aFrameNum);
if (!frame) {
frame = GetImgFrame(framenum);
return DrawableFrameRef();
}
DrawableFrameRef ref = frame->DrawableRef();
if (!ref) {
// The OS threw this frame away. We need to discard and redecode.
MOZ_ASSERT(!mAnim, "Animated frames should be locked");
ForceDiscard();
WantDecodedFrames();
return DrawableFrameRef();
}
// We will return a paletted frame if it's not marked as compositing failed
// so we can catch crashes for reasons we haven't investigated.
if (frame && frame->GetCompositingFailed())
return nullptr;
if (ref->GetCompositingFailed()) {
return DrawableFrameRef();
}
return frame.forget();
return ref;
}
uint32_t
RasterImage::GetCurrentImgFrameIndex() const
RasterImage::GetCurrentFrameIndex() const
{
if (mAnim)
if (mAnim) {
return mAnim->GetCurrentAnimationFrameIndex();
}
return 0;
}
already_AddRefed<imgFrame>
RasterImage::GetCurrentImgFrame()
uint32_t
RasterImage::GetRequestedFrameIndex(uint32_t aWhichFrame) const
{
return GetImgFrame(GetCurrentImgFrameIndex());
return aWhichFrame == FRAME_FIRST ? 0 : GetCurrentFrameIndex();
}
//******************************************************************************
@ -718,9 +725,8 @@ RasterImage::FrameIsOpaque(uint32_t aWhichFrame)
return false;
// See if we can get an image frame.
nsRefPtr<imgFrame> frame = aWhichFrame == FRAME_FIRST
? GetImgFrameNoDecode(0)
: GetImgFrameNoDecode(GetCurrentImgFrameIndex());
nsRefPtr<imgFrame> frame =
GetFrameNoDecode(GetRequestedFrameIndex(aWhichFrame));
// If we don't get a frame, the safe answer is "not opaque".
if (!frame)
@ -743,9 +749,8 @@ RasterImage::FrameRect(uint32_t aWhichFrame)
}
// Get the requested frame.
nsRefPtr<imgFrame> frame = aWhichFrame == FRAME_FIRST
? GetImgFrameNoDecode(0)
: GetImgFrameNoDecode(GetCurrentImgFrameIndex());
nsRefPtr<imgFrame> frame =
GetFrameNoDecode(GetRequestedFrameIndex(aWhichFrame));
// If we have the frame, use that rectangle.
if (frame) {
@ -760,12 +765,6 @@ RasterImage::FrameRect(uint32_t aWhichFrame)
return nsIntRect();
}
uint32_t
RasterImage::GetCurrentFrameIndex()
{
return GetCurrentImgFrameIndex();
}
uint32_t
RasterImage::GetNumFrames() const
{
@ -842,10 +841,13 @@ RasterImage::CopyFrame(uint32_t aWhichFrame,
// Get the frame. If it's not there, it's probably the caller's fault for
// not waiting for the data to be loaded from the network or not passing
// FLAG_SYNC_DECODE
uint32_t frameIndex = (aWhichFrame == FRAME_FIRST) ?
0 : GetCurrentImgFrameIndex();
nsRefPtr<imgFrame> frame = GetDrawableImgFrame(frameIndex);
if (!frame) {
DrawableFrameRef frameRef = GetFrame(GetRequestedFrameIndex(aWhichFrame));
if (!frameRef) {
// The OS threw this frame away.
if (aFlags & FLAG_SYNC_DECODE) {
ForceDiscard();
return CopyFrame(aWhichFrame, aFlags);
}
return nullptr;
}
@ -872,16 +874,16 @@ RasterImage::CopyFrame(uint32_t aWhichFrame,
mapping.mStride,
SurfaceFormat::B8G8R8A8);
nsIntRect intframerect = frame->GetRect();
Rect rect(intframerect.x, intframerect.y,
intframerect.width, intframerect.height);
if (frame->IsSinglePixel()) {
target->FillRect(rect, ColorPattern(frame->SinglePixelColor()),
nsIntRect intFrameRect = frameRef->GetRect();
Rect rect(intFrameRect.x, intFrameRect.y,
intFrameRect.width, intFrameRect.height);
if (frameRef->IsSinglePixel()) {
target->FillRect(rect, ColorPattern(frameRef->SinglePixelColor()),
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
} else {
RefPtr<SourceSurface> srcsurf = frame->GetSurface();
Rect srcrect(0, 0, intframerect.width, intframerect.height);
target->DrawSurface(srcsurf, srcrect, rect);
RefPtr<SourceSurface> srcSurf = frameRef->GetSurface();
Rect srcRect(0, 0, intFrameRect.width, intFrameRect.height);
target->DrawSurface(srcSurf, srcRect, rect);
}
target->Flush();
@ -921,46 +923,34 @@ RasterImage::GetFrame(uint32_t aWhichFrame,
// Get the frame. If it's not there, it's probably the caller's fault for
// not waiting for the data to be loaded from the network or not passing
// FLAG_SYNC_DECODE
uint32_t frameIndex = (aWhichFrame == FRAME_FIRST) ?
0 : GetCurrentImgFrameIndex();
nsRefPtr<imgFrame> frame = GetDrawableImgFrame(frameIndex);
if (!frame) {
return nullptr;
}
RefPtr<SourceSurface> framesurf;
// If this frame covers the entire image, we can just reuse its existing
// surface.
nsIntRect framerect = frame->GetRect();
if (framerect.x == 0 && framerect.y == 0 &&
framerect.width == mSize.width &&
framerect.height == mSize.height) {
framesurf = frame->GetSurface();
if (!framesurf && !frame->IsSinglePixel()) {
// No reason to be optimized away here - the OS threw out the data
if (!(aFlags & FLAG_SYNC_DECODE))
return nullptr;
// Unconditionally call ForceDiscard() here because GetSurface can only
// return null when we can forcibly discard and redecode. There are two
// other cases where GetSurface() can return null - when it is a single
// pixel image, which we check before getting here, or when this is an
// indexed image, in which case we shouldn't be in this function at all.
// The only remaining possibility is that SetDiscardable() was called on
// this imgFrame, which implies the image can be redecoded.
DrawableFrameRef frameRef = GetFrame(GetRequestedFrameIndex(aWhichFrame));
if (!frameRef) {
// The OS threw this frame away. We'll request a redecode.
if (aFlags & FLAG_SYNC_DECODE) {
ForceDiscard();
return GetFrame(aWhichFrame, aFlags);
}
return nullptr;
}
// The image doesn't have a surface because it's been optimized away. Create
// one.
if (!framesurf) {
framesurf = CopyFrame(aWhichFrame, aFlags);
// If this frame covers the entire image, we can just reuse its existing
// surface.
RefPtr<SourceSurface> frameSurf;
nsIntRect frameRect = frameRef->GetRect();
if (frameRect.x == 0 && frameRect.y == 0 &&
frameRect.width == mSize.width &&
frameRect.height == mSize.height) {
frameSurf = frameRef->GetSurface();
}
return framesurf;
// The image doesn't have a usable surface because it's been optimized away or
// because it's a partial update frame from an animation. Create one.
if (!frameSurf) {
frameSurf = CopyFrame(aWhichFrame, aFlags);
}
return frameSurf;
}
already_AddRefed<layers::Image>
@ -1183,7 +1173,8 @@ RasterImage::InternalAddFrame(uint32_t framenum,
nsRefPtr<imgFrame> frame(new imgFrame());
nsresult rv = frame->Init(aX, aY, aWidth, aHeight, aFormat, aPaletteDepth);
nsIntRect frameRect(aX, aY, aWidth, aHeight);
nsresult rv = frame->InitForDecoder(frameRect, aFormat, aPaletteDepth);
if (!(mSize.width > 0 && mSize.height > 0))
NS_WARNING("Shouldn't call InternalAddFrame with zero size");
if (!NS_SUCCEEDED(rv))
@ -1367,7 +1358,8 @@ RasterImage::EnsureFrame(uint32_t aFrameNum, int32_t aX, int32_t aY,
mFrameBlender.RemoveFrame(aFrameNum);
nsRefPtr<imgFrame> newFrame(new imgFrame());
nsresult rv = newFrame->Init(aX, aY, aWidth, aHeight, aFormat, aPaletteDepth);
nsIntRect frameRect(aX, aY, aWidth, aHeight);
nsresult rv = newFrame->InitForDecoder(frameRect, aFormat, aPaletteDepth);
NS_ENSURE_SUCCESS(rv, rv);
return InternalAddFrameHelper(aFrameNum, newFrame, imageData, imageLength,
paletteData, paletteLength, aRetFrame);
@ -1490,9 +1482,10 @@ RasterImage::StartAnimation()
EnsureAnimExists();
nsRefPtr<imgFrame> currentFrame = GetCurrentImgFrame();
nsRefPtr<imgFrame> currentFrame = GetFrameNoDecode(GetCurrentFrameIndex());
// A timeout of -1 means we should display this frame forever.
if (currentFrame && mFrameBlender.GetTimeoutForFrame(GetCurrentImgFrameIndex()) < 0) {
if (currentFrame &&
mFrameBlender.GetTimeoutForFrame(GetCurrentFrameIndex()) < 0) {
mAnimationFinished = true;
return NS_ERROR_ABORT;
}
@ -2636,67 +2629,56 @@ RasterImage::RequestScale(imgFrame* aFrame, nsIntSize aSize)
}
}
bool
RasterImage::DrawWithPreDownscaleIfNeeded(imgFrame *aFrame,
void
RasterImage::DrawWithPreDownscaleIfNeeded(DrawableFrameRef&& aFrameRef,
gfxContext *aContext,
const nsIntSize& aSize,
const ImageRegion& aRegion,
GraphicsFilter aFilter,
uint32_t aFlags)
{
nsRefPtr<imgFrame> frame = aFrame;
nsIntRect framerect = frame->GetRect();
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
RefPtr<SourceSurface> surf;
DrawableFrameRef frameRef;
gfx::Size scale(double(aSize.width) / mSize.width,
double(aSize.height) / mSize.height);
if (CanScale(aFilter, scale, aFlags) && !frame->IsSinglePixel()) {
// If scale factor is still the same that we scaled for and
// ScaleWorker isn't still working, then we can use pre-downscaled frame.
// If scale factor has changed, order new request.
if (CanScale(aFilter, scale, aFlags) && !aFrameRef->IsSinglePixel()) {
// FIXME: Current implementation doesn't support pre-downscale
// mechanism for multiple sizes from same src, since we cache
// pre-downscaled frame only for the latest requested scale.
// The solution is to cache more than one scaled image frame
// for each RasterImage.
bool needScaleReq;
if (mScaleResult.status == SCALE_DONE && mScaleResult.scaledSize == aSize) {
// Grab and hold the surface to make sure the OS didn't destroy it
surf = mScaleResult.frame->GetSurface();
needScaleReq = !surf;
if (surf) {
frame = mScaleResult.frame;
}
} else {
needScaleReq = !(mScaleResult.status == SCALE_PENDING &&
mScaleResult.scaledSize == aSize);
frameRef = mScaleResult.frame->DrawableRef();
}
// If we're not waiting for exactly this result, and there's only one
// instance of this image on this page, ask for a scale.
if (needScaleReq) {
RequestScale(frame, aSize);
if (!frameRef &&
(mScaleResult.status != SCALE_PENDING || mScaleResult.scaledSize != aSize)) {
// We either didn't have a complete scaled frame, it didn't match, or the
// OS threw it away. Fall back to aFrame, and request a new scaled frame
// if we're not already working on the one we need.
RequestScale(aFrameRef.get(), aSize);
}
}
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
ImageRegion region(aRegion);
if (!frameRef) {
frameRef = Move(aFrameRef);
}
// By now we may have a frame with the requested size. If not, we need to
// adjust the drawing parameters accordingly.
nsIntSize finalFrameSize(frame->GetRect().Size());
if (finalFrameSize != aSize) {
nsIntRect finalFrameRect = frameRef->GetRect();
if (finalFrameRect.Size() != aSize) {
aContext->Multiply(gfxMatrix::Scaling(scale.width, scale.height));
region.Scale(1.0 / scale.width, 1.0 / scale.height);
}
nsIntMargin padding(framerect.y,
mSize.width - framerect.XMost(),
mSize.height - framerect.YMost(),
framerect.x);
nsIntMargin padding(finalFrameRect.y,
mSize.width - finalFrameRect.XMost(),
mSize.height - finalFrameRect.YMost(),
finalFrameRect.x);
return frame->Draw(aContext, region, padding, aFilter, aFlags);
frameRef->Draw(aContext, region, padding, aFilter, aFlags);
}
//******************************************************************************
@ -2779,21 +2761,12 @@ RasterImage::Draw(gfxContext* aContext,
NS_ENSURE_SUCCESS(rv, rv);
}
uint32_t frameIndex = aWhichFrame == FRAME_FIRST ? 0
: GetCurrentImgFrameIndex();
nsRefPtr<imgFrame> frame = GetDrawableImgFrame(frameIndex);
if (!frame) {
DrawableFrameRef ref = GetFrame(GetRequestedFrameIndex(aWhichFrame));
if (!ref) {
return NS_OK; // Getting the frame (above) touches the image and kicks off decoding
}
bool drawn = DrawWithPreDownscaleIfNeeded(frame, aContext, aSize,
aRegion, aFilter, aFlags);
if (!drawn) {
// The OS threw out some or all of our buffer. Start decoding again.
ForceDiscard();
WantDecodedFrames();
return NS_OK;
}
DrawWithPreDownscaleIfNeeded(Move(ref), aContext, aSize, aRegion, aFilter, aFlags);
if (mDecoded && !mDrawStartTime.IsNull()) {
TimeDuration drawLatency = TimeStamp::Now() - mDrawStartTime;
@ -3709,12 +3682,9 @@ RasterImage::OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
}
// If there's only one instance of this image on this page, ask for a scale.
uint32_t frameIndex = aWhichFrame == FRAME_FIRST ? 0
: GetCurrentImgFrameIndex();
nsRefPtr<imgFrame> frame = GetDrawableImgFrame(frameIndex);
if (frame) {
RequestScale(frame, destSize);
DrawableFrameRef frameRef = GetFrame(GetRequestedFrameIndex(aWhichFrame));
if (frameRef) {
RequestScale(frameRef.get(), destSize);
}
}

Просмотреть файл

@ -169,10 +169,6 @@ public:
uint32_t aToOffset, uint32_t aCount,
uint32_t* aWriteCount);
/* The index of the current frame that would be drawn if the image was to be
* drawn now. */
uint32_t GetCurrentFrameIndex();
/* The total number of frames in this image. */
uint32_t GetNumFrames() const;
@ -557,8 +553,8 @@ private:
nsresult FinishedSomeDecoding(eShutdownIntent intent = eShutdownIntent_Done,
DecodeRequest* request = nullptr);
bool DrawWithPreDownscaleIfNeeded(imgFrame *aFrame,
gfxContext *aContext,
void DrawWithPreDownscaleIfNeeded(DrawableFrameRef&& aFrameRef,
gfxContext* aContext,
const nsIntSize& aSize,
const ImageRegion& aRegion,
GraphicsFilter aFilter,
@ -567,21 +563,10 @@ private:
TemporaryRef<gfx::SourceSurface> CopyFrame(uint32_t aWhichFrame,
uint32_t aFlags);
/**
* Deletes and nulls out the frame in mFrames[framenum].
*
* Does not change the size of mFrames.
*
* @param framenum The index of the frame to be deleted.
* Must lie in [0, mFrames.Length() )
*/
void DeleteImgFrame(uint32_t framenum);
already_AddRefed<imgFrame> GetImgFrameNoDecode(uint32_t framenum);
already_AddRefed<imgFrame> GetImgFrame(uint32_t framenum);
already_AddRefed<imgFrame> GetDrawableImgFrame(uint32_t framenum);
already_AddRefed<imgFrame> GetCurrentImgFrame();
uint32_t GetCurrentImgFrameIndex() const;
already_AddRefed<imgFrame> GetFrameNoDecode(uint32_t aFrameNum);
DrawableFrameRef GetFrame(uint32_t aFrameNum);
uint32_t GetCurrentFrameIndex() const;
uint32_t GetRequestedFrameIndex(uint32_t aWhichFrame) const;
size_t SizeOfDecodedWithComputedFallbackIfHeap(gfxMemoryLocation aLocation,
MallocSizeOf aMallocSizeOf) const;

Просмотреть файл

@ -12,14 +12,15 @@
#include <algorithm>
#include "mozilla/Attributes.h" // for MOZ_THIS_IN_INITIALIZER_LIST
#include "mozilla/DebugOnly.h"
#include "mozilla/Move.h"
#include "mozilla/Preferences.h"
#include "mozilla/RefPtr.h"
#include "mozilla/StaticPtr.h"
#include "nsIMemoryReporter.h"
#include "gfx2DGlue.h"
#include "gfxPattern.h" // Workaround for flaw in bug 921753 part 2.
#include "gfxDrawable.h"
#include "gfxPlatform.h"
#include "imgFrame.h"
#include "nsAutoPtr.h"
#include "nsExpirationTracker.h"
#include "nsHashKeys.h"
@ -117,7 +118,7 @@ class CachedSurface
public:
NS_INLINE_DECL_REFCOUNTING(CachedSurface)
CachedSurface(SourceSurface* aSurface,
CachedSurface(imgFrame* aSurface,
const IntSize aTargetSize,
const Cost aCost,
const ImageKey aImageKey,
@ -132,11 +133,9 @@ public:
MOZ_ASSERT(mImageKey, "Must have a valid image key");
}
already_AddRefed<gfxDrawable> Drawable() const
DrawableFrameRef DrawableRef() const
{
nsRefPtr<gfxDrawable> drawable =
new gfxSurfaceDrawable(mSurface, ThebesIntSize(mTargetSize));
return drawable.forget();
return mSurface->DrawableRef();
}
ImageKey GetImageKey() const { return mImageKey; }
@ -145,12 +144,12 @@ public:
nsExpirationState* GetExpirationState() { return &mExpirationState; }
private:
nsExpirationState mExpirationState;
nsRefPtr<SourceSurface> mSurface;
const IntSize mTargetSize;
const Cost mCost;
const ImageKey mImageKey;
const SurfaceKey mSurfaceKey;
nsExpirationState mExpirationState;
nsRefPtr<imgFrame> mSurface;
const IntSize mTargetSize;
const Cost mCost;
const ImageKey mImageKey;
const SurfaceKey mSurfaceKey;
};
/*
@ -240,14 +239,14 @@ public:
RegisterWeakMemoryReporter(this);
}
void Insert(SourceSurface* aSurface,
void Insert(imgFrame* aSurface,
IntSize aTargetSize,
const Cost aCost,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{
MOZ_ASSERT(!Lookup(aImageKey, aSurfaceKey).take(),
"Inserting a duplicate drawable into the SurfaceCache");
MOZ_ASSERT(!Lookup(aImageKey, aSurfaceKey),
"Inserting a duplicate surface into the SurfaceCache");
// If this is bigger than the maximum cache size, refuse to cache it.
if (!CanHold(aCost))
@ -317,19 +316,27 @@ public:
MOZ_ASSERT(mAvailableCost <= mMaxCost, "More available cost than we started with");
}
already_AddRefed<gfxDrawable> Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
DrawableFrameRef Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
if (!cache)
return nullptr; // No cached surfaces for this image.
return DrawableFrameRef(); // No cached surfaces for this image.
nsRefPtr<CachedSurface> surface = cache->Lookup(aSurfaceKey);
if (!surface)
return nullptr; // Lookup in the per-image cache missed.
return DrawableFrameRef(); // Lookup in the per-image cache missed.
DrawableFrameRef ref = surface->DrawableRef();
if (!ref) {
// The surface was released by the operating system. Remove the cache
// entry as well.
Remove(surface);
return DrawableFrameRef();
}
mExpirationTracker.MarkUsed(surface);
return surface->Drawable();
return ref;
}
bool CanHold(const Cost aCost) const
@ -497,7 +504,7 @@ SurfaceCache::Shutdown()
sInstance = nullptr;
}
/* static */ already_AddRefed<gfxDrawable>
/* static */ DrawableFrameRef
SurfaceCache::Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{
@ -508,7 +515,7 @@ SurfaceCache::Lookup(const ImageKey aImageKey,
}
/* static */ void
SurfaceCache::Insert(SourceSurface* aSurface,
SurfaceCache::Insert(imgFrame* aSurface,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{

Просмотреть файл

@ -4,7 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* SurfaceCache is a service for caching temporary surfaces in imagelib.
* SurfaceCache is a service for caching temporary surfaces and decoded image
* data in imagelib.
*/
#ifndef MOZILLA_IMAGELIB_SURFACECACHE_H_
@ -15,19 +16,15 @@
#include "gfxPoint.h" // for gfxSize
#include "nsCOMPtr.h" // for already_AddRefed
#include "mozilla/gfx/Point.h" // for mozilla::gfx::IntSize
#include "mozilla/gfx/2D.h" // for SourceSurface
#include "SVGImageContext.h" // for SVGImageContext
class gfxDrawable;
namespace mozilla {
namespace gfx {
class DrawTarget;
} // namespace gfx
namespace image {
class DrawableFrameRef;
class Image;
class imgFrame;
/*
* ImageKey contains the information we need to look up all cached surfaces for
@ -90,6 +87,11 @@ private:
* surfaces. Surfaces expire from the cache automatically if they go too long
* without being accessed.
*
* SurfaceCache does not hold surfaces directly; instead, it holds imgFrame
* objects, which hold surfaces but also layer on additional features specific
* to imagelib's needs like animation, padding support, and transparent support
* for volatile buffers.
*
* SurfaceCache is not thread-safe; it should only be accessed from the main
* thread.
*/
@ -108,27 +110,33 @@ struct SurfaceCache
static void Shutdown();
/*
* Look up a surface in the cache.
* Look up the imgFrame containing a surface in the cache and returns a
* drawable reference to that imgFrame.
*
* If the imgFrame was found in the cache, but had stored its surface in a
* volatile buffer which was discarded by the OS, then it is automatically
* removed from the cache and an empty DrawableFrameRef is returned.
*
* @param aImageKey Key data identifying which image the surface belongs to.
* @param aSurfaceKey Key data which uniquely identifies the requested surface.
*
* @return the requested surface, or nullptr if not found.
* @return a DrawableFrameRef to the imgFrame wrapping the requested surface,
* or an empty DrawableFrameRef if not found.
*/
static already_AddRefed<gfxDrawable> Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey);
static DrawableFrameRef Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey);
/*
* Insert a surface into the cache. It is an error to call this function
* without first calling Lookup to verify that the surface is not already in
* the cache.
*
* @param aTarget The new surface (in the form of a DrawTarget) to insert
* into the cache.
* @param aTarget The new surface (wrapped in an imgFrame) to insert into
* the cache.
* @param aImageKey Key data identifying which image the surface belongs to.
* @param aSurfaceKey Key data which uniquely identifies the requested surface.
*/
static void Insert(gfx::SourceSurface* aSurface,
static void Insert(imgFrame* aSurface,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey);

Просмотреть файл

@ -11,6 +11,7 @@
#include "gfxPlatform.h"
#include "gfxUtils.h"
#include "imgDecoderObserver.h"
#include "imgFrame.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/SVGSVGElement.h"
@ -842,27 +843,30 @@ VectorImage::Draw(gfxContext* aContext,
aSVGContext, animTime, aFlags);
if (aFlags & FLAG_BYPASS_SURFACE_CACHE) {
CreateDrawableAndShow(params);
CreateSurfaceAndShow(params);
return NS_OK;
}
nsRefPtr<gfxDrawable> drawable =
DrawableFrameRef frameRef =
SurfaceCache::Lookup(ImageKey(this),
SurfaceKey(params.size, aSVGContext,
animTime, aFlags));
// Draw.
if (drawable) {
Show(drawable, params);
if (frameRef) {
RefPtr<SourceSurface> surface = frameRef->GetSurface();
nsRefPtr<gfxDrawable> svgDrawable =
new gfxSurfaceDrawable(surface, ThebesIntSize(frameRef->GetSize()));
Show(svgDrawable, params);
} else {
CreateDrawableAndShow(params);
CreateSurfaceAndShow(params);
}
return NS_OK;
}
void
VectorImage::CreateDrawableAndShow(const SVGDrawingParameters& aParams)
VectorImage::CreateSurfaceAndShow(const SVGDrawingParameters& aParams)
{
mSVGDocumentWrapper->UpdateViewportBounds(aParams.viewportSize);
mSVGDocumentWrapper->FlushImageTransformInvalidation();
@ -885,38 +889,32 @@ VectorImage::CreateDrawableAndShow(const SVGDrawingParameters& aParams)
if (bypassCache)
return Show(svgDrawable, aParams);
// Try to create an offscreen surface.
RefPtr<gfx::DrawTarget> target =
gfxPlatform::GetPlatform()->
CreateOffscreenContentDrawTarget(aParams.size,
gfx::SurfaceFormat::B8G8R8A8);
// Try to create an imgFrame, initializing the surface it contains by drawing
// our gfxDrawable into it. (We use FILTER_NEAREST since we never scale here.)
nsRefPtr<imgFrame> frame = new imgFrame;
nsresult rv =
frame->InitWithDrawable(svgDrawable, ThebesIntSize(aParams.size),
SurfaceFormat::B8G8R8A8,
GraphicsFilter::FILTER_NEAREST, aParams.flags);
// If we couldn't create the draw target, it was probably because it would end
// If we couldn't create the frame, it was probably because it would end
// up way too big. Generally it also wouldn't fit in the cache, but the prefs
// could be set such that the cache isn't the limiting factor.
if (!target)
if (NS_FAILED(rv))
return Show(svgDrawable, aParams);
nsRefPtr<gfxContext> ctx = new gfxContext(target);
// Take a strong reference to the frame's surface and make sure it hasn't
// already been purged by the operating system.
RefPtr<SourceSurface> surface = frame->GetSurface();
if (!surface)
return Show(svgDrawable, aParams);
// Actually draw. (We use FILTER_NEAREST since we never scale here.)
nsIntRect imageRect(ThebesIntRect(aParams.imageRect));
gfxUtils::DrawPixelSnapped(ctx, svgDrawable,
ThebesIntSize(aParams.size),
ImageRegion::Create(imageRect),
SurfaceFormat::B8G8R8A8,
GraphicsFilter::FILTER_NEAREST, aParams.flags);
RefPtr<SourceSurface> surface = target->Snapshot();
// Attempt to cache the resulting surface.
SurfaceCache::Insert(surface, ImageKey(this),
// Attempt to cache the frame.
SurfaceCache::Insert(frame, ImageKey(this),
SurfaceKey(aParams.size, aParams.svgContext,
aParams.animationTime, aParams.flags));
// Draw. Note that if SurfaceCache::Insert failed for whatever reason,
// then |target| is all that is keeping the pixel data alive, so we have
// to draw before returning from this function.
// Draw.
nsRefPtr<gfxDrawable> drawable =
new gfxSurfaceDrawable(surface, ThebesIntSize(aParams.size));
Show(drawable, aParams);

Просмотреть файл

@ -86,7 +86,7 @@ protected:
virtual nsresult StopAnimation();
virtual bool ShouldAnimate();
void CreateDrawableAndShow(const SVGDrawingParameters& aParams);
void CreateSurfaceAndShow(const SVGDrawingParameters& aParams);
void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams);
private:

Просмотреть файл

@ -143,17 +143,20 @@ imgFrame::~imgFrame()
}
}
nsresult imgFrame::Init(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight,
SurfaceFormat aFormat, uint8_t aPaletteDepth /* = 0 */)
nsresult
imgFrame::InitForDecoder(const nsIntRect& aRect,
SurfaceFormat aFormat,
uint8_t aPaletteDepth /* = 0 */)
{
// assert for properties that should be verified by decoders, warn for properties related to bad content
if (!AllowedImageSize(aWidth, aHeight)) {
// Assert for properties that should be verified by decoders,
// warn for properties related to bad content.
if (!AllowedImageSize(aRect.width, aRect.height)) {
NS_WARNING("Should have legal image size");
return NS_ERROR_FAILURE;
}
mOffset.MoveTo(aX, aY);
mSize.SizeTo(aWidth, aHeight);
mOffset.MoveTo(aRect.x, aRect.y);
mSize.SizeTo(aRect.width, aRect.height);
mFormat = aFormat;
mPaletteDepth = aPaletteDepth;
@ -172,32 +175,121 @@ nsresult imgFrame::Init(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight,
NS_WARNING("moz_malloc for paletted image data should succeed");
NS_ENSURE_TRUE(mPalettedImageData, NS_ERROR_OUT_OF_MEMORY);
} else {
MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitForDecoder() twice?");
// Inform the discard tracker that we are going to allocate some memory.
if (!DiscardTracker::TryAllocation(4 * mSize.width * mSize.height)) {
NS_WARNING("Exceed the hard limit of decode image size");
mInformedDiscardTracker =
DiscardTracker::TryAllocation(4 * mSize.width * mSize.height);
if (!mInformedDiscardTracker) {
NS_WARNING("Exceeded the image decode size hard limit");
return NS_ERROR_OUT_OF_MEMORY;
}
if (!mImageSurface) {
mVBuf = AllocateBufferForImage(mSize, mFormat);
if (!mVBuf) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (mVBuf->OnHeap()) {
int32_t stride = VolatileSurfaceStride(mSize, mFormat);
VolatileBufferPtr<uint8_t> ptr(mVBuf);
memset(ptr, 0, stride * mSize.height);
}
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
mVBuf = AllocateBufferForImage(mSize, mFormat);
if (!mVBuf) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (mVBuf->OnHeap()) {
int32_t stride = VolatileSurfaceStride(mSize, mFormat);
VolatileBufferPtr<uint8_t> ptr(mVBuf);
memset(ptr, 0, stride * mSize.height);
}
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
if (!mImageSurface) {
NS_WARNING("Failed to create VolatileDataSourceSurface");
// Image surface allocation is failed, need to return
// the booked buffer size.
DiscardTracker::InformDeallocation(4 * mSize.width * mSize.height);
return NS_ERROR_OUT_OF_MEMORY;
}
mInformedDiscardTracker = true;
}
return NS_OK;
}
nsresult
imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
const nsIntSize& aSize,
const SurfaceFormat aFormat,
GraphicsFilter aFilter,
uint32_t aImageFlags)
{
// Assert for properties that should be verified by decoders,
// warn for properties related to bad content.
if (!AllowedImageSize(aSize.width, aSize.height)) {
NS_WARNING("Should have legal image size");
return NS_ERROR_FAILURE;
}
mOffset.MoveTo(0, 0);
mSize.SizeTo(aSize.width, aSize.height);
mFormat = aFormat;
mPaletteDepth = 0;
// Inform the discard tracker that we are going to allocate some memory.
mInformedDiscardTracker =
DiscardTracker::TryAllocation(4 * mSize.width * mSize.height);
if (!mInformedDiscardTracker) {
NS_WARNING("Exceed the image decode size hard limit");
return NS_ERROR_OUT_OF_MEMORY;
}
RefPtr<DrawTarget> target;
bool canUseDataSurface =
gfxPlatform::GetPlatform()->CanRenderContentToDataSurface();
if (canUseDataSurface) {
// It's safe to use data surfaces for content on this platform, so we can
// get away with using volatile buffers.
MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitWithDrawable() twice?");
mVBuf = AllocateBufferForImage(mSize, mFormat);
if (!mVBuf) {
return NS_ERROR_OUT_OF_MEMORY;
}
int32_t stride = VolatileSurfaceStride(mSize, mFormat);
VolatileBufferPtr<uint8_t> ptr(mVBuf);
if (!ptr) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (mVBuf->OnHeap()) {
memset(ptr, 0, stride * mSize.height);
}
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
target = gfxPlatform::GetPlatform()->
CreateDrawTargetForData(ptr, mSize, stride, mFormat);
} else {
// We can't use data surfaces for content, so we'll create an offscreen
// surface instead. This means if someone later calls RawAccessRef(), we
// may have to do an expensive readback, but we warned callers about that in
// the documentation for this method.
MOZ_ASSERT(!mOptSurface, "Called imgFrame::InitWithDrawable() twice?");
target = gfxPlatform::GetPlatform()->
CreateOffscreenContentDrawTarget(mSize, mFormat);
}
if (!target) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Draw using the drawable the caller provided.
nsIntRect imageRect(0, 0, mSize.width, mSize.height);
nsRefPtr<gfxContext> ctx = new gfxContext(target);
gfxUtils::DrawPixelSnapped(ctx, aDrawable, ThebesIntSize(mSize),
ImageRegion::Create(imageRect),
mFormat, aFilter, aImageFlags);
if (canUseDataSurface && !mImageSurface) {
NS_WARNING("Failed to create VolatileDataSourceSurface");
return NS_ERROR_OUT_OF_MEMORY;
}
if (!canUseDataSurface) {
// We used an offscreen surface, which is an "optimized" surface from
// imgFrame's perspective.
mOptSurface = target->Snapshot();
}
return NS_OK;

Просмотреть файл

@ -36,7 +36,44 @@ public:
imgFrame();
nsresult Init(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight, SurfaceFormat aFormat, uint8_t aPaletteDepth = 0);
/**
* Initialize this imgFrame with an empty surface and prepare it for being
* written to by a decoder.
*
* This is appropriate for use with decoded images, but it should not be used
* when drawing content into an imgFrame, as it may use a different graphics
* backend than normal content drawing.
*/
nsresult InitForDecoder(const nsIntRect& aRect,
SurfaceFormat aFormat,
uint8_t aPaletteDepth = 0);
nsresult InitForDecoder(const nsIntSize& aSize,
SurfaceFormat aFormat,
uint8_t aPaletteDepth = 0)
{
return InitForDecoder(nsIntRect(0, 0, aSize.width, aSize.height),
aFormat, aPaletteDepth);
}
/**
* Initialize this imgFrame with a new surface and draw the provided
* gfxDrawable into it.
*
* This is appropriate to use when drawing content into an imgFrame, as it
* uses the same graphics backend as normal content drawing. The downside is
* that the underlying surface may not be stored in a volatile buffer on all
* platforms, and raw access to the surface (using RawAccessRef() or
* LockImageData()) may be much more expensive than in the InitForDecoder()
* case.
*/
nsresult InitWithDrawable(gfxDrawable* aDrawable,
const nsIntSize& aSize,
const SurfaceFormat aFormat,
GraphicsFilter aFilter,
uint32_t aImageFlags);
nsresult Optimize();
DrawableFrameRef DrawableRef();

Просмотреть файл

@ -75,6 +75,7 @@ class LIRGeneratorNone : public LIRGeneratorShared
LTableSwitchV *newLTableSwitchV(MTableSwitch *) { MOZ_CRASH(); }
bool visitSimdTernaryBitwise(MSimdTernaryBitwise *ins) { MOZ_CRASH(); }
bool visitSimdSplatX4(MSimdSplatX4 *ins) { MOZ_CRASH(); }
bool visitSimdValueX4(MSimdValueX4 *lir) { MOZ_CRASH(); }
};
typedef LIRGeneratorNone LIRGeneratorSpecific;

Просмотреть файл

@ -1,9 +1,19 @@
<svg xmlns="http://www.w3.org/2000/svg">
<rect x="10" y="10" width="80" height="80" fill="#00ff00"/>
<rect x="110" y="10" width="80" height="80" fill="#000000"/>
<rect x="210" y="10" width="80" height="80" fill="#ffff00"/>
<rect x="310" y="10" width="80" height="80" fill="#000000"/>
<rect x="410" y="10" width="80" height="80" fill="#ffff00"/>
<rect x="0" y="0" width="50" height="50" fill="#ACCC10"/>
<rect x="50" y="0" width="50" height="50" fill="#B4B43F"/>
<rect x="100" y="0" width="50" height="50" fill="#DFDF3F"/>
<rect x="150" y="0" width="50" height="50" fill="#B4B43F"/>
<rect x="200" y="0" width="50" height="50" fill="#DFDF3F"/>
<rect x="250" y="0" width="50" height="50" fill="#DFB43F"/>
<rect x="300" y="0" width="50" height="50" fill="#DFB43F"/>
<rect x="350" y="0" width="50" height="50" fill="#DFB43F"/>
<rect x="0" y="50" width="50" height="50" fill="#E0B440"/>
<rect x="50" y="50" width="50" height="50" fill="#DFB43F"/>
<rect x="100" y="50" width="50" height="50" fill="#DFDF3F"/>
<rect x="150" y="50" width="50" height="50" fill="#DFDF3F"/>
<rect x="200" y="50" width="50" height="50" fill="#B4CC3F"/>
<rect x="250" y="50" width="50" height="50" fill="#DFB43F"/>
<rect x="300" y="50" width="50" height="50" fill="#B4CC3F"/>
<rect x="350" y="50" width="50" height="50" fill="#DFC88D"/>
</svg>

До

Ширина:  |  Высота:  |  Размер: 354 B

После

Ширина:  |  Высота:  |  Размер: 1011 B

Просмотреть файл

@ -1,38 +1,104 @@
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="f1" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox"
x="0%" y="0%" width="100%" height="100%">
<feFlood flood-color="#ff0000" result="flood"/>
<feBlend mode="normal" in="SourceGraphic" in2="flood" x="10%" y="10%" width="80%" height="80%"/>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%">
<filter id="f0" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="normal"/>
</filter>
<rect x="0" y="0" width="100" height="100" fill="#00ff00" filter="url(#f1)"/>
<filter id="f2" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox"
x="0%" y="0%" width="100%" height="100%">
<feFlood flood-color="#ff0000" result="flood"/>
<feBlend mode="multiply" in="SourceGraphic" in2="flood" x="10%" y="10%" width="80%" height="80%"/>
<rect x="0" y="0" width="50" height="50" filter="url(#f0)"/>
<filter id="f1" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="multiply"/>
</filter>
<rect x="100" y="0" width="100" height="100" fill="#00ff00" filter="url(#f2)"/>
<filter id="f3" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox"
x="0%" y="0%" width="100%" height="100%">
<feFlood flood-color="#ff0000" result="flood"/>
<feBlend mode="screen" in="SourceGraphic" in2="flood" x="10%" y="10%" width="80%" height="80%"/>
<rect x="50" y="0" width="50" height="50" filter="url(#f1)"/>
<filter id="f2" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="screen"/>
</filter>
<rect x="200" y="0" width="100" height="100" fill="#00ff00" filter="url(#f3)"/>
<filter id="f4" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox"
x="0%" y="0%" width="100%" height="100%">
<feFlood flood-color="#ff0000" result="flood"/>
<feBlend mode="darken" in="SourceGraphic" in2="flood" x="10%" y="10%" width="80%" height="80%"/>
<rect x="100" y="0" width="50" height="50" filter="url(#f2)"/>
<filter id="f3" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="darken"/>
</filter>
<rect x="300" y="0" width="100" height="100" fill="#00ff00" filter="url(#f4)"/>
<filter id="f5" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox"
x="0%" y="0%" width="100%" height="100%">
<feFlood flood-color="#ff0000" result="flood"/>
<feBlend mode="lighten" in="SourceGraphic" in2="flood" x="10%" y="10%" width="80%" height="80%"/>
<rect x="150" y="0" width="50" height="50" filter="url(#f3)"/>
<filter id="f4" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="lighten"/>
</filter>
<rect x="400" y="0" width="100" height="100" fill="#00ff00" filter="url(#f5)"/>
</svg>
<rect x="200" y="0" width="50" height="50" filter="url(#f4)"/>
<filter id="f5" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="overlay"/>
</filter>
<rect x="250" y="0" width="50" height="50" filter="url(#f5)"/>
<filter id="f6" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="color-dodge"/>
</filter>
<rect x="300" y="0" width="50" height="50" filter="url(#f6)"/>
<filter id="f7" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="color-burn"/>
</filter>
<rect x="350" y="0" width="50" height="50" filter="url(#f7)"/>
<filter id="f8" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="hard-light"/>
</filter>
<rect x="0" y="0" width="50" height="50" filter="url(#f8)"/>
<filter id="f9" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="soft-light"/>
</filter>
<rect x="50" y="50" width="50" height="50" filter="url(#f9)"/>
<filter id="f10" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="difference"/>
</filter>
<rect x="100" y="50" width="50" height="50" filter="url(#f10)"/>
<filter id="f11" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="exclusion"/>
</filter>
<rect x="150" y="50" width="50" height="50" filter="url(#f11)"/>
<filter id="f12" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="hue"/>
</filter>
<rect x="200" y="50" width="50" height="50" filter="url(#f12)"/>
<filter id="f13" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="saturation"/>
</filter>
<rect x="250" y="50" width="50" height="50" filter="url(#f13)"/>
<filter id="f14" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="color"/>
</filter>
<rect x="300" y="50" width="50" height="50" filter="url(#f14)"/>
<filter id="f15" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="luminosity"/>
</filter>
<rect x="350" y="50" width="50" height="50" filter="url(#f15)"/>
<filter id="f16" x="0%" y="0%" width="100%" height="100%">
<feFlood result="a" flood-color="rgb(255,0,0)" flood-opacity="0.5"/>
<feFlood result="b" flood-color="rgb(0,255,0)" flood-opacity="0.5"/>
<feBlend in="a" in2="b" mode="undefined"/>
</filter>
<rect x="0" y="50" width="50" height="50" filter="url(#f16)"/>
</svg>

До

Ширина:  |  Высота:  |  Размер: 1.9 KiB

После

Ширина:  |  Высота:  |  Размер: 5.4 KiB

Просмотреть файл

@ -18,7 +18,7 @@ include svg-filter-chains/reftest.list
== dynamic-filter-invalidation-01.svg pass.svg
== dynamic-filter-invalidation-02.svg pass.svg
== feBlend-1.svg feBlend-1-ref.svg
fuzzy(1,40000) == feBlend-1.svg feBlend-1-ref.svg
== feBlend-2.svg feBlend-2-ref.svg
fuzzy-if(d2d,1,6400) == feColorMatrix-1.svg feColorMatrix-1-ref.svg

Просмотреть файл

@ -102,13 +102,17 @@ MP4Demuxer::Init()
if (!mPrivate->mAudio.get() && !strncmp(mimeType, "audio/", 6)) {
mPrivate->mAudio = e->getTrack(i);
mPrivate->mAudio->start();
if (mPrivate->mAudio->start() != OK) {
return false;
}
mAudioConfig.Update(metaData, mimeType);
mPrivate->mIndexes.AppendElement(new Index(
mPrivate->mAudio->exportIndex(), mSource, mAudioConfig.mTrackId));
} else if (!mPrivate->mVideo.get() && !strncmp(mimeType, "video/", 6)) {
mPrivate->mVideo = e->getTrack(i);
mPrivate->mVideo->start();
if (mPrivate->mVideo->start() != OK) {
return false;
}
mVideoConfig.Update(metaData, mimeType);
mPrivate->mIndexes.AppendElement(new Index(
mPrivate->mVideo->exportIndex(), mSource, mVideoConfig.mTrackId));

Просмотреть файл

@ -48,7 +48,6 @@ public:
int32_t timeScale,
const sp<SampleTable> &sampleTable,
Vector<SidxEntry> &sidx,
off64_t firstMoofOffset,
MPEG4Extractor::TrackExtends &trackExtends);
virtual status_t start(MetaData *params = NULL);
@ -73,6 +72,7 @@ private:
uint32_t mCurrentSampleIndex;
uint32_t mCurrentFragmentIndex;
Vector<SidxEntry> &mSegments;
bool mLookedForMoof;
off64_t mFirstMoofOffset;
off64_t mCurrentMoofOffset;
off64_t mNextMoofOffset;
@ -111,6 +111,7 @@ private:
status_t parseTrackFragmentRun(off64_t offset, off64_t size);
status_t parseSampleAuxiliaryInformationSizes(off64_t offset, off64_t size);
status_t parseSampleAuxiliaryInformationOffsets(off64_t offset, off64_t size);
void lookForMoof();
struct TrackFragmentData {
TrackFragmentData(): mPresent(false), mFlags(0), mBaseMediaDecodeTime(0) {}
@ -349,7 +350,6 @@ static bool AdjustChannelsAndRate(uint32_t fourcc, uint32_t *channels, uint32_t
MPEG4Extractor::MPEG4Extractor(const sp<DataSource> &source)
: mSidxDuration(0),
mMoofOffset(0),
mDataSource(source),
mInitCheck(NO_INIT),
mHasVideo(false),
@ -386,9 +386,7 @@ MPEG4Extractor::~MPEG4Extractor() {
}
uint32_t MPEG4Extractor::flags() const {
return CAN_PAUSE |
((mMoofOffset == 0 || mSidxEntries.size() != 0) ?
(CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_SEEK) : 0);
return CAN_PAUSE | CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_SEEK;
}
sp<MetaData> MPEG4Extractor::getMetaData() {
@ -439,38 +437,6 @@ sp<MetaData> MPEG4Extractor::getTrackMetaData(
return NULL;
}
if ((flags & kIncludeExtensiveMetaData)
&& !track->includes_expensive_metadata) {
track->includes_expensive_metadata = true;
const char *mime;
CHECK(track->meta->findCString(kKeyMIMEType, &mime));
if (!strncasecmp("video/", mime, 6)) {
if (mMoofOffset > 0) {
int64_t duration;
if (track->meta->findInt64(kKeyDuration, &duration)) {
// nothing fancy, just pick a frame near 1/4th of the duration
track->meta->setInt64(
kKeyThumbnailTime, duration / 4);
}
} else {
uint32_t sampleIndex;
uint32_t sampleTime;
if (track->sampleTable->findThumbnailSample(&sampleIndex) == OK
&& track->sampleTable->getMetaDataForSample(
sampleIndex, NULL /* offset */, NULL /* size */,
&sampleTime) == OK) {
if (!track->timescale) {
return NULL;
}
track->meta->setInt64(
kKeyThumbnailTime,
((int64_t)sampleTime * 1000000) / track->timescale);
}
}
}
}
return track->meta;
}
@ -488,27 +454,9 @@ status_t MPEG4Extractor::readMetaData() {
}
off64_t offset = 0;
status_t err = OK;
while (true) {
uint32_t hdr[2];
if (mDataSource->readAt(offset, hdr, 8) < 8) {
break;
}
uint32_t chunk_type = ntohl(hdr[1]);
if (chunk_type == FOURCC('m', 'd', 'a', 't') && mFirstTrack) {
break;
}
if (chunk_type == FOURCC('m', 'o', 'o', 'f')) {
// store the offset of the first segment
mMoofOffset = offset;
break;
}
status_t err;
while (!mFirstTrack) {
err = parseChunk(&offset, 0);
if (err != OK &&
chunk_type != FOURCC('s', 'i', 'd', 'x') &&
chunk_type != FOURCC('m', 'o', 'o', 'v')) {
break;
}
}
if (mInitCheck == OK) {
@ -2253,7 +2201,7 @@ sp<MediaSource> MPEG4Extractor::getTrack(size_t index) {
return new MPEG4Source(
track->meta, mDataSource, track->timescale, track->sampleTable,
mSidxEntries, mMoofOffset, mTrackExtends);
mSidxEntries, mTrackExtends);
}
// static
@ -2412,7 +2360,6 @@ MPEG4Source::MPEG4Source(
int32_t timeScale,
const sp<SampleTable> &sampleTable,
Vector<SidxEntry> &sidx,
off64_t firstMoofOffset,
MPEG4Extractor::TrackExtends &trackExtends)
: mFormat(format),
mDataSource(dataSource),
@ -2421,8 +2368,9 @@ MPEG4Source::MPEG4Source(
mCurrentSampleIndex(0),
mCurrentFragmentIndex(0),
mSegments(sidx),
mFirstMoofOffset(firstMoofOffset),
mCurrentMoofOffset(firstMoofOffset),
mLookedForMoof(false),
mFirstMoofOffset(0),
mCurrentMoofOffset(0),
mCurrentTime(0),
mCurrentSampleInfoAllocSize(0),
mCurrentSampleInfoSizes(NULL),
@ -2470,11 +2418,6 @@ MPEG4Source::MPEG4Source(
}
CHECK(format->findInt32(kKeyTrackID, &mTrackId));
if (mFirstMoofOffset != 0) {
off64_t offset = mFirstMoofOffset;
parseChunk(&offset);
}
}
MPEG4Source::~MPEG4Source() {
@ -2485,6 +2428,13 @@ MPEG4Source::~MPEG4Source() {
free(mCurrentSampleInfoOffsets);
}
static bool ValidInputSize(int32_t size) {
// Reject compressed samples larger than an uncompressed UHD
// frame. This is a reasonable cut-off for a lossy codec,
// combined with the current Firefox limit to 5k video.
return (size > 0 && size < 4 * (1920 * 1080) * 3 / 2);
}
status_t MPEG4Source::start(MetaData *params) {
Mutex::Autolock autoLock(mLock);
@ -2500,6 +2450,10 @@ status_t MPEG4Source::start(MetaData *params) {
int32_t max_size;
CHECK(mFormat->findInt32(kKeyMaxInputSize, &max_size));
if (!ValidInputSize(max_size)) {
ALOGE("Invalid max input size %d", max_size);
return ERROR_MALFORMED;
}
mSrcBuffer = new uint8_t[max_size];
@ -3131,12 +3085,43 @@ size_t MPEG4Source::parseNALSize(const uint8_t *data) const {
return 0;
}
void MPEG4Source::lookForMoof() {
off64_t offset = 0;
off64_t size;
while (true) {
uint32_t hdr[2];
auto x = mDataSource->readAt(offset, hdr, 8);
if (x < 8) {
break;
}
uint32_t chunk_size = ntohl(hdr[0]);
uint32_t chunk_type = ntohl(hdr[1]);
char chunk[5];
MakeFourCCString(chunk_type, chunk);
if (chunk_type == FOURCC('m', 'o', 'o', 'f')) {
mFirstMoofOffset = mCurrentMoofOffset = offset;
parseChunk(&offset);
break;
}
if (chunk_type == FOURCC('m', 'd', 'a', 't')) {
break;
}
offset += chunk_size;
}
}
status_t MPEG4Source::read(
MediaBuffer **out, const ReadOptions *options) {
Mutex::Autolock autoLock(mLock);
CHECK(mStarted);
if (!mLookedForMoof) {
mLookedForMoof = true;
lookForMoof();
}
if (mFirstMoofOffset > 0) {
return fragmentedRead(out, options);
}
@ -3251,6 +3236,10 @@ status_t MPEG4Source::read(
int32_t max_size;
CHECK(mFormat->findInt32(kKeyMaxInputSize, &max_size));
if (!ValidInputSize(max_size)) {
ALOGE("Invalid max input size %d", max_size);
return ERROR_MALFORMED;
}
mBuffer = new MediaBuffer(max_size);
assert(mBuffer);
}
@ -3533,6 +3522,10 @@ status_t MPEG4Source::fragmentedRead(
int32_t max_size;
CHECK(mFormat->findInt32(kKeyMaxInputSize, &max_size));
if (!ValidInputSize(max_size)) {
ALOGE("Invalid max input size %d", max_size);
return ERROR_MALFORMED;
}
mBuffer = new MediaBuffer(max_size);
assert(mBuffer);
}

Просмотреть файл

@ -93,7 +93,6 @@ private:
Vector<SidxEntry> mSidxEntries;
uint64_t mSidxDuration;
off64_t mMoofOffset;
Vector<PsshInfo> mPssh;

Просмотреть файл

@ -41,19 +41,19 @@ table {
/******************************
* TEST RESULT COLORS
******************************/
span.passed, .passed .col-result {
span.pass, .pass .col-result {
color: green;
}
span.expected.failure, .expected.failure .col-result {
span.expected_fail, .expected_fail .col-result {
color: orange;
}
span.skipped, .skipped .col-result {
span.skip, .skip .col-result {
color: orange;
}
span.unexpected.pass, .unexpected.pass .col-result {
span.unexpected_pass, .unexpected_pass .col-result {
color: red;
}
span.failed, .failure .col-result {
span.fail, .fail .col-result {
color: red;
}
span.error,.error .col-result {

Просмотреть файл

@ -6,6 +6,7 @@ from threading import Lock
import codecs
from ..structuredlog import log_levels
from statushandler import StatusHandler
class BaseHandler(object):

Просмотреть файл

@ -0,0 +1,59 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from collections import defaultdict
from mozlog.structured.structuredlog import log_levels
class StatusHandler(object):
"""A handler used to determine an overall status for a test run according
to a sequence of log messages."""
def __init__(self):
# The count of unexpected results (includes tests and subtests)
self.unexpected = 0
# The count of skip results (includes tests and subtests)
self.skipped = 0
# The count of top level tests run (test_end messages)
self.test_count = 0
# The count of messages logged at each log level
self.level_counts = defaultdict(int)
def __call__(self, data):
action = data['action']
if action == 'log':
self.level_counts[data['level']] += 1
if action == 'test_end':
self.test_count += 1
if action in ('test_status', 'test_end'):
if 'expected' in data:
self.unexpected += 1
if data['status'] == 'SKIP':
self.skipped += 1
def evaluate(self):
status = 'OK'
if self.unexpected:
status = 'FAIL'
if not self.test_count:
status = 'ERROR'
for level in self.level_counts:
if log_levels[level] <= log_levels['ERROR']:
status = 'ERROR'
summary = {
'status': status,
'unexpected': self.unexpected,
'skipped': self.skipped,
'test_count': self.test_count,
'level_counts': dict(self.level_counts),
}
return summary

Просмотреть файл

@ -56,6 +56,84 @@ class BaseStructuredTest(unittest.TestCase):
self.assertEquals(set(all_expected.keys()) | specials, set(actual.keys()))
class TestStatusHandler(BaseStructuredTest):
def setUp(self):
super(TestStatusHandler, self).setUp()
self.handler = handlers.StatusHandler()
self.logger.add_handler(self.handler)
def assertStatus(self, expected):
"""Assert every key present in expected matches the current
status."""
actual = self.handler.evaluate()
for k, v in expected.iteritems():
self.assertEquals(expected[k], actual[k])
def test_ok_run(self):
self.logger.suite_start([])
self.logger.test_start("test1")
self.logger.test_status("test1", "sub1", status='PASS')
self.logger.info("Info between sub1 and sub2")
self.logger.test_status("test1", "sub2", status='PASS')
self.logger.test_end("test1", status='OK')
self.logger.suite_end()
self.assertStatus({
"status": "OK",
"test_count": 1,
"level_counts": { "INFO": 1 },
})
def test_failure_run(self):
self.logger.suite_start([])
self.logger.test_start("test1")
self.logger.test_status("test1", "sub1", status='PASS')
self.logger.test_status("test1", "sub2", status='TIMEOUT')
self.logger.test_end("test1", status='OK')
self.logger.suite_end()
self.assertStatus({
"status": "FAIL",
"test_count": 1,
"unexpected": 1,
"level_counts": {},
})
def test_error_run(self):
self.logger.suite_start([])
self.logger.test_start("test1")
self.logger.error("ERRR!")
self.logger.test_end("test1", status='PASS')
self.logger.test_start("test2")
self.logger.test_end("test2", status='PASS')
self.logger.suite_end()
self.assertStatus({
"status": "ERROR",
"test_count": 2,
"level_counts": {'ERROR': 1},
})
def test_error_trumps_failure(self):
self.logger.suite_start([])
self.logger.test_start("test1")
self.logger.critical("ERRR!")
self.logger.test_status("test1", "sub1", status='FAIL')
self.logger.test_end("test1", status='OK')
self.logger.suite_end()
self.assertStatus({
"status": "ERROR",
"test_count": 1,
"level_counts": {'CRITICAL': 1},
})
def test_notrun_is_error(self):
self.logger.suite_start([])
self.logger.suite_end()
self.assertStatus({
"status": "ERROR",
"test_count": 0,
"level_counts": {},
})
class TestStructuredLog(BaseStructuredTest):
def test_suite_start(self):
self.logger.suite_start(["test"])

Просмотреть файл

@ -37,33 +37,20 @@ private:
~WinWakeLockListener() {}
NS_IMETHOD Callback(const nsAString& aTopic, const nsAString& aState) {
bool isLocked = mLockedTopics.Contains(aTopic);
bool shouldLock = aState.EqualsLiteral("locked-foreground");
if (isLocked == shouldLock) {
if (!aTopic.EqualsASCII("screen")) {
return NS_OK;
}
if (shouldLock) {
if (!mLockedTopics.Count()) {
// This is the first topic to request the screen saver be disabled.
// Prevent screen saver.
SetThreadExecutionState(ES_DISPLAY_REQUIRED|ES_CONTINUOUS);
}
mLockedTopics.PutEntry(aTopic);
// Note the wake lock code ensures that we're not sent duplicate
// "locked-foreground" notifications when multipe wake locks are held.
if (aState.EqualsASCII("locked-foreground")) {
// Prevent screen saver.
SetThreadExecutionState(ES_DISPLAY_REQUIRED|ES_CONTINUOUS);
} else {
mLockedTopics.RemoveEntry(aTopic);
if (!mLockedTopics.Count()) {
// No other outstanding topics have requested screen saver be disabled.
// Re-enable screen saver.
SetThreadExecutionState(ES_CONTINUOUS);
}
}
// Re-enable screen saver.
SetThreadExecutionState(ES_CONTINUOUS);
}
return NS_OK;
}
// Keep track of all the topics that have requested a wake lock. When the
// number of topics in the hashtable reaches zero, we can uninhibit the
// screensaver again.
nsTHashtable<nsStringHashKey> mLockedTopics;
};
NS_IMPL_ISUPPORTS(WinWakeLockListener, nsIDOMMozWakeLockListener)

Просмотреть файл

@ -527,21 +527,29 @@ PuppetWidget::NotifyIMEOfUpdateComposition()
NS_ENSURE_TRUE(textComposition, NS_ERROR_FAILURE);
nsEventStatus status;
uint32_t offset = textComposition->OffsetOfTargetClause();
WidgetQueryContentEvent textRect(true, NS_QUERY_TEXT_RECT, this);
InitEvent(textRect, nullptr);
textRect.InitForQueryTextRect(offset, 1);
DispatchEvent(&textRect, status);
NS_ENSURE_TRUE(textRect.mSucceeded, NS_ERROR_FAILURE);
nsTArray<nsIntRect> textRectArray(textComposition->String().Length());
uint32_t startOffset = textComposition->NativeOffsetOfStartComposition();
uint32_t endOffset = textComposition->String().Length() + startOffset;
for (uint32_t i = startOffset; i < endOffset; i++) {
WidgetQueryContentEvent textRect(true, NS_QUERY_TEXT_RECT, this);
InitEvent(textRect, nullptr);
textRect.InitForQueryTextRect(i, 1);
DispatchEvent(&textRect, status);
NS_ENSURE_TRUE(textRect.mSucceeded, NS_ERROR_FAILURE);
textRectArray.AppendElement(textRect.mReply.mRect);
}
uint32_t targetCauseOffset = textComposition->OffsetOfTargetClause();
WidgetQueryContentEvent caretRect(true, NS_QUERY_CARET_RECT, this);
InitEvent(caretRect, nullptr);
caretRect.InitForQueryCaretRect(offset);
caretRect.InitForQueryCaretRect(targetCauseOffset);
DispatchEvent(&caretRect, status);
NS_ENSURE_TRUE(caretRect.mSucceeded, NS_ERROR_FAILURE);
mTabChild->SendNotifyIMESelectedCompositionRect(offset,
textRect.mReply.mRect,
mTabChild->SendNotifyIMESelectedCompositionRect(startOffset,
textRectArray,
targetCauseOffset,
caretRect.mReply.mRect);
return NS_OK;
}