2013-11-01 01:54:14 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#include "MacIOSurfaceImage.h"
|
2014-12-22 08:49:00 +00:00
|
|
|
#include "mozilla/layers/CompositableClient.h"
|
|
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
2013-11-18 02:04:38 +00:00
|
|
|
#include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
|
2013-11-01 01:54:14 +00:00
|
|
|
|
2014-01-27 13:25:50 +00:00
|
|
|
using namespace mozilla;
|
2013-11-01 01:54:14 +00:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
TextureClient*
|
2014-02-16 22:23:39 +00:00
|
|
|
MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient)
|
2013-11-01 01:54:14 +00:00
|
|
|
{
|
|
|
|
if (!mTextureClient) {
|
2015-04-29 17:34:00 +00:00
|
|
|
mTextureClient = MacIOSurfaceTextureClientOGL::Create(aClient->GetForwarder(),
|
|
|
|
TextureFlags::DEFAULT,
|
|
|
|
mSurface);
|
2013-11-01 01:54:14 +00:00
|
|
|
}
|
|
|
|
return mTextureClient;
|
|
|
|
}
|
2014-01-27 13:25:50 +00:00
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<gfx::SourceSurface>
|
2014-01-27 13:25:50 +00:00
|
|
|
MacIOSurfaceImage::GetAsSourceSurface()
|
|
|
|
{
|
|
|
|
mSurface->Lock();
|
|
|
|
size_t bytesPerRow = mSurface->GetBytesPerRow();
|
|
|
|
size_t ioWidth = mSurface->GetDevicePixelWidth();
|
|
|
|
size_t ioHeight = mSurface->GetDevicePixelHeight();
|
|
|
|
|
|
|
|
unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress();
|
|
|
|
|
|
|
|
RefPtr<gfx::DataSourceSurface> dataSurface
|
|
|
|
= gfx::Factory::CreateDataSourceSurface(gfx::IntSize(ioWidth, ioHeight), gfx::SurfaceFormat::B8G8R8A8);
|
2014-08-27 15:57:43 +00:00
|
|
|
if (NS_WARN_IF(!dataSurface)) {
|
2014-01-27 13:25:50 +00:00
|
|
|
return nullptr;
|
2014-08-27 15:57:43 +00:00
|
|
|
}
|
2014-01-27 13:25:50 +00:00
|
|
|
|
|
|
|
gfx::DataSourceSurface::MappedSurface mappedSurface;
|
|
|
|
if (!dataSurface->Map(gfx::DataSourceSurface::WRITE, &mappedSurface))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ioHeight; ++i) {
|
|
|
|
memcpy(mappedSurface.mData + i * mappedSurface.mStride,
|
|
|
|
ioData + i * bytesPerRow,
|
|
|
|
ioWidth * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
dataSurface->Unmap();
|
|
|
|
mSurface->Unlock();
|
|
|
|
|
2015-05-01 13:14:16 +00:00
|
|
|
return dataSurface.forget();
|
2014-01-27 13:25:50 +00:00
|
|
|
}
|