michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "MacIOSurfaceImage.h" michael@0: #include "mozilla/layers/MacIOSurfaceTextureClientOGL.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::layers; michael@0: michael@0: TextureClient* michael@0: MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient) michael@0: { michael@0: if (!mTextureClient) { michael@0: RefPtr buffer = michael@0: new MacIOSurfaceTextureClientOGL(TEXTURE_FLAGS_DEFAULT); michael@0: buffer->InitWith(mSurface); michael@0: mTextureClient = buffer; michael@0: } michael@0: return mTextureClient; michael@0: } michael@0: michael@0: TemporaryRef michael@0: MacIOSurfaceImage::GetAsSourceSurface() michael@0: { michael@0: mSurface->Lock(); michael@0: size_t bytesPerRow = mSurface->GetBytesPerRow(); michael@0: size_t ioWidth = mSurface->GetDevicePixelWidth(); michael@0: size_t ioHeight = mSurface->GetDevicePixelHeight(); michael@0: michael@0: unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress(); michael@0: michael@0: RefPtr dataSurface michael@0: = gfx::Factory::CreateDataSourceSurface(gfx::IntSize(ioWidth, ioHeight), gfx::SurfaceFormat::B8G8R8A8); michael@0: if (!dataSurface) michael@0: return nullptr; michael@0: michael@0: gfx::DataSourceSurface::MappedSurface mappedSurface; michael@0: if (!dataSurface->Map(gfx::DataSourceSurface::WRITE, &mappedSurface)) michael@0: return nullptr; michael@0: michael@0: for (size_t i = 0; i < ioHeight; ++i) { michael@0: memcpy(mappedSurface.mData + i * mappedSurface.mStride, michael@0: ioData + i * bytesPerRow, michael@0: ioWidth * 4); michael@0: } michael@0: michael@0: dataSurface->Unmap(); michael@0: mSurface->Unlock(); michael@0: michael@0: return dataSurface; michael@0: }