2008-02-20 03:33:27 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2008-02-20 03:33:27 -08:00
|
|
|
|
|
|
|
#include "gfxQuartzNativeDrawing.h"
|
|
|
|
#include "gfxQuartzSurface.h"
|
2013-10-24 09:23:22 -07:00
|
|
|
#include "gfxPlatform.h"
|
2010-04-29 20:19:08 -07:00
|
|
|
#include "cairo-quartz.h"
|
2014-08-28 20:08:15 -07:00
|
|
|
#include "gfx2DGlue.h"
|
2013-09-22 20:28:16 -07:00
|
|
|
|
2013-07-12 14:19:29 -07:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2008-02-20 03:33:27 -08:00
|
|
|
gfxQuartzNativeDrawing::gfxQuartzNativeDrawing(gfxContext* ctx,
|
2014-08-28 20:08:15 -07:00
|
|
|
const gfxRect& nativeRect)
|
2014-06-04 05:44:25 -07:00
|
|
|
: mContext(ctx)
|
2014-08-28 20:08:15 -07:00
|
|
|
, mNativeRect(ToRect(nativeRect))
|
2014-06-04 05:44:25 -07:00
|
|
|
, mCGContext(nullptr)
|
2008-02-20 03:33:27 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CGContextRef
|
|
|
|
gfxQuartzNativeDrawing::BeginNativeDrawing()
|
|
|
|
{
|
2014-06-04 05:44:25 -07:00
|
|
|
NS_ASSERTION(!mCGContext, "BeginNativeDrawing called when drawing already in progress");
|
|
|
|
|
|
|
|
DrawTarget *dt = mContext->GetDrawTarget();
|
2014-08-28 20:08:15 -07:00
|
|
|
if (dt->GetBackendType() != BackendType::COREGRAPHICS ||
|
|
|
|
dt->IsDualDrawTarget() ||
|
|
|
|
dt->IsTiledDrawTarget()) {
|
|
|
|
Matrix transform = dt->GetTransform();
|
|
|
|
mNativeRect = transform.TransformBounds(mNativeRect);
|
|
|
|
mNativeRect.RoundOut();
|
|
|
|
|
|
|
|
// Quartz theme drawing often adjusts drawing rects, so make
|
|
|
|
// sure our surface is big enough for that.
|
|
|
|
mNativeRect.Inflate(5);
|
|
|
|
|
|
|
|
if (mNativeRect.IsEmpty()) {
|
2014-06-04 05:44:25 -07:00
|
|
|
return nullptr;
|
2008-02-20 03:33:27 -08:00
|
|
|
}
|
|
|
|
|
2014-08-28 20:08:15 -07:00
|
|
|
mDrawTarget = Factory::CreateDrawTarget(BackendType::COREGRAPHICS,
|
|
|
|
IntSize(mNativeRect.width, mNativeRect.height),
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
2014-06-04 05:44:25 -07:00
|
|
|
|
2014-08-28 20:08:15 -07:00
|
|
|
transform.PostTranslate(-mNativeRect.x, -mNativeRect.y);
|
2014-06-04 05:44:25 -07:00
|
|
|
|
|
|
|
mDrawTarget->SetTransform(transform);
|
|
|
|
dt = mDrawTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCGContext = mBorrowedContext.Init(dt);
|
|
|
|
MOZ_ASSERT(mCGContext);
|
|
|
|
return mCGContext;
|
2008-02-20 03:33:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxQuartzNativeDrawing::EndNativeDrawing()
|
|
|
|
{
|
2014-06-04 05:44:25 -07:00
|
|
|
NS_ASSERTION(mCGContext, "EndNativeDrawing called without BeginNativeDrawing");
|
2013-07-12 14:19:29 -07:00
|
|
|
|
2014-06-04 05:44:25 -07:00
|
|
|
mBorrowedContext.Finish();
|
|
|
|
if (mDrawTarget) {
|
|
|
|
DrawTarget *dest = mContext->GetDrawTarget();
|
|
|
|
RefPtr<SourceSurface> source = mDrawTarget->Snapshot();
|
2013-07-12 14:19:29 -07:00
|
|
|
|
2014-06-04 05:44:25 -07:00
|
|
|
Matrix oldTransform = dest->GetTransform();
|
2014-08-28 20:08:15 -07:00
|
|
|
dest->SetTransform(Matrix());
|
2013-07-12 14:19:29 -07:00
|
|
|
|
2014-06-04 05:44:25 -07:00
|
|
|
dest->DrawSurface(source,
|
2014-08-28 20:08:15 -07:00
|
|
|
mNativeRect,
|
|
|
|
gfx::Rect(0, 0, mNativeRect.width, mNativeRect.height));
|
2013-07-12 14:19:29 -07:00
|
|
|
|
2008-02-20 03:33:27 -08:00
|
|
|
|
2014-06-04 05:44:25 -07:00
|
|
|
dest->SetTransform(oldTransform);
|
|
|
|
}
|
2008-02-20 03:33:27 -08:00
|
|
|
}
|