/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
already_AddRefed<SourceSurface> DrawTarget::IntoLuminanceSource(
LuminanceType aMaskType, float aOpacity) { // The default IntoLuminanceSource implementation needs a format of B8G8R8A8. if (mFormat != SurfaceFormat::B8G8R8A8) { return nullptr;
}
RefPtr<SourceSurface> surface = Snapshot(); if (!surface) { return nullptr;
}
IntSize size = surface->GetSize();
RefPtr<DataSourceSurface> maskSurface = surface->GetDataSurface(); if (!maskSurface) { return nullptr;
}
DataSourceSurface::MappedSurface map; if (!maskSurface->Map(DataSourceSurface::MapType::READ, &map)) { return nullptr;
}
// Create alpha channel mask for output
RefPtr<SourceSurfaceAlignedRawData> destMaskSurface = new SourceSurfaceAlignedRawData; if (!destMaskSurface->Init(size, SurfaceFormat::A8, false, 0)) { return nullptr;
}
DataSourceSurface::MappedSurface destMap; if (!destMaskSurface->Map(DataSourceSurface::MapType::WRITE, &destMap)) { return nullptr;
}
void DrawTarget::DrawShadow(const Path* aPath, const Pattern& aPattern, const ShadowOptions& aShadow, const DrawOptions& aOptions, const StrokeOptions* aStrokeOptions) { // Get the approximate bounds of the source path
Rect bounds = aPath->GetFastBounds(GetTransform(), aStrokeOptions); if (bounds.IsEmpty()) { return;
} // Inflate the bounds by the blur radius
bounds += aShadow.mOffset;
int32_t blurRadius = aShadow.BlurRadius();
bounds.Inflate(blurRadius);
bounds.RoundOut(); // Check if the bounds intersect the viewport
Rect viewport(GetRect());
viewport.Inflate(blurRadius);
bounds = bounds.Intersect(viewport);
IntRect intBounds; if (bounds.IsEmpty() || !bounds.ToIntRect(&intBounds) ||
!CanCreateSimilarDrawTarget(intBounds.Size(), SurfaceFormat::A8)) { return;
} // Create a draw target for drawing the shadow mask with enough room for blur
RefPtr<DrawTarget> shadowTarget = CreateShadowDrawTarget(
intBounds.Size(), SurfaceFormat::A8, aShadow.mSigma); if (shadowTarget) { // See bug 1524554.
shadowTarget->ClearRect(Rect());
} if (!shadowTarget || !shadowTarget->IsValid()) { return;
} // Draw the path into the target for the initial shadow mask
Point offset = Point(intBounds.TopLeft()) - aShadow.mOffset;
shadowTarget->SetTransform(GetTransform().PostTranslate(-offset));
DrawOptions shadowDrawOptions(
aOptions.mAlpha, CompositionOp::OP_OVER,
blurRadius > 1 ? AntialiasMode::NONE : aOptions.mAntialiasMode); if (aStrokeOptions) {
shadowTarget->Stroke(aPath, aPattern, *aStrokeOptions, shadowDrawOptions);
} else {
shadowTarget->Fill(aPath, aPattern, shadowDrawOptions);
}
RefPtr<SourceSurface> snapshot = shadowTarget->Snapshot(); // Finally, hand a snapshot of the mask to DrawSurfaceWithShadow for the // final shadow blur if (snapshot) {
DrawSurfaceWithShadow(snapshot, offset, aShadow, aOptions.mCompositionOp);
}
}
} // namespace gfx
} // namespace mozilla
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.