|
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/. */ |
|
5 |
|
6 #include "MacIOSurfaceImage.h" |
|
7 #include "mozilla/layers/MacIOSurfaceTextureClientOGL.h" |
|
8 |
|
9 using namespace mozilla; |
|
10 using namespace mozilla::layers; |
|
11 |
|
12 TextureClient* |
|
13 MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient) |
|
14 { |
|
15 if (!mTextureClient) { |
|
16 RefPtr<MacIOSurfaceTextureClientOGL> buffer = |
|
17 new MacIOSurfaceTextureClientOGL(TEXTURE_FLAGS_DEFAULT); |
|
18 buffer->InitWith(mSurface); |
|
19 mTextureClient = buffer; |
|
20 } |
|
21 return mTextureClient; |
|
22 } |
|
23 |
|
24 TemporaryRef<gfx::SourceSurface> |
|
25 MacIOSurfaceImage::GetAsSourceSurface() |
|
26 { |
|
27 mSurface->Lock(); |
|
28 size_t bytesPerRow = mSurface->GetBytesPerRow(); |
|
29 size_t ioWidth = mSurface->GetDevicePixelWidth(); |
|
30 size_t ioHeight = mSurface->GetDevicePixelHeight(); |
|
31 |
|
32 unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress(); |
|
33 |
|
34 RefPtr<gfx::DataSourceSurface> dataSurface |
|
35 = gfx::Factory::CreateDataSourceSurface(gfx::IntSize(ioWidth, ioHeight), gfx::SurfaceFormat::B8G8R8A8); |
|
36 if (!dataSurface) |
|
37 return nullptr; |
|
38 |
|
39 gfx::DataSourceSurface::MappedSurface mappedSurface; |
|
40 if (!dataSurface->Map(gfx::DataSourceSurface::WRITE, &mappedSurface)) |
|
41 return nullptr; |
|
42 |
|
43 for (size_t i = 0; i < ioHeight; ++i) { |
|
44 memcpy(mappedSurface.mData + i * mappedSurface.mStride, |
|
45 ioData + i * bytesPerRow, |
|
46 ioWidth * 4); |
|
47 } |
|
48 |
|
49 dataSurface->Unmap(); |
|
50 mSurface->Unlock(); |
|
51 |
|
52 return dataSurface; |
|
53 } |