gfx/layers/MacIOSurfaceImage.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/MacIOSurfaceImage.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "MacIOSurfaceImage.h"
    1.10 +#include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
    1.11 +
    1.12 +using namespace mozilla;
    1.13 +using namespace mozilla::layers;
    1.14 +
    1.15 +TextureClient*
    1.16 +MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient)
    1.17 +{
    1.18 +  if (!mTextureClient) {
    1.19 +    RefPtr<MacIOSurfaceTextureClientOGL> buffer =
    1.20 +      new MacIOSurfaceTextureClientOGL(TEXTURE_FLAGS_DEFAULT);
    1.21 +    buffer->InitWith(mSurface);
    1.22 +    mTextureClient = buffer;
    1.23 +  }
    1.24 +  return mTextureClient;
    1.25 +}
    1.26 +
    1.27 +TemporaryRef<gfx::SourceSurface>
    1.28 +MacIOSurfaceImage::GetAsSourceSurface()
    1.29 +{
    1.30 +  mSurface->Lock();
    1.31 +  size_t bytesPerRow = mSurface->GetBytesPerRow();
    1.32 +  size_t ioWidth = mSurface->GetDevicePixelWidth();
    1.33 +  size_t ioHeight = mSurface->GetDevicePixelHeight();
    1.34 +
    1.35 +  unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress();
    1.36 +
    1.37 +  RefPtr<gfx::DataSourceSurface> dataSurface
    1.38 +    = gfx::Factory::CreateDataSourceSurface(gfx::IntSize(ioWidth, ioHeight), gfx::SurfaceFormat::B8G8R8A8);
    1.39 +  if (!dataSurface)
    1.40 +    return nullptr;
    1.41 +
    1.42 +  gfx::DataSourceSurface::MappedSurface mappedSurface;
    1.43 +  if (!dataSurface->Map(gfx::DataSourceSurface::WRITE, &mappedSurface))
    1.44 +    return nullptr;
    1.45 +
    1.46 +  for (size_t i = 0; i < ioHeight; ++i) {
    1.47 +    memcpy(mappedSurface.mData + i * mappedSurface.mStride,
    1.48 +           ioData + i * bytesPerRow,
    1.49 +           ioWidth * 4);
    1.50 +  }
    1.51 +
    1.52 +  dataSurface->Unmap();
    1.53 +  mSurface->Unlock();
    1.54 +
    1.55 +  return dataSurface;
    1.56 +}

mercurial