Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "MacIOSurfaceImage.h" |
michael@0 | 7 | #include "mozilla/layers/MacIOSurfaceTextureClientOGL.h" |
michael@0 | 8 | |
michael@0 | 9 | using namespace mozilla; |
michael@0 | 10 | using namespace mozilla::layers; |
michael@0 | 11 | |
michael@0 | 12 | TextureClient* |
michael@0 | 13 | MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient) |
michael@0 | 14 | { |
michael@0 | 15 | if (!mTextureClient) { |
michael@0 | 16 | RefPtr<MacIOSurfaceTextureClientOGL> buffer = |
michael@0 | 17 | new MacIOSurfaceTextureClientOGL(TEXTURE_FLAGS_DEFAULT); |
michael@0 | 18 | buffer->InitWith(mSurface); |
michael@0 | 19 | mTextureClient = buffer; |
michael@0 | 20 | } |
michael@0 | 21 | return mTextureClient; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | TemporaryRef<gfx::SourceSurface> |
michael@0 | 25 | MacIOSurfaceImage::GetAsSourceSurface() |
michael@0 | 26 | { |
michael@0 | 27 | mSurface->Lock(); |
michael@0 | 28 | size_t bytesPerRow = mSurface->GetBytesPerRow(); |
michael@0 | 29 | size_t ioWidth = mSurface->GetDevicePixelWidth(); |
michael@0 | 30 | size_t ioHeight = mSurface->GetDevicePixelHeight(); |
michael@0 | 31 | |
michael@0 | 32 | unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress(); |
michael@0 | 33 | |
michael@0 | 34 | RefPtr<gfx::DataSourceSurface> dataSurface |
michael@0 | 35 | = gfx::Factory::CreateDataSourceSurface(gfx::IntSize(ioWidth, ioHeight), gfx::SurfaceFormat::B8G8R8A8); |
michael@0 | 36 | if (!dataSurface) |
michael@0 | 37 | return nullptr; |
michael@0 | 38 | |
michael@0 | 39 | gfx::DataSourceSurface::MappedSurface mappedSurface; |
michael@0 | 40 | if (!dataSurface->Map(gfx::DataSourceSurface::WRITE, &mappedSurface)) |
michael@0 | 41 | return nullptr; |
michael@0 | 42 | |
michael@0 | 43 | for (size_t i = 0; i < ioHeight; ++i) { |
michael@0 | 44 | memcpy(mappedSurface.mData + i * mappedSurface.mStride, |
michael@0 | 45 | ioData + i * bytesPerRow, |
michael@0 | 46 | ioWidth * 4); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | dataSurface->Unmap(); |
michael@0 | 50 | mSurface->Unlock(); |
michael@0 | 51 | |
michael@0 | 52 | return dataSurface; |
michael@0 | 53 | } |