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"
|
2013-10-24 20:23:22 +04:00
|
|
|
#include "gfxPlatform.h"
|
2014-10-24 11:26:27 +04:00
|
|
|
#include "mozilla/gfx/Helpers.h"
|
2013-09-23 07:28:16 +04:00
|
|
|
|
2013-07-13 01:19:29 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2014-10-24 11:26:27 +04:00
|
|
|
gfxQuartzNativeDrawing::gfxQuartzNativeDrawing(DrawTarget& aDrawTarget,
|
|
|
|
const Rect& nativeRect)
|
|
|
|
: mDrawTarget(&aDrawTarget)
|
|
|
|
, mNativeRect(nativeRect)
|
2014-06-04 16:44:25 +04:00
|
|
|
, mCGContext(nullptr)
|
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");
|
|
|
|
|
2014-10-24 11:26:27 +04:00
|
|
|
DrawTarget *dt = mDrawTarget;
|
2016-10-25 23:22:17 +03:00
|
|
|
if (dt->IsDualDrawTarget() || dt->IsTiledDrawTarget() ||
|
|
|
|
dt->GetBackendType() != BackendType::SKIA) {
|
2014-10-24 11:26:27 +04:00
|
|
|
// We need a DrawTarget that we can get a CGContextRef from:
|
2014-08-29 07:08:15 +04:00
|
|
|
Matrix transform = dt->GetTransform();
|
2014-10-24 11:26:27 +04:00
|
|
|
|
2014-08-29 07:08:15 +04:00
|
|
|
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 16:44:25 +04:00
|
|
|
return nullptr;
|
2008-02-20 14:33:27 +03:00
|
|
|
}
|
|
|
|
|
2014-10-24 11:26:27 +04:00
|
|
|
mTempDrawTarget =
|
2016-08-03 17:53:12 +03:00
|
|
|
Factory::CreateDrawTarget(BackendType::SKIA,
|
2016-07-26 19:55:28 +03:00
|
|
|
IntSize::Truncate(mNativeRect.width, mNativeRect.height),
|
2014-10-24 11:26:27 +04:00
|
|
|
SurfaceFormat::B8G8R8A8);
|
2014-06-04 16:44:25 +04:00
|
|
|
|
2015-03-06 00:38:23 +03:00
|
|
|
if (mTempDrawTarget) {
|
|
|
|
transform.PostTranslate(-mNativeRect.x, -mNativeRect.y);
|
|
|
|
mTempDrawTarget->SetTransform(transform);
|
|
|
|
}
|
2014-10-24 11:26:27 +04:00
|
|
|
dt = mTempDrawTarget;
|
2014-06-04 16:44:25 +04:00
|
|
|
}
|
2015-03-06 00:38:23 +03:00
|
|
|
if (dt) {
|
2016-10-25 23:22:17 +03:00
|
|
|
MOZ_ASSERT(dt->GetBackendType() == BackendType::SKIA);
|
2015-03-06 00:38:23 +03:00
|
|
|
mCGContext = mBorrowedContext.Init(dt);
|
|
|
|
MOZ_ASSERT(mCGContext);
|
|
|
|
}
|
2014-06-04 16:44:25 +04:00
|
|
|
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();
|
2014-10-24 11:26:27 +04:00
|
|
|
if (mTempDrawTarget) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> source = mTempDrawTarget->Snapshot();
|
2008-02-20 14:33:27 +03:00
|
|
|
|
2014-10-24 11:26:27 +04:00
|
|
|
AutoRestoreTransform autoRestore(mDrawTarget);
|
|
|
|
mDrawTarget->SetTransform(Matrix());
|
|
|
|
mDrawTarget->DrawSurface(source, mNativeRect,
|
|
|
|
Rect(0, 0, mNativeRect.width, mNativeRect.height));
|
2014-06-04 16:44:25 +04:00
|
|
|
}
|
2008-02-20 14:33:27 +03:00
|
|
|
}
|