mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 05:37:11 +00:00
0cf4874c58
- Bug 1206072 - Don't call GetNextRenderTarget if CreateRenderTargetSet failed,r=vlad (323c478a5d) - Bug 1210444 - Set DEALLOCATE_CLIENT flag for EGLImage SharedSurfaceTextureClients. r=nical (194d629af0) - Bug 1218395 - Avoid calling AddFlags from SharedSurfaceTextureClient constructor. r=milan (335cdc86d3) - Bug 1226000 - control may pick up its name from wrong label, r=yzen (2686bf0a50) - bug 1213402 - add another , to fix silly string concatonation r=me landed on a CLOSED TREE (0900ea3a94) - Bug 1189108 - Walk up tree to get LinkableAccessible actions instead of caching r=tbsaunde (3ee63b4b0b) - Bug 1174383 - Fix bogus gfx/2d debug assertions that have side effects. r=Bas (0e47cdfd76) - Bug 1222569 - remove unused const variables from ExtendInputEffectD2D1.cpp; r=Bas (790f7ac4ed) - Bug 1191527 - Fix the YCbCr shaders in BlitImageToFramebuffer. r=jgilbert (68c5fcd454) - Bug 1207153 - Restore texture binding to correct target in GLBlitHelper. r=snorp (5f199889e2) - Bug 1178601 - Don't crash on incomplete FB. - r=jrmuizel (5bb9860bd3) - Bug 1164088 - Avoid IsFramebuffer assertion on Android emulator; r=jgilbert (2eaed192af) - Bug 1213431. Support using Core profile for WebGL2 on Linux. r=jgilbert (8cfa018ec7) - Bug 1209612 - Formalize client vs display EGL exts, and don't check client exts on ANDROID due to topcrash. - r=jrmuizel,snorp (0e98415c39) - Bug 1186431. Backout "Recreate the RenderTargetView on demand" r=jgilbert (90ff243064) - Bug 1213339 - Fix logic in WantsSmallTiles. r=nical (7c0e4c4d7d) - Bug 1212664 - Perform y-inversion correctly when dumping compositor surface. r=jrmuizel (01963dd49d) - Bug 1223540 - Add a pref for CGL's multithreaded mode (EMPEngine). r=jrmuizel (53b6cf04bd) - Bug 1133527. Fallback to software vsync on android. r=kats (40207086ae) - Bug 1200098 - patch 3 - Pass the gr_nobidi flag when shaping with graphite2, as we split text into unidirectional runs ahead of time. r=jdaggett (4de177c3fe) - Bug 1226801 - None of the GCHashMap users require movable keys; r=fitzgen (0f4c2e7cd7) - Bug 1226687 - Part 1: Export a GCPolicy usable by JS::Heap; r=fitzgen (cf5466239a) - Bug 1226687 - Part 2: Use stable hashing and builtin sweep for JSObject2JSObjectMap; r=mccr8 (4c68f76048) - Bug 1224418 - Functions directly scoped under non-syntactic scopes should be considered cloneable. (r=billm) (9efd091f1d) - No Bug - Remove two unused, orphan variables; r=sfink (1e2191c4c2) - Bug 1223990 - Cleanly throw errors in self-hosted code. (r=till) (6f25a3bd3e) - Bug 1132183 - Make |this| a real binding, remove lazy this computation. r=efaust,shu (c1e39487a2) - Bug 1221844 - Part 1: TraceLogger: Move TraceLogger_Invalidation to LOG_ITEM. r=h4writer (c2bbb7edd8) - Bug 1221844 - Part 2: TraceLogger: Add some debug checks to logTimestamp. r=h4writer (9ee099bd8b) - Bug 1223636: Tracelogger - Don't treat extraTextId as containing only extra ids, r=bbouvier (bad93df318) - Bug 1224123 - "Tracelogger: fix the use of LastEntryId in tracelogger.h". r=hv1989 (2cf9a30cf1) - Bug 1205893 - Eliminate vanilla memory allocations in Debugger-vixl. r=sstangl (56a3e3d37b) - Bug 1205893 - Remove vanilla allocations in ARM64 simulator. r=sstangl Use js_malloc/js_free and js_new/js_delete where appropriate. (5da0ec44b3) - Bug 1208674 - part 1: Add ToggleCall assertions. r=sstangl Assert that the ToggleCall() function does not overwrite any unexpected instructions. (cfb5c4be1a) - Bug 1208674 - Fix ToggleCall to handle constant pools. r=sstangl Handle constant pools inserted anywhere, even at the initial pointer location. Don't attempt handling constant pools with natural guard branches. They are not relevant here (and actually never generated currently). (cd025860b4) - Bug 1208259 - Handle OOM in the ARM64 VIXL Simulator. r=sstangl Make the Simulator creation robust against OOM stress tests. Now passes jsapitests testNewRuntime. (92a26871eb) - Bug 1219050 - Update VIXL helper code to v1.10. r=jolesen (7e57b34e76) - Bug 1227263 part 1 - Rename frame thisValue methods to thisArgument. r=shu (5818076931) - Bug 1227263 part 2 - Remove this-slot from generators. r=efaust (c89453a7ce) - Bug 1227263 part 3 - Remove this-slot from non-function frames. r=efaust (c2dd744cca) - Bug 1207571 r=jandem a=abillings (461bb9213f) - Bug 1108290 - introduce machine-independent definitions of sub32. r=nbp (2906131e4d) - Bug 1226799 - De-duplicate the 11 Is[BuiltinName] self-hosting intrinsics with templates. r=arai (50bcb68306) - No Bug - Fix accumulated unified build bustage in the JS shell; r=sfink (dbf8db9215) - Bug 1227535 - Add ZoneAllocPolicy and use it to attribute module memory usage to the zone r=terrence (63127682a9) - Bug 1227555 - Force specialization of JSObject::is() for ProxyObject subclasses r=shu (95b6dc79f8) - Bug 1201620 - Follow up: add a missing null check in js::SavedFrame::isSavedFrameOrWrapperAndNotProto; r=terrence (f2b6cc4751) - Bug 1226936 - Remove PreserveRegExpStatics and telemetry for it. r=till (6ca85fb1ea) - Bug 1221747 - Fix OOM handling in IonScriptCounts r=nbp (aea5012869) - Bug 1094057 - Violations of "use strict"; should generate errors, not warnings, r=jorendorff (627a9def4c)
399 lines
12 KiB
C++
399 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* 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/. */
|
|
|
|
#include "RadialGradientEffectD2D1.h"
|
|
|
|
#include "Logging.h"
|
|
|
|
#include "ShadersD2D1.h"
|
|
#include "HelpersD2D.h"
|
|
|
|
#include <vector>
|
|
|
|
#define TEXTW(x) L##x
|
|
#define XML(X) TEXTW(#X) // This macro creates a single string from multiple lines of text.
|
|
|
|
static const PCWSTR kXmlDescription =
|
|
XML(
|
|
<?xml version='1.0'?>
|
|
<Effect>
|
|
<!-- System Properties -->
|
|
<Property name='DisplayName' type='string' value='RadialGradientEffect'/>
|
|
<Property name='Author' type='string' value='Mozilla'/>
|
|
<Property name='Category' type='string' value='Pattern effects'/>
|
|
<Property name='Description' type='string' value='This effect is used to render radial gradients in a manner compliant with the 2D Canvas specification.'/>
|
|
<Inputs>
|
|
<Input name='Geometry'/>
|
|
</Inputs>
|
|
<Property name='StopCollection' type='iunknown'>
|
|
<Property name='DisplayName' type='string' value='Gradient stop collection'/>
|
|
</Property>
|
|
<Property name='Center1' type='vector2'>
|
|
<Property name='DisplayName' type='string' value='Inner circle center'/>
|
|
</Property>
|
|
<Property name='Center2' type='vector2'>
|
|
<Property name='DisplayName' type='string' value='Outer circle center'/>
|
|
</Property>
|
|
<Property name='Radius1' type='float'>
|
|
<Property name='DisplayName' type='string' value='Inner circle radius'/>
|
|
</Property>
|
|
<Property name='Radius2' type='float'>
|
|
<Property name='DisplayName' type='string' value='Outer circle radius'/>
|
|
</Property>
|
|
<Property name='Transform' type='matrix3x2'>
|
|
<Property name='DisplayName' type='string' value='Transform applied to the pattern'/>
|
|
</Property>
|
|
|
|
</Effect>
|
|
);
|
|
|
|
// {FB947CDA-718E-40CC-AE7B-D255830D7D14}
|
|
static const GUID GUID_SampleRadialGradientPS =
|
|
{0xfb947cda, 0x718e, 0x40cc, {0xae, 0x7b, 0xd2, 0x55, 0x83, 0xd, 0x7d, 0x14}};
|
|
// {2C468128-6546-453C-8E25-F2DF0DE10A0F}
|
|
static const GUID GUID_SampleRadialGradientA0PS =
|
|
{0x2c468128, 0x6546, 0x453c, {0x8e, 0x25, 0xf2, 0xdf, 0xd, 0xe1, 0xa, 0xf}};
|
|
|
|
namespace mozilla {
|
|
namespace gfx {
|
|
|
|
RadialGradientEffectD2D1::RadialGradientEffectD2D1()
|
|
: mRefCount(0)
|
|
, mCenter1(D2D1::Vector2F(0, 0))
|
|
, mCenter2(D2D1::Vector2F(0, 0))
|
|
, mRadius1(0)
|
|
, mRadius2(0)
|
|
, mTransform(D2D1::IdentityMatrix())
|
|
|
|
{
|
|
}
|
|
|
|
IFACEMETHODIMP
|
|
RadialGradientEffectD2D1::Initialize(ID2D1EffectContext* pContextInternal, ID2D1TransformGraph* pTransformGraph)
|
|
{
|
|
HRESULT hr;
|
|
|
|
hr = pContextInternal->LoadPixelShader(GUID_SampleRadialGradientPS, SampleRadialGradientPS, sizeof(SampleRadialGradientPS));
|
|
|
|
if (FAILED(hr)) {
|
|
return hr;
|
|
}
|
|
|
|
hr = pContextInternal->LoadPixelShader(GUID_SampleRadialGradientA0PS, SampleRadialGradientA0PS, sizeof(SampleRadialGradientA0PS));
|
|
|
|
if (FAILED(hr)) {
|
|
return hr;
|
|
}
|
|
|
|
hr = pTransformGraph->SetSingleTransformNode(this);
|
|
|
|
if (FAILED(hr)) {
|
|
return hr;
|
|
}
|
|
|
|
mEffectContext = pContextInternal;
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
IFACEMETHODIMP
|
|
RadialGradientEffectD2D1::PrepareForRender(D2D1_CHANGE_TYPE changeType)
|
|
{
|
|
if (changeType == D2D1_CHANGE_TYPE_NONE) {
|
|
return S_OK;
|
|
}
|
|
|
|
// We'll need to inverse transform our pixel, precompute inverse here.
|
|
Matrix mat = ToMatrix(mTransform);
|
|
if (!mat.Invert()) {
|
|
// Singular
|
|
return S_OK;
|
|
}
|
|
|
|
if (!mStopCollection) {
|
|
return S_OK;
|
|
}
|
|
|
|
D2D1_POINT_2F dc = D2D1::Point2F(mCenter2.x - mCenter1.x, mCenter2.y - mCenter1.y);
|
|
float dr = mRadius2 - mRadius1;
|
|
float A = dc.x * dc.x + dc.y * dc.y - dr * dr;
|
|
|
|
HRESULT hr;
|
|
|
|
if (A == 0) {
|
|
hr = mDrawInfo->SetPixelShader(GUID_SampleRadialGradientA0PS);
|
|
} else {
|
|
hr = mDrawInfo->SetPixelShader(GUID_SampleRadialGradientPS);
|
|
}
|
|
|
|
if (FAILED(hr)) {
|
|
return hr;
|
|
}
|
|
|
|
RefPtr<ID2D1ResourceTexture> tex = CreateGradientTexture();
|
|
hr = mDrawInfo->SetResourceTexture(1, tex);
|
|
|
|
if (FAILED(hr)) {
|
|
return hr;
|
|
}
|
|
|
|
struct PSConstantBuffer
|
|
{
|
|
float diff[3];
|
|
float padding;
|
|
float center1[2];
|
|
float A;
|
|
float radius1;
|
|
float sq_radius1;
|
|
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,
|
|
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));
|
|
|
|
if (FAILED(hr)) {
|
|
return hr;
|
|
}
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
IFACEMETHODIMP
|
|
RadialGradientEffectD2D1::SetGraph(ID2D1TransformGraph* pGraph)
|
|
{
|
|
return pGraph->SetSingleTransformNode(this);
|
|
}
|
|
|
|
IFACEMETHODIMP_(ULONG)
|
|
RadialGradientEffectD2D1::AddRef()
|
|
{
|
|
return ++mRefCount;
|
|
}
|
|
|
|
IFACEMETHODIMP_(ULONG)
|
|
RadialGradientEffectD2D1::Release()
|
|
{
|
|
if (!--mRefCount) {
|
|
delete this;
|
|
return 0;
|
|
}
|
|
return mRefCount;
|
|
}
|
|
|
|
IFACEMETHODIMP
|
|
RadialGradientEffectD2D1::QueryInterface(const IID &aIID, void **aPtr)
|
|
{
|
|
if (!aPtr) {
|
|
return E_POINTER;
|
|
}
|
|
|
|
if (aIID == IID_IUnknown) {
|
|
*aPtr = static_cast<IUnknown*>(static_cast<ID2D1EffectImpl*>(this));
|
|
} else if (aIID == IID_ID2D1EffectImpl) {
|
|
*aPtr = static_cast<ID2D1EffectImpl*>(this);
|
|
} else if (aIID == IID_ID2D1DrawTransform) {
|
|
*aPtr = static_cast<ID2D1DrawTransform*>(this);
|
|
} else if (aIID == IID_ID2D1Transform) {
|
|
*aPtr = static_cast<ID2D1Transform*>(this);
|
|
} else if (aIID == IID_ID2D1TransformNode) {
|
|
*aPtr = static_cast<ID2D1TransformNode*>(this);
|
|
} else {
|
|
return E_NOINTERFACE;
|
|
}
|
|
|
|
static_cast<IUnknown*>(*aPtr)->AddRef();
|
|
return S_OK;
|
|
}
|
|
|
|
IFACEMETHODIMP
|
|
RadialGradientEffectD2D1::MapInputRectsToOutputRect(const D2D1_RECT_L* pInputRects,
|
|
const D2D1_RECT_L* pInputOpaqueSubRects,
|
|
UINT32 inputRectCount,
|
|
D2D1_RECT_L* pOutputRect,
|
|
D2D1_RECT_L* pOutputOpaqueSubRect)
|
|
{
|
|
if (inputRectCount != 1) {
|
|
return E_INVALIDARG;
|
|
}
|
|
|
|
*pOutputRect = *pInputRects;
|
|
*pOutputOpaqueSubRect = *pInputOpaqueSubRects;
|
|
return S_OK;
|
|
}
|
|
|
|
IFACEMETHODIMP
|
|
RadialGradientEffectD2D1::MapOutputRectToInputRects(const D2D1_RECT_L* pOutputRect,
|
|
D2D1_RECT_L* pInputRects,
|
|
UINT32 inputRectCount) const
|
|
{
|
|
if (inputRectCount != 1) {
|
|
return E_INVALIDARG;
|
|
}
|
|
|
|
*pInputRects = *pOutputRect;
|
|
return S_OK;
|
|
}
|
|
|
|
IFACEMETHODIMP
|
|
RadialGradientEffectD2D1::MapInvalidRect(UINT32 inputIndex,
|
|
D2D1_RECT_L invalidInputRect,
|
|
D2D1_RECT_L* pInvalidOutputRect) const
|
|
{
|
|
MOZ_ASSERT(inputIndex == 0);
|
|
|
|
*pInvalidOutputRect = invalidInputRect;
|
|
return S_OK;
|
|
}
|
|
|
|
IFACEMETHODIMP
|
|
RadialGradientEffectD2D1::SetDrawInfo(ID2D1DrawInfo *pDrawInfo)
|
|
{
|
|
mDrawInfo = pDrawInfo;
|
|
return S_OK;
|
|
}
|
|
|
|
HRESULT
|
|
RadialGradientEffectD2D1::Register(ID2D1Factory1 *aFactory)
|
|
{
|
|
D2D1_PROPERTY_BINDING bindings[] = {
|
|
D2D1_VALUE_TYPE_BINDING(L"StopCollection", &RadialGradientEffectD2D1::SetStopCollection,
|
|
&RadialGradientEffectD2D1::GetStopCollection),
|
|
D2D1_VALUE_TYPE_BINDING(L"Center1", &RadialGradientEffectD2D1::SetCenter1, &RadialGradientEffectD2D1::GetCenter1),
|
|
D2D1_VALUE_TYPE_BINDING(L"Center2", &RadialGradientEffectD2D1::SetCenter2, &RadialGradientEffectD2D1::GetCenter2),
|
|
D2D1_VALUE_TYPE_BINDING(L"Radius1", &RadialGradientEffectD2D1::SetRadius1, &RadialGradientEffectD2D1::GetRadius1),
|
|
D2D1_VALUE_TYPE_BINDING(L"Radius2", &RadialGradientEffectD2D1::SetRadius2, &RadialGradientEffectD2D1::GetRadius2),
|
|
D2D1_VALUE_TYPE_BINDING(L"Transform", &RadialGradientEffectD2D1::SetTransform, &RadialGradientEffectD2D1::GetTransform)
|
|
};
|
|
HRESULT hr = aFactory->RegisterEffectFromString(CLSID_RadialGradientEffect, kXmlDescription, bindings, ARRAYSIZE(bindings), CreateEffect);
|
|
|
|
if (FAILED(hr)) {
|
|
gfxWarning() << "Failed to register radial gradient effect.";
|
|
}
|
|
return hr;
|
|
}
|
|
|
|
void
|
|
RadialGradientEffectD2D1::Unregister(ID2D1Factory1 *aFactory)
|
|
{
|
|
aFactory->UnregisterEffect(CLSID_RadialGradientEffect);
|
|
}
|
|
|
|
HRESULT __stdcall
|
|
RadialGradientEffectD2D1::CreateEffect(IUnknown **aEffectImpl)
|
|
{
|
|
*aEffectImpl = static_cast<ID2D1EffectImpl*>(new RadialGradientEffectD2D1());
|
|
(*aEffectImpl)->AddRef();
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
HRESULT
|
|
RadialGradientEffectD2D1::SetStopCollection(IUnknown *aStopCollection)
|
|
{
|
|
if (SUCCEEDED(aStopCollection->QueryInterface((ID2D1GradientStopCollection**)getter_AddRefs(mStopCollection)))) {
|
|
return S_OK;
|
|
}
|
|
|
|
return E_INVALIDARG;
|
|
}
|
|
|
|
already_AddRefed<ID2D1ResourceTexture>
|
|
RadialGradientEffectD2D1::CreateGradientTexture()
|
|
{
|
|
std::vector<D2D1_GRADIENT_STOP> rawStops;
|
|
rawStops.resize(mStopCollection->GetGradientStopCount());
|
|
mStopCollection->GetGradientStops(&rawStops.front(), rawStops.size());
|
|
|
|
std::vector<unsigned char> textureData;
|
|
textureData.resize(4096 * 4);
|
|
unsigned char *texData = &textureData.front();
|
|
|
|
float prevColorPos = 0;
|
|
float nextColorPos = 1.0f;
|
|
D2D1_COLOR_F prevColor = rawStops[0].color;
|
|
D2D1_COLOR_F nextColor = prevColor;
|
|
|
|
if (rawStops.size() >= 2) {
|
|
nextColor = rawStops[1].color;
|
|
nextColorPos = rawStops[1].position;
|
|
}
|
|
|
|
uint32_t stopPosition = 2;
|
|
|
|
// Not the most optimized way but this will do for now.
|
|
for (int i = 0; i < 4096; i++) {
|
|
// The 4095 seems a little counter intuitive, but we want the gradient
|
|
// color at offset 0 at the first pixel, and at offset 1.0f at the last
|
|
// pixel.
|
|
float pos = float(i) / 4095;
|
|
|
|
while (pos > nextColorPos) {
|
|
prevColor = nextColor;
|
|
prevColorPos = nextColorPos;
|
|
if (rawStops.size() > stopPosition) {
|
|
nextColor = rawStops[stopPosition].color;
|
|
nextColorPos = rawStops[stopPosition++].position;
|
|
} else {
|
|
nextColorPos = 1.0f;
|
|
}
|
|
}
|
|
|
|
float interp;
|
|
|
|
if (nextColorPos != prevColorPos) {
|
|
interp = (pos - prevColorPos) / (nextColorPos - prevColorPos);
|
|
} else {
|
|
interp = 0;
|
|
}
|
|
|
|
Color newColor(prevColor.r + (nextColor.r - prevColor.r) * interp,
|
|
prevColor.g + (nextColor.g - prevColor.g) * interp,
|
|
prevColor.b + (nextColor.b - prevColor.b) * interp,
|
|
prevColor.a + (nextColor.a - prevColor.a) * interp);
|
|
|
|
// Note D2D expects RGBA here!!
|
|
texData[i * 4] = (char)(255.0f * newColor.r);
|
|
texData[i * 4 + 1] = (char)(255.0f * newColor.g);
|
|
texData[i * 4 + 2] = (char)(255.0f * newColor.b);
|
|
texData[i * 4 + 3] = (char)(255.0f * newColor.a);
|
|
}
|
|
|
|
RefPtr<ID2D1ResourceTexture> tex;
|
|
|
|
UINT32 width = 4096;
|
|
UINT32 stride = 4096 * 4;
|
|
D2D1_RESOURCE_TEXTURE_PROPERTIES props;
|
|
// 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(), mStopCollection->GetExtendMode() };
|
|
props.extendModes = extendMode;
|
|
|
|
HRESULT hr = mEffectContext->CreateResourceTexture(nullptr, &props, &textureData.front(), &stride, 4096 * 4, getter_AddRefs(tex));
|
|
|
|
if (FAILED(hr)) {
|
|
gfxWarning() << "Failed to create resource texture: " << hexa(hr);
|
|
}
|
|
|
|
return tex.forget();
|
|
}
|
|
|
|
}
|
|
}
|