コード例 #1
0
void ArgumentCoder<WebCore::FilterOperations>::encode(ArgumentEncoder& encoder, const WebCore::FilterOperations& filters)
{
    encoder << static_cast<uint32_t>(filters.size());
    for (size_t i = 0; i < filters.size(); ++i) {
        const FilterOperation* filter = filters.at(i);
        FilterOperation::OperationType type = filter->getOperationType();
        encoder.encodeEnum(type);
        switch (type) {
        case FilterOperation::GRAYSCALE:
        case FilterOperation::SEPIA:
        case FilterOperation::SATURATE:
        case FilterOperation::HUE_ROTATE:
            encoder << static_cast<double>(static_cast<const BasicColorMatrixFilterOperation*>(filter)->amount());
            break;
        case FilterOperation::INVERT:
        case FilterOperation::BRIGHTNESS:
        case FilterOperation::CONTRAST:
        case FilterOperation::OPACITY:
            encoder << static_cast<double>(static_cast<const BasicComponentTransferFilterOperation*>(filter)->amount());
            break;
        case FilterOperation::BLUR:
            ArgumentCoder<Length>::encode(encoder, static_cast<const BlurFilterOperation*>(filter)->stdDeviation());
            break;
        case FilterOperation::DROP_SHADOW: {
            const DropShadowFilterOperation* shadow = static_cast<const DropShadowFilterOperation*>(filter);
            ArgumentCoder<IntPoint>::encode(encoder, shadow->location());
            encoder << static_cast<int32_t>(shadow->stdDeviation());
            ArgumentCoder<Color>::encode(encoder, shadow->color());
            break;
        }
#if ENABLE(CSS_SHADERS)
        case FilterOperation::CUSTOM:
            // Custom Filters are converted to VALIDATED_CUSTOM before reaching this point.
            ASSERT_NOT_REACHED();
            break;
        case FilterOperation::VALIDATED_CUSTOM: {
            const ValidatedCustomFilterOperation* customOperation = static_cast<const ValidatedCustomFilterOperation*>(filter);
            ASSERT(customOperation->validatedProgram());
            RefPtr<CustomFilterValidatedProgram> program = customOperation->validatedProgram();
            ASSERT(program->isInitialized());
            ASSERT(program->platformCompiledProgram());
            ASSERT(program->platformCompiledProgram()->client());
            WebCustomFilterProgramProxy* customFilterProgramProxy = static_cast<WebCustomFilterProgramProxy*>(program->platformCompiledProgram()->client());
            const CustomFilterProgramInfo& programInfo = program->programInfo();
            // FIXME: CustomFilterOperation should not need the meshType, it should just be encoded in the program itself.
            // https://bugs.webkit.org/show_bug.cgi?id=102529
            encoder.encodeEnum(programInfo.meshType());
            encoder << customFilterProgramProxy->id();
            CustomFilterParameterList parameters = customOperation->parameters();
            encoder << static_cast<uint32_t>(parameters.size());
            for (size_t i = 0; i < parameters.size(); ++i) {
                RefPtr<CustomFilterParameter> parameter = parameters[i];
                encoder << parameter->name();
                encoder.encodeEnum(parameter->parameterType());

                switch (parameter->parameterType()) {
                case CustomFilterParameter::ARRAY: {
                    CustomFilterArrayParameter* arrayParameter = static_cast<CustomFilterArrayParameter*>(parameter.get());
                    encoder << static_cast<uint32_t>(arrayParameter->size());
                    for (size_t j = 0; j < arrayParameter->size(); ++j)
                        encoder << arrayParameter->valueAt(j);
                    break;
                }
                case CustomFilterParameter::NUMBER: {
                    CustomFilterNumberParameter* nubmerParameter = static_cast<CustomFilterNumberParameter*>(parameter.get());
                    encoder << static_cast<uint32_t>(nubmerParameter->size());
                    for (size_t j = 0; j < nubmerParameter->size(); ++j)
                        encoder << nubmerParameter->valueAt(j);
                    break;
                }
                case CustomFilterParameter::TRANSFORM: {
                    CustomFilterTransformParameter* transformParameter = static_cast<CustomFilterTransformParameter*>(parameter.get());
                    ArgumentCoder<TransformOperations>::encode(encoder, transformParameter->operations());
                    break;
                }
                }
            }

            encoder << customOperation->meshRows();
            encoder << customOperation->meshColumns();
            break;
        }
#endif
        default:
            break;
        }
    }
}
コード例 #2
0
void ArgumentCoder<WebCore::FilterOperations>::encode(ArgumentEncoder& encoder, const WebCore::FilterOperations& filters)
{
    encoder << static_cast<uint32_t>(filters.size());
    for (size_t i = 0; i < filters.size(); ++i) {
        const FilterOperation* filter = filters.at(i);
        FilterOperation::OperationType type = filter->getOperationType();
        encoder.encodeEnum(type);
        switch (type) {
        case FilterOperation::GRAYSCALE:
        case FilterOperation::SEPIA:
        case FilterOperation::SATURATE:
        case FilterOperation::HUE_ROTATE:
            encoder << static_cast<double>(static_cast<const BasicColorMatrixFilterOperation*>(filter)->amount());
            break;
        case FilterOperation::INVERT:
        case FilterOperation::BRIGHTNESS:
        case FilterOperation::CONTRAST:
        case FilterOperation::OPACITY:
            encoder << static_cast<double>(static_cast<const BasicComponentTransferFilterOperation*>(filter)->amount());
            break;
        case FilterOperation::BLUR:
            ArgumentCoder<Length>::encode(encoder, static_cast<const BlurFilterOperation*>(filter)->stdDeviation());
            break;
        case FilterOperation::DROP_SHADOW: {
            const DropShadowFilterOperation* shadow = static_cast<const DropShadowFilterOperation*>(filter);
            ArgumentCoder<IntPoint>::encode(encoder, shadow->location());
            encoder << static_cast<int32_t>(shadow->stdDeviation());
            ArgumentCoder<Color>::encode(encoder, shadow->color());
            break;
        }
#if ENABLE(CSS_SHADERS)
        case FilterOperation::CUSTOM: {
            const CustomFilterOperation* customOperation = static_cast<const CustomFilterOperation*>(filter);

            ASSERT(customOperation->program());
            RefPtr<CustomFilterProgram> program = customOperation->program();
            ASSERT(program->isLoaded());
            encoder << program->vertexShaderString();
            encoder << program->fragmentShaderString();
            encoder.encodeEnum(program->programType());
            CustomFilterProgramMixSettings mixSettings = program->mixSettings();
            encoder.encodeEnum(mixSettings.blendMode);
            encoder.encodeEnum(mixSettings.compositeOperator);
            encoder.encodeEnum(program->meshType());

            CustomFilterParameterList parameters = customOperation->parameters();
            encoder << static_cast<uint32_t>(parameters.size());
            for (size_t i = 0; i < parameters.size(); ++i) {
                RefPtr<CustomFilterParameter> parameter = parameters[i];
                encoder << parameter->name();
                encoder.encodeEnum(parameter->parameterType());

                switch (parameter->parameterType()) {
                case CustomFilterParameter::ARRAY: {
                    CustomFilterArrayParameter* arrayParameter = static_cast<CustomFilterArrayParameter*>(parameter.get());
                    encoder << static_cast<uint32_t>(arrayParameter->size());
                    for (size_t j = 0; j < arrayParameter->size(); ++j)
                        encoder << arrayParameter->valueAt(j);
                    break;
                }
                case CustomFilterParameter::NUMBER: {
                    CustomFilterNumberParameter* nubmerParameter = static_cast<CustomFilterNumberParameter*>(parameter.get());
                    encoder << static_cast<uint32_t>(nubmerParameter->size());
                    for (size_t j = 0; j < nubmerParameter->size(); ++j)
                        encoder << nubmerParameter->valueAt(j);
                    break;
                }
                case CustomFilterParameter::TRANSFORM: {
                    CustomFilterTransformParameter* transformParameter = static_cast<CustomFilterTransformParameter*>(parameter.get());
                    ArgumentCoder<TransformOperations>::encode(encoder, transformParameter->operations());
                    break;
                }
                }
            }

            encoder << customOperation->meshRows();
            encoder << customOperation->meshColumns();
            encoder.encodeEnum(customOperation->meshBoxType());
            break;
        }
#endif
        default:
            break;
        }
    }
}