gfx/ipc/SharedDIBSurface.h
author Mike Conley <mconley@mozilla.com>
Thu, 05 Dec 2013 13:56:35 -0500
changeset 173599 52c84e6c3056f64492cbc83ec78c39d3cf8df693
parent 108463 a16372ce30b5f6b747246b01fcd215a4bf3b6342
child 266834 aee0f61516c53778dba9c97c6cbd5c35750902e3
permissions -rw-r--r--
Merge mozilla-central into holly

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_gfx_SharedDIBSurface_h
#define mozilla_gfx_SharedDIBSurface_h

#include "gfxImageSurface.h"
#include "SharedDIBWin.h"

#include <windows.h>

namespace mozilla {
namespace gfx {

/**
 * A SharedDIBSurface owns an underlying SharedDIBWin.
 */
class SharedDIBSurface : public gfxImageSurface
{
public:
  typedef base::SharedMemoryHandle Handle;

  SharedDIBSurface() { }
  ~SharedDIBSurface() { }

  /**
   * Create this image surface backed by shared memory.
   */
  bool Create(HDC adc, uint32_t aWidth, uint32_t aHeight, bool aTransparent);

  /**
   * Attach this surface to shared memory from another process.
   */
  bool Attach(Handle aHandle, uint32_t aWidth, uint32_t aHeight,
              bool aTransparent);

  /**
   * After drawing to a surface via GDI, GDI must be flushed before the bitmap
   * is valid.
   */
  void Flush() { ::GdiFlush(); }

  HDC GetHDC() { return mSharedDIB.GetHDC(); }

  nsresult ShareToProcess(base::ProcessHandle aChildProcess, Handle* aChildHandle) {
    return mSharedDIB.ShareToProcess(aChildProcess, aChildHandle);
  }

  static bool IsSharedDIBSurface(gfxASurface* aSurface);

private:
  SharedDIBWin mSharedDIB;

  void InitSurface(uint32_t aWidth, uint32_t aHeight, bool aTransparent);
};

} // namespace gfx
} // namespace mozilla

#endif // mozilla_gfx_SharedDIBSurface_h