1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "MacIOSurfaceImage.h"
7 #include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
9 using namespace mozilla
;
10 using namespace mozilla::layers
;
13 MacIOSurfaceImage::GetTextureClient(CompositableClient
* aClient
)
15 if (!mTextureClient
) {
16 RefPtr
<MacIOSurfaceTextureClientOGL
> buffer
=
17 new MacIOSurfaceTextureClientOGL(TextureFlags::DEFAULT
);
18 buffer
->InitWith(mSurface
);
19 mTextureClient
= buffer
;
21 return mTextureClient
;
24 TemporaryRef
<gfx::SourceSurface
>
25 MacIOSurfaceImage::GetAsSourceSurface()
28 size_t bytesPerRow
= mSurface
->GetBytesPerRow();
29 size_t ioWidth
= mSurface
->GetDevicePixelWidth();
30 size_t ioHeight
= mSurface
->GetDevicePixelHeight();
32 unsigned char* ioData
= (unsigned char*)mSurface
->GetBaseAddress();
34 RefPtr
<gfx::DataSourceSurface
> dataSurface
35 = gfx::Factory::CreateDataSourceSurface(gfx::IntSize(ioWidth
, ioHeight
), gfx::SurfaceFormat::B8G8R8A8
);
36 if (NS_WARN_IF(!dataSurface
)) {
40 gfx::DataSourceSurface::MappedSurface mappedSurface
;
41 if (!dataSurface
->Map(gfx::DataSourceSurface::WRITE
, &mappedSurface
))
44 for (size_t i
= 0; i
< ioHeight
; ++i
) {
45 memcpy(mappedSurface
.mData
+ i
* mappedSurface
.mStride
,
46 ioData
+ i
* bytesPerRow
,