2013-11-27 03:25:16 -08:00
|
|
|
/* -*- 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 "FilterNodeD2D1.h"
|
|
|
|
|
|
|
|
#include "Logging.h"
|
|
|
|
|
|
|
|
#include "SourceSurfaceD2D1.h"
|
|
|
|
#include "SourceSurfaceD2D.h"
|
|
|
|
#include "SourceSurfaceD2DTarget.h"
|
|
|
|
#include "DrawTargetD2D.h"
|
|
|
|
#include "DrawTargetD2D1.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
D2D1_COLORMATRIX_ALPHA_MODE D2DAlphaMode(uint32_t aMode)
|
|
|
|
{
|
|
|
|
switch (aMode) {
|
|
|
|
case ALPHA_MODE_PREMULTIPLIED:
|
|
|
|
return D2D1_COLORMATRIX_ALPHA_MODE_PREMULTIPLIED;
|
|
|
|
case ALPHA_MODE_STRAIGHT:
|
|
|
|
return D2D1_COLORMATRIX_ALPHA_MODE_STRAIGHT;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown enum value!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return D2D1_COLORMATRIX_ALPHA_MODE_PREMULTIPLIED;
|
|
|
|
}
|
|
|
|
|
2014-02-11 04:44:17 -08:00
|
|
|
D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE D2DAffineTransformInterpolationMode(Filter aFilter)
|
2013-11-27 03:25:27 -08:00
|
|
|
{
|
|
|
|
switch (aFilter) {
|
2014-01-10 11:06:17 -08:00
|
|
|
case Filter::GOOD:
|
2013-11-27 03:25:27 -08:00
|
|
|
return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR;
|
2014-01-10 11:06:17 -08:00
|
|
|
case Filter::LINEAR:
|
2013-11-27 03:25:27 -08:00
|
|
|
return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR;
|
2014-01-10 11:06:17 -08:00
|
|
|
case Filter::POINT:
|
2013-11-27 03:25:27 -08:00
|
|
|
return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_NEAREST_NEIGHBOR;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown enum value!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return D2D1_2DAFFINETRANSFORM_INTERPOLATION_MODE_LINEAR;
|
|
|
|
}
|
|
|
|
|
2013-11-27 03:25:16 -08:00
|
|
|
D2D1_BLEND_MODE D2DBlendMode(uint32_t aMode)
|
|
|
|
{
|
|
|
|
switch (aMode) {
|
|
|
|
case BLEND_MODE_DARKEN:
|
|
|
|
return D2D1_BLEND_MODE_DARKEN;
|
|
|
|
case BLEND_MODE_LIGHTEN:
|
|
|
|
return D2D1_BLEND_MODE_LIGHTEN;
|
|
|
|
case BLEND_MODE_MULTIPLY:
|
|
|
|
return D2D1_BLEND_MODE_MULTIPLY;
|
|
|
|
case BLEND_MODE_SCREEN:
|
|
|
|
return D2D1_BLEND_MODE_SCREEN;
|
2014-09-12 07:32:00 -07:00
|
|
|
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;
|
|
|
|
|
2013-11-27 03:25:16 -08:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown enum value!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return D2D1_BLEND_MODE_DARKEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
D2D1_MORPHOLOGY_MODE D2DMorphologyMode(uint32_t aMode)
|
|
|
|
{
|
|
|
|
switch (aMode) {
|
|
|
|
case MORPHOLOGY_OPERATOR_DILATE:
|
|
|
|
return D2D1_MORPHOLOGY_MODE_DILATE;
|
|
|
|
case MORPHOLOGY_OPERATOR_ERODE:
|
|
|
|
return D2D1_MORPHOLOGY_MODE_ERODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Unknown enum value!");
|
|
|
|
return D2D1_MORPHOLOGY_MODE_DILATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
D2D1_TURBULENCE_NOISE D2DTurbulenceNoise(uint32_t aMode)
|
|
|
|
{
|
|
|
|
switch (aMode) {
|
|
|
|
case TURBULENCE_TYPE_FRACTAL_NOISE:
|
|
|
|
return D2D1_TURBULENCE_NOISE_FRACTAL_SUM;
|
|
|
|
case TURBULENCE_TYPE_TURBULENCE:
|
|
|
|
return D2D1_TURBULENCE_NOISE_TURBULENCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Unknown enum value!");
|
|
|
|
return D2D1_TURBULENCE_NOISE_TURBULENCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
D2D1_COMPOSITE_MODE D2DFilterCompositionMode(uint32_t aMode)
|
|
|
|
{
|
|
|
|
switch (aMode) {
|
|
|
|
case COMPOSITE_OPERATOR_OVER:
|
|
|
|
return D2D1_COMPOSITE_MODE_SOURCE_OVER;
|
|
|
|
case COMPOSITE_OPERATOR_IN:
|
|
|
|
return D2D1_COMPOSITE_MODE_SOURCE_IN;
|
|
|
|
case COMPOSITE_OPERATOR_OUT:
|
|
|
|
return D2D1_COMPOSITE_MODE_SOURCE_OUT;
|
|
|
|
case COMPOSITE_OPERATOR_ATOP:
|
|
|
|
return D2D1_COMPOSITE_MODE_SOURCE_ATOP;
|
|
|
|
case COMPOSITE_OPERATOR_XOR:
|
|
|
|
return D2D1_COMPOSITE_MODE_XOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Unknown enum value!");
|
|
|
|
return D2D1_COMPOSITE_MODE_SOURCE_OVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
D2D1_CHANNEL_SELECTOR D2DChannelSelector(uint32_t aMode)
|
|
|
|
{
|
|
|
|
switch (aMode) {
|
|
|
|
case COLOR_CHANNEL_R:
|
|
|
|
return D2D1_CHANNEL_SELECTOR_R;
|
|
|
|
case COLOR_CHANNEL_G:
|
|
|
|
return D2D1_CHANNEL_SELECTOR_G;
|
|
|
|
case COLOR_CHANNEL_B:
|
|
|
|
return D2D1_CHANNEL_SELECTOR_B;
|
|
|
|
case COLOR_CHANNEL_A:
|
|
|
|
return D2D1_CHANNEL_SELECTOR_A;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Unknown enum value!");
|
|
|
|
return D2D1_CHANNEL_SELECTOR_R;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<ID2D1Image> GetImageForSourceSurface(DrawTarget *aDT, SourceSurface *aSurface)
|
|
|
|
{
|
2014-08-06 05:40:03 -07:00
|
|
|
if (aDT->IsTiledDrawTarget() || aDT->IsDualDrawTarget()) {
|
|
|
|
MOZ_CRASH("Incompatible draw target type!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-19 13:35:33 -07:00
|
|
|
switch (aDT->GetBackendType()) {
|
2014-04-15 15:45:11 -07:00
|
|
|
case BackendType::DIRECT2D1_1:
|
|
|
|
return static_cast<DrawTargetD2D1*>(aDT)->GetImageForSurface(aSurface, ExtendMode::CLAMP);
|
|
|
|
case BackendType::DIRECT2D:
|
|
|
|
return static_cast<DrawTargetD2D*>(aDT)->GetImageForSurface(aSurface);
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown draw target type!");
|
|
|
|
return nullptr;
|
2013-11-27 03:25:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-11 22:26:20 -08:00
|
|
|
uint32_t ConvertValue(FilterType aType, uint32_t aAttribute, uint32_t aValue)
|
2013-11-27 03:25:16 -08:00
|
|
|
{
|
|
|
|
switch (aType) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::COLOR_MATRIX:
|
2013-11-27 03:25:16 -08:00
|
|
|
if (aAttribute == ATT_COLOR_MATRIX_ALPHA_MODE) {
|
|
|
|
aValue = D2DAlphaMode(aValue);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TRANSFORM:
|
2013-11-27 03:25:27 -08:00
|
|
|
if (aAttribute == ATT_TRANSFORM_FILTER) {
|
2014-02-11 04:44:17 -08:00
|
|
|
aValue = D2DAffineTransformInterpolationMode(Filter(aValue));
|
2013-11-27 03:25:27 -08:00
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::BLEND:
|
2013-11-27 03:25:16 -08:00
|
|
|
if (aAttribute == ATT_BLEND_BLENDMODE) {
|
|
|
|
aValue = D2DBlendMode(aValue);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::MORPHOLOGY:
|
2013-11-27 03:25:16 -08:00
|
|
|
if (aAttribute == ATT_MORPHOLOGY_OPERATOR) {
|
|
|
|
aValue = D2DMorphologyMode(aValue);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISPLACEMENT_MAP:
|
2013-11-27 03:25:16 -08:00
|
|
|
if (aAttribute == ATT_DISPLACEMENT_MAP_X_CHANNEL ||
|
|
|
|
aAttribute == ATT_DISPLACEMENT_MAP_Y_CHANNEL) {
|
|
|
|
aValue = D2DChannelSelector(aValue);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TURBULENCE:
|
2013-11-27 03:25:16 -08:00
|
|
|
if (aAttribute == ATT_TURBULENCE_TYPE) {
|
|
|
|
aValue = D2DTurbulenceNoise(aValue);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::COMPOSITE:
|
2013-11-27 03:25:16 -08:00
|
|
|
if (aAttribute == ATT_COMPOSITE_OPERATOR) {
|
|
|
|
aValue = D2DFilterCompositionMode(aValue);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aValue;
|
|
|
|
}
|
|
|
|
|
2014-01-11 22:26:20 -08:00
|
|
|
void ConvertValue(FilterType aType, uint32_t aAttribute, IntSize &aValue)
|
2013-11-27 03:25:16 -08:00
|
|
|
{
|
|
|
|
switch (aType) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::MORPHOLOGY:
|
2013-11-27 03:25:16 -08:00
|
|
|
if (aAttribute == ATT_MORPHOLOGY_RADII) {
|
|
|
|
aValue.width *= 2;
|
|
|
|
aValue.width += 1;
|
|
|
|
aValue.height *= 2;
|
|
|
|
aValue.height += 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32
|
2014-01-11 22:26:20 -08:00
|
|
|
GetD2D1InputForInput(FilterType aType, uint32_t aIndex)
|
2013-11-27 03:25:16 -08:00
|
|
|
{
|
|
|
|
return aIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONVERT_PROP(moz2dname, d2dname) \
|
|
|
|
case ATT_##moz2dname: \
|
|
|
|
return D2D1_##d2dname
|
|
|
|
|
|
|
|
UINT32
|
2014-01-11 22:26:20 -08:00
|
|
|
GetD2D1PropForAttribute(FilterType aType, uint32_t aIndex)
|
2013-11-27 03:25:16 -08:00
|
|
|
{
|
|
|
|
switch (aType) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::COLOR_MATRIX:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(COLOR_MATRIX_MATRIX, COLORMATRIX_PROP_COLOR_MATRIX);
|
|
|
|
CONVERT_PROP(COLOR_MATRIX_ALPHA_MODE, COLORMATRIX_PROP_ALPHA_MODE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TRANSFORM:
|
2013-11-27 03:25:27 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(TRANSFORM_MATRIX, 2DAFFINETRANSFORM_PROP_TRANSFORM_MATRIX);
|
|
|
|
CONVERT_PROP(TRANSFORM_FILTER, 2DAFFINETRANSFORM_PROP_INTERPOLATION_MODE);
|
|
|
|
}
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::BLEND:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(BLEND_BLENDMODE, BLEND_PROP_MODE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::MORPHOLOGY:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(MORPHOLOGY_OPERATOR, MORPHOLOGY_PROP_MODE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::FLOOD:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(FLOOD_COLOR, FLOOD_PROP_COLOR);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TILE:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(TILE_SOURCE_RECT, TILE_PROP_RECT);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TABLE_TRANSFER:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(TABLE_TRANSFER_DISABLE_R, TABLETRANSFER_PROP_RED_DISABLE);
|
|
|
|
CONVERT_PROP(TABLE_TRANSFER_DISABLE_G, TABLETRANSFER_PROP_GREEN_DISABLE);
|
|
|
|
CONVERT_PROP(TABLE_TRANSFER_DISABLE_B, TABLETRANSFER_PROP_BLUE_DISABLE);
|
|
|
|
CONVERT_PROP(TABLE_TRANSFER_DISABLE_A, TABLETRANSFER_PROP_ALPHA_DISABLE);
|
|
|
|
CONVERT_PROP(TABLE_TRANSFER_TABLE_R, TABLETRANSFER_PROP_RED_TABLE);
|
|
|
|
CONVERT_PROP(TABLE_TRANSFER_TABLE_G, TABLETRANSFER_PROP_GREEN_TABLE);
|
|
|
|
CONVERT_PROP(TABLE_TRANSFER_TABLE_B, TABLETRANSFER_PROP_BLUE_TABLE);
|
|
|
|
CONVERT_PROP(TABLE_TRANSFER_TABLE_A, TABLETRANSFER_PROP_ALPHA_TABLE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISCRETE_TRANSFER:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(DISCRETE_TRANSFER_DISABLE_R, DISCRETETRANSFER_PROP_RED_DISABLE);
|
|
|
|
CONVERT_PROP(DISCRETE_TRANSFER_DISABLE_G, DISCRETETRANSFER_PROP_GREEN_DISABLE);
|
|
|
|
CONVERT_PROP(DISCRETE_TRANSFER_DISABLE_B, DISCRETETRANSFER_PROP_BLUE_DISABLE);
|
|
|
|
CONVERT_PROP(DISCRETE_TRANSFER_DISABLE_A, DISCRETETRANSFER_PROP_ALPHA_DISABLE);
|
|
|
|
CONVERT_PROP(DISCRETE_TRANSFER_TABLE_R, DISCRETETRANSFER_PROP_RED_TABLE);
|
|
|
|
CONVERT_PROP(DISCRETE_TRANSFER_TABLE_G, DISCRETETRANSFER_PROP_GREEN_TABLE);
|
|
|
|
CONVERT_PROP(DISCRETE_TRANSFER_TABLE_B, DISCRETETRANSFER_PROP_BLUE_TABLE);
|
|
|
|
CONVERT_PROP(DISCRETE_TRANSFER_TABLE_A, DISCRETETRANSFER_PROP_ALPHA_TABLE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::LINEAR_TRANSFER:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_DISABLE_R, LINEARTRANSFER_PROP_RED_DISABLE);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_DISABLE_G, LINEARTRANSFER_PROP_GREEN_DISABLE);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_DISABLE_B, LINEARTRANSFER_PROP_BLUE_DISABLE);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_DISABLE_A, LINEARTRANSFER_PROP_ALPHA_DISABLE);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_INTERCEPT_R, LINEARTRANSFER_PROP_RED_Y_INTERCEPT);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_INTERCEPT_G, LINEARTRANSFER_PROP_GREEN_Y_INTERCEPT);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_INTERCEPT_B, LINEARTRANSFER_PROP_BLUE_Y_INTERCEPT);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_INTERCEPT_A, LINEARTRANSFER_PROP_ALPHA_Y_INTERCEPT);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_SLOPE_R, LINEARTRANSFER_PROP_RED_SLOPE);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_SLOPE_G, LINEARTRANSFER_PROP_GREEN_SLOPE);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_SLOPE_B, LINEARTRANSFER_PROP_BLUE_SLOPE);
|
|
|
|
CONVERT_PROP(LINEAR_TRANSFER_SLOPE_A, LINEARTRANSFER_PROP_ALPHA_SLOPE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::GAMMA_TRANSFER:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_DISABLE_R, GAMMATRANSFER_PROP_RED_DISABLE);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_DISABLE_G, GAMMATRANSFER_PROP_GREEN_DISABLE);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_DISABLE_B, GAMMATRANSFER_PROP_BLUE_DISABLE);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_DISABLE_A, GAMMATRANSFER_PROP_ALPHA_DISABLE);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_AMPLITUDE_R, GAMMATRANSFER_PROP_RED_AMPLITUDE);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_AMPLITUDE_G, GAMMATRANSFER_PROP_GREEN_AMPLITUDE);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_AMPLITUDE_B, GAMMATRANSFER_PROP_BLUE_AMPLITUDE);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_AMPLITUDE_A, GAMMATRANSFER_PROP_ALPHA_AMPLITUDE);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_EXPONENT_R, GAMMATRANSFER_PROP_RED_EXPONENT);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_EXPONENT_G, GAMMATRANSFER_PROP_GREEN_EXPONENT);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_EXPONENT_B, GAMMATRANSFER_PROP_BLUE_EXPONENT);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_EXPONENT_A, GAMMATRANSFER_PROP_ALPHA_EXPONENT);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_OFFSET_R, GAMMATRANSFER_PROP_RED_OFFSET);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_OFFSET_G, GAMMATRANSFER_PROP_GREEN_OFFSET);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_OFFSET_B, GAMMATRANSFER_PROP_BLUE_OFFSET);
|
|
|
|
CONVERT_PROP(GAMMA_TRANSFER_OFFSET_A, GAMMATRANSFER_PROP_ALPHA_OFFSET);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::CONVOLVE_MATRIX:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(CONVOLVE_MATRIX_BIAS, CONVOLVEMATRIX_PROP_BIAS);
|
|
|
|
CONVERT_PROP(CONVOLVE_MATRIX_KERNEL_MATRIX, CONVOLVEMATRIX_PROP_KERNEL_MATRIX);
|
|
|
|
CONVERT_PROP(CONVOLVE_MATRIX_DIVISOR, CONVOLVEMATRIX_PROP_DIVISOR);
|
|
|
|
CONVERT_PROP(CONVOLVE_MATRIX_KERNEL_UNIT_LENGTH, CONVOLVEMATRIX_PROP_KERNEL_UNIT_LENGTH);
|
|
|
|
CONVERT_PROP(CONVOLVE_MATRIX_PRESERVE_ALPHA, CONVOLVEMATRIX_PROP_PRESERVE_ALPHA);
|
|
|
|
}
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISPLACEMENT_MAP:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(DISPLACEMENT_MAP_SCALE, DISPLACEMENTMAP_PROP_SCALE);
|
|
|
|
CONVERT_PROP(DISPLACEMENT_MAP_X_CHANNEL, DISPLACEMENTMAP_PROP_X_CHANNEL_SELECT);
|
|
|
|
CONVERT_PROP(DISPLACEMENT_MAP_Y_CHANNEL, DISPLACEMENTMAP_PROP_Y_CHANNEL_SELECT);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TURBULENCE:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(TURBULENCE_BASE_FREQUENCY, TURBULENCE_PROP_BASE_FREQUENCY);
|
|
|
|
CONVERT_PROP(TURBULENCE_NUM_OCTAVES, TURBULENCE_PROP_NUM_OCTAVES);
|
|
|
|
CONVERT_PROP(TURBULENCE_SEED, TURBULENCE_PROP_SEED);
|
|
|
|
CONVERT_PROP(TURBULENCE_STITCHABLE, TURBULENCE_PROP_STITCHABLE);
|
|
|
|
CONVERT_PROP(TURBULENCE_TYPE, TURBULENCE_PROP_NOISE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::ARITHMETIC_COMBINE:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(ARITHMETIC_COMBINE_COEFFICIENTS, ARITHMETICCOMPOSITE_PROP_COEFFICIENTS);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::COMPOSITE:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(COMPOSITE_OPERATOR, COMPOSITE_PROP_MODE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::GAUSSIAN_BLUR:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(GAUSSIAN_BLUR_STD_DEVIATION, GAUSSIANBLUR_PROP_STANDARD_DEVIATION);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DIRECTIONAL_BLUR:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(DIRECTIONAL_BLUR_STD_DEVIATION, DIRECTIONALBLUR_PROP_STANDARD_DEVIATION);
|
|
|
|
CONVERT_PROP(DIRECTIONAL_BLUR_DIRECTION, DIRECTIONALBLUR_PROP_ANGLE);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::POINT_DIFFUSE:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(POINT_DIFFUSE_DIFFUSE_CONSTANT, POINTDIFFUSE_PROP_DIFFUSE_CONSTANT);
|
|
|
|
CONVERT_PROP(POINT_DIFFUSE_POSITION, POINTDIFFUSE_PROP_LIGHT_POSITION);
|
|
|
|
CONVERT_PROP(POINT_DIFFUSE_COLOR, POINTDIFFUSE_PROP_COLOR);
|
|
|
|
CONVERT_PROP(POINT_DIFFUSE_SURFACE_SCALE, POINTDIFFUSE_PROP_SURFACE_SCALE);
|
|
|
|
CONVERT_PROP(POINT_DIFFUSE_KERNEL_UNIT_LENGTH, POINTDIFFUSE_PROP_KERNEL_UNIT_LENGTH);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::SPOT_DIFFUSE:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(SPOT_DIFFUSE_DIFFUSE_CONSTANT, SPOTDIFFUSE_PROP_DIFFUSE_CONSTANT);
|
|
|
|
CONVERT_PROP(SPOT_DIFFUSE_POINTS_AT, SPOTDIFFUSE_PROP_POINTS_AT);
|
|
|
|
CONVERT_PROP(SPOT_DIFFUSE_FOCUS, SPOTDIFFUSE_PROP_FOCUS);
|
|
|
|
CONVERT_PROP(SPOT_DIFFUSE_LIMITING_CONE_ANGLE, SPOTDIFFUSE_PROP_LIMITING_CONE_ANGLE);
|
|
|
|
CONVERT_PROP(SPOT_DIFFUSE_POSITION, SPOTDIFFUSE_PROP_LIGHT_POSITION);
|
|
|
|
CONVERT_PROP(SPOT_DIFFUSE_COLOR, SPOTDIFFUSE_PROP_COLOR);
|
|
|
|
CONVERT_PROP(SPOT_DIFFUSE_SURFACE_SCALE, SPOTDIFFUSE_PROP_SURFACE_SCALE);
|
|
|
|
CONVERT_PROP(SPOT_DIFFUSE_KERNEL_UNIT_LENGTH, SPOTDIFFUSE_PROP_KERNEL_UNIT_LENGTH);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISTANT_DIFFUSE:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(DISTANT_DIFFUSE_DIFFUSE_CONSTANT, DISTANTDIFFUSE_PROP_DIFFUSE_CONSTANT);
|
|
|
|
CONVERT_PROP(DISTANT_DIFFUSE_AZIMUTH, DISTANTDIFFUSE_PROP_AZIMUTH);
|
|
|
|
CONVERT_PROP(DISTANT_DIFFUSE_ELEVATION, DISTANTDIFFUSE_PROP_ELEVATION);
|
|
|
|
CONVERT_PROP(DISTANT_DIFFUSE_COLOR, DISTANTDIFFUSE_PROP_COLOR);
|
|
|
|
CONVERT_PROP(DISTANT_DIFFUSE_SURFACE_SCALE, DISTANTDIFFUSE_PROP_SURFACE_SCALE);
|
|
|
|
CONVERT_PROP(DISTANT_DIFFUSE_KERNEL_UNIT_LENGTH, DISTANTDIFFUSE_PROP_KERNEL_UNIT_LENGTH);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::POINT_SPECULAR:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(POINT_SPECULAR_SPECULAR_CONSTANT, POINTSPECULAR_PROP_SPECULAR_CONSTANT);
|
|
|
|
CONVERT_PROP(POINT_SPECULAR_SPECULAR_EXPONENT, POINTSPECULAR_PROP_SPECULAR_EXPONENT);
|
|
|
|
CONVERT_PROP(POINT_SPECULAR_POSITION, POINTSPECULAR_PROP_LIGHT_POSITION);
|
|
|
|
CONVERT_PROP(POINT_SPECULAR_COLOR, POINTSPECULAR_PROP_COLOR);
|
|
|
|
CONVERT_PROP(POINT_SPECULAR_SURFACE_SCALE, POINTSPECULAR_PROP_SURFACE_SCALE);
|
|
|
|
CONVERT_PROP(POINT_SPECULAR_KERNEL_UNIT_LENGTH, POINTSPECULAR_PROP_KERNEL_UNIT_LENGTH);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::SPOT_SPECULAR:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_SPECULAR_CONSTANT, SPOTSPECULAR_PROP_SPECULAR_CONSTANT);
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_SPECULAR_EXPONENT, SPOTSPECULAR_PROP_SPECULAR_EXPONENT);
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_POINTS_AT, SPOTSPECULAR_PROP_POINTS_AT);
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_FOCUS, SPOTSPECULAR_PROP_FOCUS);
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_LIMITING_CONE_ANGLE, SPOTSPECULAR_PROP_LIMITING_CONE_ANGLE);
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_POSITION, SPOTSPECULAR_PROP_LIGHT_POSITION);
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_COLOR, SPOTSPECULAR_PROP_COLOR);
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_SURFACE_SCALE, SPOTSPECULAR_PROP_SURFACE_SCALE);
|
|
|
|
CONVERT_PROP(SPOT_SPECULAR_KERNEL_UNIT_LENGTH, SPOTSPECULAR_PROP_KERNEL_UNIT_LENGTH);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISTANT_SPECULAR:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(DISTANT_SPECULAR_SPECULAR_CONSTANT, DISTANTSPECULAR_PROP_SPECULAR_CONSTANT);
|
|
|
|
CONVERT_PROP(DISTANT_SPECULAR_SPECULAR_EXPONENT, DISTANTSPECULAR_PROP_SPECULAR_EXPONENT);
|
|
|
|
CONVERT_PROP(DISTANT_SPECULAR_AZIMUTH, DISTANTSPECULAR_PROP_AZIMUTH);
|
|
|
|
CONVERT_PROP(DISTANT_SPECULAR_ELEVATION, DISTANTSPECULAR_PROP_ELEVATION);
|
|
|
|
CONVERT_PROP(DISTANT_SPECULAR_COLOR, DISTANTSPECULAR_PROP_COLOR);
|
|
|
|
CONVERT_PROP(DISTANT_SPECULAR_SURFACE_SCALE, DISTANTSPECULAR_PROP_SURFACE_SCALE);
|
|
|
|
CONVERT_PROP(DISTANT_SPECULAR_KERNEL_UNIT_LENGTH, DISTANTSPECULAR_PROP_KERNEL_UNIT_LENGTH);
|
|
|
|
}
|
|
|
|
break;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::CROP:
|
2013-11-27 03:25:16 -08:00
|
|
|
switch (aIndex) {
|
|
|
|
CONVERT_PROP(CROP_RECT, CROP_PROP_RECT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-01-11 22:26:20 -08:00
|
|
|
GetD2D1PropsForIntSize(FilterType aType, uint32_t aIndex, UINT32 *aPropWidth, UINT32 *aPropHeight)
|
2013-11-27 03:25:16 -08:00
|
|
|
{
|
|
|
|
switch (aType) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::MORPHOLOGY:
|
2013-11-27 03:25:16 -08:00
|
|
|
if (aIndex == ATT_MORPHOLOGY_RADII) {
|
|
|
|
*aPropWidth = D2D1_MORPHOLOGY_PROP_WIDTH;
|
|
|
|
*aPropHeight = D2D1_MORPHOLOGY_PROP_HEIGHT;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline REFCLSID GetCLDIDForFilterType(FilterType aType)
|
|
|
|
{
|
|
|
|
switch (aType) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::COLOR_MATRIX:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1ColorMatrix;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TRANSFORM:
|
2013-11-27 03:25:27 -08:00
|
|
|
return CLSID_D2D12DAffineTransform;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::BLEND:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1Blend;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::MORPHOLOGY:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1Morphology;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::FLOOD:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1Flood;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TILE:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1Tile;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TABLE_TRANSFER:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1TableTransfer;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::LINEAR_TRANSFER:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1LinearTransfer;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISCRETE_TRANSFER:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1DiscreteTransfer;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::GAMMA_TRANSFER:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1GammaTransfer;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISPLACEMENT_MAP:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1DisplacementMap;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TURBULENCE:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1Turbulence;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::ARITHMETIC_COMBINE:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1ArithmeticComposite;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::COMPOSITE:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1Composite;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::GAUSSIAN_BLUR:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1GaussianBlur;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DIRECTIONAL_BLUR:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1DirectionalBlur;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::POINT_DIFFUSE:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1PointDiffuse;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::POINT_SPECULAR:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1PointSpecular;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::SPOT_DIFFUSE:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1SpotDiffuse;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::SPOT_SPECULAR:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1SpotSpecular;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISTANT_DIFFUSE:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1DistantDiffuse;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::DISTANT_SPECULAR:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1DistantSpecular;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::CROP:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1Crop;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::PREMULTIPLY:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1Premultiply;
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::UNPREMULTIPLY:
|
2013-11-27 03:25:16 -08:00
|
|
|
return CLSID_D2D1UnPremultiply;
|
|
|
|
}
|
|
|
|
return GUID_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
TemporaryRef<FilterNode>
|
2014-09-25 12:18:29 -07:00
|
|
|
FilterNodeD2D1::Create(ID2D1DeviceContext *aDC, FilterType aType)
|
2013-11-27 03:25:16 -08:00
|
|
|
{
|
2014-01-10 11:06:16 -08:00
|
|
|
if (aType == FilterType::CONVOLVE_MATRIX) {
|
2014-09-25 12:18:29 -07:00
|
|
|
return new FilterNodeConvolveD2D1(aDC);
|
2013-11-27 03:25:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID2D1Effect> effect;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = aDC->CreateEffect(GetCLDIDForFilterType(aType), byRef(effect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2014-09-23 08:35:39 -07:00
|
|
|
gfxWarning() << "Failed to create effect for FilterType: " << hexa(hr);
|
2013-11-27 03:25:16 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aType) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::LINEAR_TRANSFER:
|
|
|
|
case FilterType::GAMMA_TRANSFER:
|
|
|
|
case FilterType::TABLE_TRANSFER:
|
|
|
|
case FilterType::DISCRETE_TRANSFER:
|
2014-09-25 12:18:29 -07:00
|
|
|
return new FilterNodeComponentTransferD2D1(aDC, effect, aType);
|
2013-11-27 03:25:16 -08:00
|
|
|
default:
|
2014-09-25 12:18:29 -07:00
|
|
|
return new FilterNodeD2D1(effect, aType);
|
2013-11-27 03:25:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 03:25:27 -08:00
|
|
|
void
|
|
|
|
FilterNodeD2D1::InitUnmappedProperties()
|
|
|
|
{
|
|
|
|
switch (mType) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::TRANSFORM:
|
2013-11-27 03:25:27 -08:00
|
|
|
mEffect->SetValue(D2D1_2DAFFINETRANSFORM_PROP_BORDER_MODE, D2D1_BORDER_MODE_HARD);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 03:25:16 -08:00
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetInput(uint32_t aIndex, SourceSurface *aSurface)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1InputForInput(mType, aIndex);
|
|
|
|
ID2D1Effect* effect = InputEffect();
|
|
|
|
MOZ_ASSERT(input < effect->GetInputCount());
|
|
|
|
|
2014-01-10 11:06:16 -08:00
|
|
|
if (mType == FilterType::COMPOSITE) {
|
2013-11-27 03:25:16 -08:00
|
|
|
UINT32 inputCount = effect->GetInputCount();
|
|
|
|
|
|
|
|
if (aIndex == inputCount - 1 && aSurface == nullptr) {
|
|
|
|
effect->SetInputCount(inputCount - 1);
|
|
|
|
} else if (aIndex >= inputCount && aSurface) {
|
|
|
|
effect->SetInputCount(aIndex + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
MOZ_ASSERT(input < effect->GetInputCount());
|
|
|
|
|
|
|
|
mInputSurfaces.resize(effect->GetInputCount());
|
|
|
|
mInputFilters.resize(effect->GetInputCount());
|
|
|
|
|
|
|
|
// In order to convert aSurface into an ID2D1Image, we need to know what
|
|
|
|
// DrawTarget we paint into. However, the same FilterNode object can be
|
|
|
|
// used on different DrawTargets, so we need to hold on to the SourceSurface
|
|
|
|
// objects and delay the conversion until we're actually painted and know
|
|
|
|
// our target DrawTarget.
|
|
|
|
// The conversion happens in WillDraw().
|
|
|
|
|
|
|
|
mInputSurfaces[input] = aSurface;
|
|
|
|
mInputFilters[input] = nullptr;
|
|
|
|
|
|
|
|
// Clear the existing image from the effect.
|
|
|
|
effect->SetInput(input, nullptr);
|
2013-11-27 03:25:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetInput(uint32_t aIndex, FilterNode *aFilter)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1InputForInput(mType, aIndex);
|
|
|
|
ID2D1Effect* effect = InputEffect();
|
|
|
|
|
2014-01-10 11:06:16 -08:00
|
|
|
if (mType == FilterType::COMPOSITE) {
|
2013-11-27 03:25:16 -08:00
|
|
|
UINT32 inputCount = effect->GetInputCount();
|
|
|
|
|
|
|
|
if (aIndex == inputCount - 1 && aFilter == nullptr) {
|
|
|
|
effect->SetInputCount(inputCount - 1);
|
|
|
|
} else if (aIndex >= inputCount && aFilter) {
|
|
|
|
effect->SetInputCount(aIndex + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
MOZ_ASSERT(input < effect->GetInputCount());
|
2013-11-27 03:25:16 -08:00
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
if (aFilter && aFilter->GetBackendType() != FILTER_BACKEND_DIRECT2D1_1) {
|
|
|
|
gfxWarning() << "Unknown input FilterNode set on effect.";
|
2013-11-27 03:25:16 -08:00
|
|
|
MOZ_ASSERT(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
FilterNodeD2D1* filter = static_cast<FilterNodeD2D1*>(aFilter);
|
|
|
|
|
|
|
|
mInputSurfaces.resize(effect->GetInputCount());
|
|
|
|
mInputFilters.resize(effect->GetInputCount());
|
|
|
|
|
|
|
|
// We hold on to the FilterNode object so that we can call WillDraw() on it.
|
|
|
|
mInputSurfaces[input] = nullptr;
|
|
|
|
mInputFilters[input] = filter;
|
|
|
|
|
|
|
|
if (filter) {
|
|
|
|
effect->SetInputEffect(input, filter->OutputEffect());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::WillDraw(DrawTarget *aDT)
|
|
|
|
{
|
|
|
|
// Convert input SourceSurfaces into ID2D1Images and set them on the effect.
|
|
|
|
for (size_t inputIndex = 0; inputIndex < mInputSurfaces.size(); inputIndex++) {
|
|
|
|
if (mInputSurfaces[inputIndex]) {
|
|
|
|
ID2D1Effect* effect = InputEffect();
|
|
|
|
RefPtr<ID2D1Image> image = GetImageForSourceSurface(aDT, mInputSurfaces[inputIndex]);
|
|
|
|
effect->SetInput(inputIndex, image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call WillDraw() on our input filters.
|
|
|
|
for (std::vector<RefPtr<FilterNodeD2D1>>::iterator it = mInputFilters.begin();
|
|
|
|
it != mInputFilters.end(); it++) {
|
|
|
|
if (*it) {
|
|
|
|
(*it)->WillDraw(aDT);
|
|
|
|
}
|
|
|
|
}
|
2013-11-27 03:25:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, uint32_t aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
2014-01-10 11:06:16 -08:00
|
|
|
if (mType == FilterType::TURBULENCE && aIndex == ATT_TURBULENCE_BASE_FREQUENCY) {
|
2013-11-27 03:25:16 -08:00
|
|
|
mEffect->SetValue(input, D2D1::Vector2F(FLOAT(aValue), FLOAT(aValue)));
|
|
|
|
return;
|
2014-01-10 11:06:16 -08:00
|
|
|
} else if (mType == FilterType::DIRECTIONAL_BLUR && aIndex == ATT_DIRECTIONAL_BLUR_DIRECTION) {
|
2013-11-27 03:25:16 -08:00
|
|
|
mEffect->SetValue(input, aValue == BLUR_DIRECTION_X ? 0 : 90.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffect->SetValue(input, ConvertValue(mType, aIndex, aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, Float aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const Point &aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, D2DPoint(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const Matrix5x4 &aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, D2DMatrix5x4(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const Point3D &aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, D2DVector3D(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const Size &aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, D2D1::Vector2F(aValue.width, aValue.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const IntSize &aValue)
|
|
|
|
{
|
|
|
|
UINT32 widthProp, heightProp;
|
|
|
|
|
|
|
|
if (!GetD2D1PropsForIntSize(mType, aIndex, &widthProp, &heightProp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize value = aValue;
|
|
|
|
ConvertValue(mType, aIndex, value);
|
|
|
|
|
|
|
|
mEffect->SetValue(widthProp, (UINT)value.width);
|
|
|
|
mEffect->SetValue(heightProp, (UINT)value.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const Color &aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
switch (mType) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case FilterType::POINT_DIFFUSE:
|
|
|
|
case FilterType::SPOT_DIFFUSE:
|
|
|
|
case FilterType::DISTANT_DIFFUSE:
|
|
|
|
case FilterType::POINT_SPECULAR:
|
|
|
|
case FilterType::SPOT_SPECULAR:
|
|
|
|
case FilterType::DISTANT_SPECULAR:
|
2013-11-27 03:25:16 -08:00
|
|
|
mEffect->SetValue(input, D2D1::Vector3F(aValue.r, aValue.g, aValue.b));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mEffect->SetValue(input, D2D1::Vector4F(aValue.r * aValue.a, aValue.g * aValue.a, aValue.b * aValue.a, aValue.a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const Rect &aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, D2DRect(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const IntRect &aValue)
|
|
|
|
{
|
2014-01-10 11:06:16 -08:00
|
|
|
if (mType == FilterType::TURBULENCE) {
|
2013-11-27 03:25:16 -08:00
|
|
|
MOZ_ASSERT(aIndex == ATT_TURBULENCE_RECT);
|
|
|
|
|
|
|
|
mEffect->SetValue(D2D1_TURBULENCE_PROP_OFFSET, D2D1::Vector2F(Float(aValue.x), Float(aValue.y)));
|
|
|
|
mEffect->SetValue(D2D1_TURBULENCE_PROP_SIZE, D2D1::Vector2F(Float(aValue.width), Float(aValue.height)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, D2D1::RectF(Float(aValue.x), Float(aValue.y),
|
|
|
|
Float(aValue.XMost()), Float(aValue.YMost())));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, bool aValue)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, (BOOL)aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const Float *aValues, uint32_t aSize)
|
|
|
|
{
|
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
|
|
|
mEffect->SetValue(input, (BYTE*)aValues, sizeof(Float) * aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const IntPoint &aValue)
|
|
|
|
{
|
2013-11-27 03:25:27 -08:00
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
2013-11-27 03:25:16 -08:00
|
|
|
|
2013-11-27 03:25:27 -08:00
|
|
|
mEffect->SetValue(input, D2DPoint(aValue));
|
|
|
|
}
|
2013-11-27 03:25:16 -08:00
|
|
|
|
2013-11-27 03:25:27 -08:00
|
|
|
void
|
|
|
|
FilterNodeD2D1::SetAttribute(uint32_t aIndex, const Matrix &aMatrix)
|
|
|
|
{
|
2013-11-27 03:25:16 -08:00
|
|
|
UINT32 input = GetD2D1PropForAttribute(mType, aIndex);
|
|
|
|
MOZ_ASSERT(input < mEffect->GetPropertyCount());
|
|
|
|
|
2013-11-27 03:25:27 -08:00
|
|
|
mEffect->SetValue(input, D2DMatrix(aMatrix));
|
2013-11-27 03:25:16 -08:00
|
|
|
}
|
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
FilterNodeConvolveD2D1::FilterNodeConvolveD2D1(ID2D1DeviceContext *aDC)
|
|
|
|
: FilterNodeD2D1(nullptr, FilterType::CONVOLVE_MATRIX)
|
2013-11-27 03:25:16 -08:00
|
|
|
, mEdgeMode(EDGE_MODE_DUPLICATE)
|
|
|
|
{
|
|
|
|
// Correctly handling the interaction of edge mode and source rect is a bit
|
|
|
|
// tricky with D2D1 effects. We want the edge mode to only apply outside of
|
|
|
|
// the source rect (as specified by the ATT_CONVOLVE_MATRIX_SOURCE_RECT
|
|
|
|
// attribute). So if our input surface or filter is smaller than the source
|
|
|
|
// rect, we need to add transparency around it until we reach the edges of
|
|
|
|
// the source rect, and only then do any repeating or edge duplicating.
|
|
|
|
// Unfortunately, D2D1 does not have any "extend with transparency" effect.
|
|
|
|
// (The crop effect can only cut off parts, it can't make the output rect
|
|
|
|
// bigger.) And the border effect does not have a source rect attribute -
|
|
|
|
// it only looks at the output rect of its input filter or surface.
|
|
|
|
// So we use the following trick to extend the input size to the source rect:
|
|
|
|
// Instead of feeding the input directly into the border effect, we first
|
|
|
|
// composite it with a transparent flood effect (which is infinite-sized) and
|
|
|
|
// use a crop effect on the result in order to get the right size. Then we
|
|
|
|
// feed the cropped composition into the border effect, which then finally
|
|
|
|
// feeds into the convolve matrix effect.
|
|
|
|
// All of this is only necessary when our edge mode is not EDGE_MODE_NONE, so
|
|
|
|
// we update the filter chain dynamically in UpdateChain().
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = aDC->CreateEffect(CLSID_D2D1ConvolveMatrix, byRef(mEffect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create ConvolveMatrix filter!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffect->SetValue(D2D1_CONVOLVEMATRIX_PROP_BORDER_MODE, D2D1_BORDER_MODE_SOFT);
|
|
|
|
|
|
|
|
hr = aDC->CreateEffect(CLSID_D2D1Flood, byRef(mFloodEffect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create ConvolveMatrix filter!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFloodEffect->SetValue(D2D1_FLOOD_PROP_COLOR, D2D1::Vector4F(0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
|
|
|
|
hr = aDC->CreateEffect(CLSID_D2D1Composite, byRef(mCompositeEffect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create ConvolveMatrix filter!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCompositeEffect->SetInputEffect(1, mFloodEffect.get());
|
|
|
|
|
|
|
|
hr = aDC->CreateEffect(CLSID_D2D1Crop, byRef(mCropEffect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create ConvolveMatrix filter!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCropEffect->SetInputEffect(0, mCompositeEffect.get());
|
|
|
|
|
|
|
|
hr = aDC->CreateEffect(CLSID_D2D1Border, byRef(mBorderEffect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create ConvolveMatrix filter!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBorderEffect->SetInputEffect(0, mCropEffect.get());
|
|
|
|
|
|
|
|
UpdateChain();
|
|
|
|
UpdateSourceRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeConvolveD2D1::SetInput(uint32_t aIndex, FilterNode *aFilter)
|
|
|
|
{
|
2014-09-25 12:18:29 -07:00
|
|
|
FilterNodeD2D1::SetInput(aIndex, aFilter);
|
2013-11-27 03:25:16 -08:00
|
|
|
|
|
|
|
UpdateChain();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeConvolveD2D1::SetAttribute(uint32_t aIndex, uint32_t aValue)
|
|
|
|
{
|
|
|
|
if (aIndex != ATT_CONVOLVE_MATRIX_EDGE_MODE) {
|
|
|
|
return FilterNodeD2D1::SetAttribute(aIndex, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
mEdgeMode = (ConvolveMatrixEdgeMode)aValue;
|
|
|
|
|
|
|
|
UpdateChain();
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
ID2D1Effect*
|
|
|
|
FilterNodeConvolveD2D1::InputEffect()
|
|
|
|
{
|
|
|
|
return mEdgeMode == EDGE_MODE_NONE ? mEffect.get() : mCompositeEffect.get();
|
|
|
|
}
|
|
|
|
|
2013-11-27 03:25:16 -08:00
|
|
|
void
|
|
|
|
FilterNodeConvolveD2D1::UpdateChain()
|
|
|
|
{
|
|
|
|
// The shape of the filter graph:
|
|
|
|
//
|
|
|
|
// EDGE_MODE_NONE:
|
|
|
|
// input --> convolvematrix
|
|
|
|
//
|
|
|
|
// EDGE_MODE_DUPLICATE or EDGE_MODE_WRAP:
|
|
|
|
// input -------v
|
|
|
|
// flood --> composite --> crop --> border --> convolvematrix
|
2014-09-25 12:18:29 -07:00
|
|
|
//
|
|
|
|
// mEffect is convolvematrix.
|
2013-11-27 03:25:16 -08:00
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
if (mEdgeMode != EDGE_MODE_NONE) {
|
2013-11-27 03:25:16 -08:00
|
|
|
mEffect->SetInputEffect(0, mBorderEffect.get());
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
RefPtr<ID2D1Effect> inputEffect;
|
|
|
|
if (mInputFilters.size() > 0 && mInputFilters[0]) {
|
|
|
|
inputEffect = mInputFilters[0]->OutputEffect();
|
2013-11-27 03:25:16 -08:00
|
|
|
}
|
2014-09-25 12:18:29 -07:00
|
|
|
InputEffect()->SetInputEffect(0, inputEffect);
|
2013-11-27 03:25:16 -08:00
|
|
|
|
|
|
|
if (mEdgeMode == EDGE_MODE_DUPLICATE) {
|
|
|
|
mBorderEffect->SetValue(D2D1_BORDER_PROP_EDGE_MODE_X, D2D1_BORDER_EDGE_MODE_CLAMP);
|
|
|
|
mBorderEffect->SetValue(D2D1_BORDER_PROP_EDGE_MODE_Y, D2D1_BORDER_EDGE_MODE_CLAMP);
|
|
|
|
} else if (mEdgeMode == EDGE_MODE_WRAP) {
|
|
|
|
mBorderEffect->SetValue(D2D1_BORDER_PROP_EDGE_MODE_X, D2D1_BORDER_EDGE_MODE_WRAP);
|
|
|
|
mBorderEffect->SetValue(D2D1_BORDER_PROP_EDGE_MODE_Y, D2D1_BORDER_EDGE_MODE_WRAP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeConvolveD2D1::SetAttribute(uint32_t aIndex, const IntSize &aValue)
|
|
|
|
{
|
|
|
|
if (aIndex != ATT_CONVOLVE_MATRIX_KERNEL_SIZE) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mKernelSize = aValue;
|
|
|
|
|
|
|
|
mEffect->SetValue(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_X, aValue.width);
|
|
|
|
mEffect->SetValue(D2D1_CONVOLVEMATRIX_PROP_KERNEL_SIZE_Y, aValue.height);
|
|
|
|
|
|
|
|
UpdateOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeConvolveD2D1::SetAttribute(uint32_t aIndex, const IntPoint &aValue)
|
|
|
|
{
|
|
|
|
if (aIndex != ATT_CONVOLVE_MATRIX_TARGET) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTarget = aValue;
|
|
|
|
|
|
|
|
UpdateOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeConvolveD2D1::SetAttribute(uint32_t aIndex, const IntRect &aValue)
|
|
|
|
{
|
|
|
|
if (aIndex != ATT_CONVOLVE_MATRIX_SOURCE_RECT) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSourceRect = aValue;
|
|
|
|
|
|
|
|
UpdateSourceRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeConvolveD2D1::UpdateOffset()
|
|
|
|
{
|
|
|
|
D2D1_VECTOR_2F vector =
|
|
|
|
D2D1::Vector2F((Float(mKernelSize.width) - 1.0f) / 2.0f - Float(mTarget.x),
|
|
|
|
(Float(mKernelSize.height) - 1.0f) / 2.0f - Float(mTarget.y));
|
|
|
|
|
|
|
|
mEffect->SetValue(D2D1_CONVOLVEMATRIX_PROP_KERNEL_OFFSET, vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FilterNodeConvolveD2D1::UpdateSourceRect()
|
|
|
|
{
|
|
|
|
mCropEffect->SetValue(D2D1_CROP_PROP_RECT,
|
|
|
|
D2D1::RectF(Float(mSourceRect.x), Float(mSourceRect.y),
|
|
|
|
Float(mSourceRect.XMost()), Float(mSourceRect.YMost())));
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:18:29 -07:00
|
|
|
FilterNodeComponentTransferD2D1::FilterNodeComponentTransferD2D1(ID2D1DeviceContext *aDC,
|
2013-11-27 03:25:16 -08:00
|
|
|
ID2D1Effect *aEffect, FilterType aType)
|
2014-09-25 12:18:29 -07:00
|
|
|
: FilterNodeD2D1(aEffect, aType)
|
2013-11-27 03:25:16 -08:00
|
|
|
{
|
|
|
|
// D2D1 component transfer effects do strange things when it comes to
|
|
|
|
// premultiplication.
|
|
|
|
// For our purposes we only need the transfer filters to apply straight to
|
|
|
|
// unpremultiplied source channels and output unpremultiplied results.
|
|
|
|
// However, the D2D1 effects are designed differently: They can apply to both
|
|
|
|
// premultiplied and unpremultiplied inputs, and they always premultiply
|
|
|
|
// their result - at least in those color channels that have not been
|
|
|
|
// disabled.
|
|
|
|
// In order to determine whether the input needs to be unpremultiplied as
|
|
|
|
// part of the transfer, the effect consults the alpha mode metadata of the
|
|
|
|
// input surface or the input effect. We don't have such a concept in Moz2D,
|
|
|
|
// and giving Moz2D users different results based on something that cannot be
|
|
|
|
// influenced through Moz2D APIs seems like a bad idea.
|
|
|
|
// We solve this by applying a premultiply effect to the input before feeding
|
|
|
|
// it into the transfer effect. The premultiply effect always premultiplies
|
|
|
|
// regardless of any alpha mode metadata on inputs, and it always marks its
|
|
|
|
// output as premultiplied so that the transfer effect will unpremultiply
|
|
|
|
// consistently. Feeding always-premultiplied input into the transfer effect
|
|
|
|
// also avoids another problem that would appear when individual color
|
|
|
|
// channels disable the transfer: In that case, the disabled channels would
|
|
|
|
// pass through unchanged in their unpremultiplied form and the other
|
|
|
|
// channels would be premultiplied, giving a mixed result.
|
|
|
|
// But since we now ensure that the input is premultiplied, disabled channels
|
|
|
|
// will pass premultiplied values through to the result, which is consistent
|
|
|
|
// with the enabled channels.
|
|
|
|
// We also add an unpremultiply effect that postprocesses the result of the
|
|
|
|
// transfer effect because getting unpremultiplied results from the transfer
|
|
|
|
// filters is part of the FilterNode API.
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = aDC->CreateEffect(CLSID_D2D1Premultiply, byRef(mPrePremultiplyEffect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create ComponentTransfer filter!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = aDC->CreateEffect(CLSID_D2D1UnPremultiply, byRef(mPostUnpremultiplyEffect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create ComponentTransfer filter!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffect->SetInputEffect(0, mPrePremultiplyEffect.get());
|
|
|
|
mPostUnpremultiplyEffect->SetInputEffect(0, mEffect.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|