gfx/layers/client/CanvasClient.h
author jdashg <jdashg+github@gmail.com>
Tue, 07 Oct 2014 21:11:54 -0700
changeset 233106 66f8715610050f9fc67c0190e7e7e3c8cd154ca8
parent 233105 a957533009dfbc03ede8e09f87de8007f410e871
child 233107 72ce4c2ccdcb6f0dd58f55422a52c5dce1caba71
permissions -rw-r--r--
Bug 1066280 - Fixes. - r=kamidphish,mattwoodrow From 4e9f52ab105333e8b1120342e9583b2d833a4465 Mon Sep 17 00:00:00 2001 --- dom/canvas/WebGLContext.cpp | 10 +++++-- gfx/gl/GLContext.cpp | 20 -------------- gfx/gl/GLContext.h | 3 -- gfx/gl/GLReadTexImageHelper.cpp | 5 +++- gfx/gl/GLScreenBuffer.cpp | 13 +++++++-- gfx/gl/GLUploadHelpers.cpp | 27 ++++++++++++++++++ gfx/gl/SharedSurfaceGralloc.cpp | 14 ++++------ gfx/gl/SharedSurfaceGralloc.h | 10 +++++-- gfx/gl/SurfaceTypes.cpp | 2 ++ gfx/gl/SurfaceTypes.h | 1 + gfx/layers/client/CanvasClient.cpp | 44 ++++++++++++++++++------------ gfx/layers/client/CanvasClient.h | 8 +++--- gfx/layers/client/ClientCanvasLayer.cpp | 6 ++++ gfx/layers/client/ClientCanvasLayer.h | 2 +- gfx/layers/client/TextureClient.cpp | 11 ++++---- gfx/layers/client/TextureClient.h | 6 ++-- gfx/layers/composite/TextureHost.cpp | 15 +++++----- gfx/layers/composite/TextureHost.h | 10 +++---- gfx/layers/d3d10/CanvasLayerD3D10.cpp | 9 ++++-- gfx/layers/d3d9/CanvasLayerD3D9.cpp | 8 ++++-- gfx/layers/ipc/LayersSurfaces.ipdlh | 4 +-- gfx/layers/moz.build | 4 ++- gfx/layers/opengl/GrallocTextureClient.cpp | 26 +++++++++++++++++- gfx/layers/opengl/GrallocTextureClient.h | 3 ++ 24 files changed, 171 insertions(+), 90 deletions(-)

/* -*- Mode: C++; tab-width: 20; 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_CANVASCLIENT_H
#define MOZILLA_GFX_CANVASCLIENT_H

#include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
#include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
#include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef
#include "mozilla/layers/CompositableClient.h"  // for CompositableClient
#include "mozilla/layers/CompositorTypes.h"  // for TextureInfo, etc
#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
#include "mozilla/layers/TextureClient.h"  // for TextureClient, etc
#include "mozilla/mozalloc.h"           // for operator delete

#include "mozilla/gfx/Point.h"          // for IntSize
#include "mozilla/gfx/Types.h"          // for SurfaceFormat

namespace mozilla {
namespace gl {
class SharedSurface;
class ShSurfHandle;
}
}

namespace mozilla {
namespace layers {

class ClientCanvasLayer;
class CompositableForwarder;

/**
 * Compositable client for 2d and webgl canvas.
 */
class CanvasClient : public CompositableClient
{
public:
  /**
   * Creates, configures, and returns a new canvas client. If necessary, a
   * message will be sent to the compositor to create a corresponding image
   * host.
   */
  enum CanvasClientType {
    CanvasClientSurface,
    CanvasClientGLContext,
    CanvasClientTypeShSurf,
  };
  static TemporaryRef<CanvasClient> CreateCanvasClient(CanvasClientType aType,
                                                       CompositableForwarder* aFwd,
                                                       TextureFlags aFlags);

  CanvasClient(CompositableForwarder* aFwd, TextureFlags aFlags)
    : CompositableClient(aFwd, aFlags)
  {
    mTextureInfo.mTextureFlags = aFlags;
  }

  virtual ~CanvasClient() {}

  virtual void Clear() {};

  virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) = 0;

  virtual void Updated() { }

protected:
  TextureInfo mTextureInfo;
};

// Used for 2D canvases and WebGL canvas on non-GL systems where readback is requried.
class CanvasClient2D : public CanvasClient
{
public:
  CanvasClient2D(CompositableForwarder* aLayerForwarder,
                 TextureFlags aFlags)
    : CanvasClient(aLayerForwarder, aFlags)
  {
  }

  TextureInfo GetTextureInfo() const
  {
    return TextureInfo(CompositableType::IMAGE);
  }

  virtual void Clear() MOZ_OVERRIDE
  {
    mBuffer = nullptr;
  }

  virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;

  virtual bool AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE
  {
    MOZ_ASSERT((mTextureInfo.mTextureFlags & aTexture->GetFlags()) == mTextureInfo.mTextureFlags);
    return CompositableClient::AddTextureClient(aTexture);
  }

  virtual void OnDetach() MOZ_OVERRIDE
  {
    mBuffer = nullptr;
  }

private:
  TemporaryRef<TextureClient>
    CreateTextureClientForCanvas(gfx::SurfaceFormat aFormat,
                                 gfx::IntSize aSize,
                                 TextureFlags aFlags,
                                 ClientCanvasLayer* aLayer);

  RefPtr<TextureClient> mBuffer;
};

// Used for GL canvases where we don't need to do any readback, i.e., with a
// GL backend.
class CanvasClientSurfaceStream : public CanvasClient
{
public:
  CanvasClientSurfaceStream(CompositableForwarder* aLayerForwarder, TextureFlags aFlags);

  TextureInfo GetTextureInfo() const
  {
    return TextureInfo(CompositableType::IMAGE);
  }

  virtual void Clear() MOZ_OVERRIDE
  {
    mBuffer = nullptr;
  }

  virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;

  virtual void OnDetach() MOZ_OVERRIDE
  {
    mBuffer = nullptr;
  }

private:
  RefPtr<TextureClient> mBuffer;
};

// Used for GL canvases where we don't need to do any readback, i.e., with a
// GL backend.
class CanvasClientSharedSurface : public CanvasClient
{
private:
  RefPtr<gl::ShSurfHandle> mFront;
  RefPtr<gl::ShSurfHandle> mPrevFront;

  RefPtr<TextureClient> mFrontTex;

public:
  CanvasClientSharedSurface(CompositableForwarder* aLayerForwarder,
                            TextureFlags aFlags);

  virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE {
    return TextureInfo(CompositableType::IMAGE);
  }

  virtual void Clear() MOZ_OVERRIDE {
    mFront = nullptr;
    mPrevFront = nullptr;
    mFrontTex = nullptr;
  }

  virtual void Update(gfx::IntSize aSize,
                      ClientCanvasLayer* aLayer) MOZ_OVERRIDE;

  virtual void OnDetach() MOZ_OVERRIDE {
    CanvasClientSharedSurface::Clear();
  }
};

}
}

#endif