本文整理匯總了C++中DrawTarget::GetNativeSurface方法的典型用法代碼示例。如果您正苦於以下問題:C++ DrawTarget::GetNativeSurface方法的具體用法?C++ DrawTarget::GetNativeSurface怎麽用?C++ DrawTarget::GetNativeSurface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DrawTarget
的用法示例。
在下文中一共展示了DrawTarget::GetNativeSurface方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: GetSkiaPathForGlyphs
already_AddRefed<Path>
ScaledFontBase::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
{
#ifdef USE_SKIA
if (aTarget->GetBackendType() == BackendType::SKIA) {
SkPath path = GetSkiaPathForGlyphs(aBuffer);
return MakeAndAddRef<PathSkia>(path, FillRule::FILL_WINDING);
}
#endif
#ifdef USE_CAIRO
if (aTarget->GetBackendType() == BackendType::CAIRO) {
MOZ_ASSERT(mScaledFont);
DrawTarget *dt = const_cast<DrawTarget*>(aTarget);
cairo_t *ctx = static_cast<cairo_t*>(dt->GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT));
bool isNewContext = !ctx;
if (!ctx) {
ctx = cairo_create(DrawTargetCairo::GetDummySurface());
cairo_matrix_t mat;
GfxMatrixToCairoMatrix(aTarget->GetTransform(), mat);
cairo_set_matrix(ctx, &mat);
}
cairo_set_scaled_font(ctx, mScaledFont);
// Convert our GlyphBuffer into an array of Cairo glyphs.
std::vector<cairo_glyph_t> glyphs(aBuffer.mNumGlyphs);
for (uint32_t i = 0; i < aBuffer.mNumGlyphs; ++i) {
glyphs[i].index = aBuffer.mGlyphs[i].mIndex;
glyphs[i].x = aBuffer.mGlyphs[i].mPosition.x;
glyphs[i].y = aBuffer.mGlyphs[i].mPosition.y;
}
cairo_new_path(ctx);
cairo_glyph_path(ctx, &glyphs[0], aBuffer.mNumGlyphs);
RefPtr<PathCairo> newPath = new PathCairo(ctx);
if (isNewContext) {
cairo_destroy(ctx);
}
return newPath.forget();
}
#endif
return nullptr;
}
示例2: if
HDC
gfxWindowsNativeDrawing::BeginNativeDrawing()
{
if (mRenderState == RENDER_STATE_INIT) {
RefPtr<gfxASurface> surf;
DrawTarget* drawTarget = mContext->GetDrawTarget();
cairo_t* cairo = nullptr;
if (drawTarget->GetBackendType() == BackendType::CAIRO) {
cairo = static_cast<cairo_t*>
(drawTarget->GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT));
if (cairo) {
cairo_surface_t* s = cairo_get_target(cairo);
if (s) {
mDeviceOffset = mContext->GetDeviceOffset();
surf = gfxASurface::Wrap(s);
}
}
}
if (surf && surf->CairoStatus() != 0)
return nullptr;
gfxMatrix m = mContext->CurrentMatrix();
if (!m.HasNonTranslation())
mTransformType = TRANSLATION_ONLY;
else if (m.HasNonAxisAlignedTransform())
mTransformType = COMPLEX;
else
mTransformType = AXIS_ALIGNED_SCALE;
// if this is a native win32 surface, we don't have to
// redirect rendering to our own HDC; in some cases,
// we may be able to use the HDC from the surface directly.
if (surf &&
((surf->GetType() == gfxSurfaceType::Win32 ||
surf->GetType() == gfxSurfaceType::Win32Printing) &&
(surf->GetContentType() == gfxContentType::COLOR ||
(surf->GetContentType() == gfxContentType::COLOR_ALPHA &&
(mNativeDrawFlags & CAN_DRAW_TO_COLOR_ALPHA)))))
{
// grab the DC. This can fail if there is a complex clipping path,
// in which case we'll have to fall back.
mWinSurface = static_cast<gfxWindowsSurface*>(static_cast<gfxASurface*>(surf.get()));
mDC = cairo_win32_get_dc_with_clip(cairo);
if (mDC) {
if (mTransformType == TRANSLATION_ONLY) {
mRenderState = RENDER_STATE_NATIVE_DRAWING;
mTranslation = m.GetTranslation();
} else if (((mTransformType == AXIS_ALIGNED_SCALE)
&& (mNativeDrawFlags & CAN_AXIS_ALIGNED_SCALE)) ||
(mNativeDrawFlags & CAN_COMPLEX_TRANSFORM))
{
mWorldTransform.eM11 = (FLOAT) m._11;
mWorldTransform.eM12 = (FLOAT) m._12;
mWorldTransform.eM21 = (FLOAT) m._21;
mWorldTransform.eM22 = (FLOAT) m._22;
mWorldTransform.eDx = (FLOAT) m._31;
mWorldTransform.eDy = (FLOAT) m._32;
mRenderState = RENDER_STATE_NATIVE_DRAWING;
}
}
}
// If we couldn't do native drawing, then we have to do two-buffer drawing
// and do alpha recovery
if (mRenderState == RENDER_STATE_INIT) {
mRenderState = RENDER_STATE_ALPHA_RECOVERY_BLACK;
// We round out our native rect here, that way the snapping will
// happen correctly.
mNativeRect.RoundOut();
// we only do the scale bit if we can do an axis aligned
// scale; otherwise we scale (if necessary) after
// rendering with cairo. Note that if we're doing alpha recovery,
// we cannot do a full complex transform with win32 (I mean, we could, but
// it would require more code that's not here.)
if (mTransformType == TRANSLATION_ONLY || !(mNativeDrawFlags & CAN_AXIS_ALIGNED_SCALE)) {
mScale = gfxSize(1.0, 1.0);
// Add 1 to the surface size; it's guaranteed to not be incorrect,
// and it fixes bug 382458
// There's probably a better fix, but I haven't figured out
// the root cause of the problem.
mTempSurfaceSize =
IntSize((int32_t) ceil(mNativeRect.Width() + 1),
(int32_t) ceil(mNativeRect.Height() + 1));
} else {
// figure out the scale factors
mScale = m.ScaleFactors(true);
mWorldTransform.eM11 = (FLOAT) mScale.width;
mWorldTransform.eM12 = 0.0f;
mWorldTransform.eM21 = 0.0f;
mWorldTransform.eM22 = (FLOAT) mScale.height;
mWorldTransform.eDx = 0.0f;
mWorldTransform.eDy = 0.0f;
//.........這裏部分代碼省略.........
示例3: affectedRect
void
gfxXlibNativeRenderer::Draw(gfxContext* ctx, nsIntSize size,
uint32_t flags, Screen *screen, Visual *visual)
{
gfxMatrix matrix = ctx->CurrentMatrix();
// We can only draw direct or onto a copied background if pixels align and
// native drawing is compatible with the current operator. (The matrix is
// actually also pixel-exact for flips and right-angle rotations, which
// would permit copying the background but not drawing direct.)
bool matrixIsIntegerTranslation = !matrix.HasNonIntegerTranslation();
bool canDrawOverBackground = matrixIsIntegerTranslation &&
ctx->CurrentOperator() == gfxContext::OPERATOR_OVER;
// The padding of 0.5 for non-pixel-exact transformations used here is
// the same as what _cairo_pattern_analyze_filter uses.
const gfxFloat filterRadius = 0.5;
gfxRect affectedRect(0.0, 0.0, size.width, size.height);
if (!matrixIsIntegerTranslation) {
// The filter footprint means that the affected rectangle is a
// little larger than the drawingRect;
affectedRect.Inflate(filterRadius);
NATIVE_DRAWING_NOTE("FALLBACK: matrix not integer translation");
} else if (!canDrawOverBackground) {
NATIVE_DRAWING_NOTE("FALLBACK: unsupported operator");
}
// Clipping to the region affected by drawing allows us to consider only
// the portions of the clip region that will be affected by drawing.
gfxRect clipExtents;
{
gfxContextAutoSaveRestore autoSR(ctx);
ctx->Clip(affectedRect);
clipExtents = ctx->GetClipExtents();
if (clipExtents.IsEmpty())
return; // nothing to do
if (canDrawOverBackground &&
DrawDirect(ctx, size, flags, screen, visual))
return;
}
IntRect drawingRect(IntPoint(0, 0), size);
// Drawing need only be performed within the clip extents
// (and padding for the filter).
if (!matrixIsIntegerTranslation) {
// The source surface may need to be a little larger than the clip
// extents due to the filter footprint.
clipExtents.Inflate(filterRadius);
}
clipExtents.RoundOut();
IntRect intExtents(int32_t(clipExtents.X()),
int32_t(clipExtents.Y()),
int32_t(clipExtents.Width()),
int32_t(clipExtents.Height()));
drawingRect.IntersectRect(drawingRect, intExtents);
gfxPoint offset(drawingRect.x, drawingRect.y);
DrawingMethod method;
DrawTarget* drawTarget = ctx->GetDrawTarget();
Matrix dtTransform = drawTarget->GetTransform();
gfxPoint deviceTranslation = gfxPoint(dtTransform._31, dtTransform._32);
cairo_surface_t* cairoTarget = static_cast<cairo_surface_t*>
(drawTarget->GetNativeSurface(NativeSurfaceType::CAIRO_SURFACE));
cairo_surface_t* tempXlibSurface =
CreateTempXlibSurface(cairoTarget, drawTarget, size,
canDrawOverBackground, flags, screen, visual,
&method);
if (!tempXlibSurface)
return;
bool drawIsOpaque = (flags & DRAW_IS_OPAQUE) != 0;
if (!drawIsOpaque) {
cairo_t* tmpCtx = cairo_create(tempXlibSurface);
if (method == eCopyBackground) {
NS_ASSERTION(cairoTarget, "eCopyBackground only used when there's a cairoTarget");
cairo_set_operator(tmpCtx, CAIRO_OPERATOR_SOURCE);
gfxPoint pt = -(offset + deviceTranslation);
cairo_set_source_surface(tmpCtx, cairoTarget, pt.x, pt.y);
// The copy from the tempXlibSurface to the target context should
// use operator SOURCE, but that would need a mask to bound the
// operation. Here we only copy opaque backgrounds so operator
// OVER will behave like SOURCE masked by the surface.
NS_ASSERTION(cairo_surface_get_content(tempXlibSurface) == CAIRO_CONTENT_COLOR,
"Don't copy background with a transparent surface");
} else {
cairo_set_operator(tmpCtx, CAIRO_OPERATOR_CLEAR);
}
cairo_paint(tmpCtx);
cairo_destroy(tmpCtx);
}
if (!DrawOntoTempSurface(tempXlibSurface, -drawingRect.TopLeft())) {
cairo_surface_destroy(tempXlibSurface);
return;
//.........這裏部分代碼省略.........
示例4: PathSkia
TemporaryRef<Path>
ScaledFontBase::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget)
{
#ifdef USE_SKIA
if (aTarget->GetType() == BACKEND_SKIA) {
SkPaint paint;
paint.setTypeface(GetSkTypeface());
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
paint.setTextSize(SkFloatToScalar(mSize));
std::vector<uint16_t> indices;
std::vector<SkPoint> offsets;
indices.resize(aBuffer.mNumGlyphs);
offsets.resize(aBuffer.mNumGlyphs);
for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
indices[i] = aBuffer.mGlyphs[i].mIndex;
offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
}
SkPath path;
paint.getPosTextPath(&indices.front(), aBuffer.mNumGlyphs*2, &offsets.front(), &path);
return new PathSkia(path, FILL_WINDING);
}
#endif
#ifdef USE_CAIRO
if (aTarget->GetType() == BACKEND_CAIRO) {
MOZ_ASSERT(mScaledFont);
DrawTarget *dt = const_cast<DrawTarget*>(aTarget);
cairo_t *ctx = static_cast<cairo_t*>(dt->GetNativeSurface(NATIVE_SURFACE_CAIRO_CONTEXT));
bool isNewContext = !ctx;
if (!ctx) {
ctx = cairo_create(DrawTargetCairo::GetDummySurface());
cairo_matrix_t mat;
GfxMatrixToCairoMatrix(aTarget->GetTransform(), mat);
cairo_set_matrix(ctx, &mat);
}
cairo_set_scaled_font(ctx, mScaledFont);
// Convert our GlyphBuffer into an array of Cairo glyphs.
std::vector<cairo_glyph_t> glyphs(aBuffer.mNumGlyphs);
for (uint32_t i = 0; i < aBuffer.mNumGlyphs; ++i) {
glyphs[i].index = aBuffer.mGlyphs[i].mIndex;
glyphs[i].x = aBuffer.mGlyphs[i].mPosition.x;
glyphs[i].y = aBuffer.mGlyphs[i].mPosition.y;
}
cairo_glyph_path(ctx, &glyphs[0], aBuffer.mNumGlyphs);
RefPtr<PathCairo> newPath = new PathCairo(ctx);
if (isNewContext) {
cairo_destroy(ctx);
}
return newPath;
}
#endif
return nullptr;
}