2008-02-20 14:33:27 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04: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 14:33:27 +03:00
|
|
|
|
|
|
|
#include "gfxQuartzNativeDrawing.h"
|
|
|
|
#include "gfxQuartzSurface.h"
|
2013-10-24 20:23:22 +04:00
|
|
|
#include "gfxPlatform.h"
|
2010-04-30 07:19:08 +04:00
|
|
|
#include "cairo-quartz.h"
|
2013-09-23 07:28:16 +04:00
|
|
|
|
2013-07-13 01:19:29 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2008-02-20 14:33:27 +03:00
|
|
|
gfxQuartzNativeDrawing::gfxQuartzNativeDrawing(gfxContext* ctx,
|
2012-10-29 13:22:30 +04:00
|
|
|
const gfxRect& nativeRect,
|
|
|
|
gfxFloat aBackingScale)
|
2014-06-04 16:44:25 +04:00
|
|
|
: mContext(ctx)
|
|
|
|
, mNativeRect(nativeRect)
|
|
|
|
, mBackingScale(aBackingScale)
|
|
|
|
, mCGContext(nullptr)
|
2008-02-20 14:33:27 +03:00
|
|
|
{
|
2014-06-04 16:44:25 +04:00
|
|
|
mNativeRect.RoundOut();
|
2008-02-20 14:33:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CGContextRef
|
|
|
|
gfxQuartzNativeDrawing::BeginNativeDrawing()
|
|
|
|
{
|
2014-06-04 16:44:25 +04:00
|
|
|
NS_ASSERTION(!mCGContext, "BeginNativeDrawing called when drawing already in progress");
|
|
|
|
|
|
|
|
DrawTarget *dt = mContext->GetDrawTarget();
|
2014-06-20 00:35:33 +04:00
|
|
|
if (dt->GetBackendType() != BackendType::COREGRAPHICS || dt->IsDualDrawTarget()) {
|
2014-06-04 16:44:25 +04:00
|
|
|
IntSize backingSize(NSToIntFloor(mNativeRect.width * mBackingScale),
|
|
|
|
NSToIntFloor(mNativeRect.height * mBackingScale));
|
|
|
|
|
|
|
|
if (backingSize.IsEmpty()) {
|
|
|
|
return nullptr;
|
2008-02-20 14:33:27 +03:00
|
|
|
}
|
|
|
|
|
2014-06-04 16:44:25 +04:00
|
|
|
mDrawTarget = Factory::CreateDrawTarget(BackendType::COREGRAPHICS, backingSize, SurfaceFormat::B8G8R8A8);
|
|
|
|
|
|
|
|
Matrix transform;
|
|
|
|
transform.Scale(mBackingScale, mBackingScale);
|
|
|
|
transform.Translate(-mNativeRect.x, -mNativeRect.y);
|
|
|
|
|
|
|
|
mDrawTarget->SetTransform(transform);
|
|
|
|
dt = mDrawTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCGContext = mBorrowedContext.Init(dt);
|
|
|
|
MOZ_ASSERT(mCGContext);
|
|
|
|
return mCGContext;
|
2008-02-20 14:33:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxQuartzNativeDrawing::EndNativeDrawing()
|
|
|
|
{
|
2014-06-04 16:44:25 +04:00
|
|
|
NS_ASSERTION(mCGContext, "EndNativeDrawing called without BeginNativeDrawing");
|
2013-07-13 01:19:29 +04:00
|
|
|
|
2014-06-04 16:44:25 +04:00
|
|
|
mBorrowedContext.Finish();
|
|
|
|
if (mDrawTarget) {
|
|
|
|
DrawTarget *dest = mContext->GetDrawTarget();
|
|
|
|
RefPtr<SourceSurface> source = mDrawTarget->Snapshot();
|
2013-07-13 01:19:29 +04:00
|
|
|
|
2014-06-04 16:44:25 +04:00
|
|
|
IntSize backingSize(NSToIntFloor(mNativeRect.width * mBackingScale),
|
|
|
|
NSToIntFloor(mNativeRect.height * mBackingScale));
|
2013-07-13 01:19:29 +04:00
|
|
|
|
2014-06-04 16:44:25 +04:00
|
|
|
Matrix oldTransform = dest->GetTransform();
|
|
|
|
Matrix newTransform = oldTransform;
|
|
|
|
newTransform.Translate(mNativeRect.x, mNativeRect.y);
|
|
|
|
newTransform.Scale(1.0f / mBackingScale, 1.0f / mBackingScale);
|
2013-07-13 01:19:29 +04:00
|
|
|
|
2014-06-04 16:44:25 +04:00
|
|
|
dest->SetTransform(newTransform);
|
2013-07-13 01:19:29 +04:00
|
|
|
|
2014-06-04 16:44:25 +04:00
|
|
|
dest->DrawSurface(source,
|
|
|
|
gfx::Rect(0, 0, backingSize.width, backingSize.height),
|
|
|
|
gfx::Rect(0, 0, backingSize.width, backingSize.height));
|
2013-07-13 01:19:29 +04:00
|
|
|
|
2008-02-20 14:33:27 +03:00
|
|
|
|
2014-06-04 16:44:25 +04:00
|
|
|
dest->SetTransform(oldTransform);
|
|
|
|
}
|
2008-02-20 14:33:27 +03:00
|
|
|
}
|