gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 "MacIOSurfaceTextureHostOGL.h"
michael@0 7 #include "mozilla/gfx/MacIOSurface.h"
michael@0 8 #include "mozilla/layers/CompositorOGL.h"
michael@0 9 #include "GLContextCGL.h"
michael@0 10
michael@0 11 namespace mozilla {
michael@0 12 namespace layers {
michael@0 13
michael@0 14 MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(TextureFlags aFlags,
michael@0 15 const SurfaceDescriptorMacIOSurface& aDescriptor)
michael@0 16 : TextureHost(aFlags)
michael@0 17 {
michael@0 18 mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(),
michael@0 19 aDescriptor.scaleFactor(),
michael@0 20 aDescriptor.hasAlpha());
michael@0 21 }
michael@0 22
michael@0 23 bool
michael@0 24 MacIOSurfaceTextureHostOGL::Lock()
michael@0 25 {
michael@0 26 if (!mCompositor || !mSurface) {
michael@0 27 return false;
michael@0 28 }
michael@0 29
michael@0 30 if (!mTextureSource) {
michael@0 31 mTextureSource = new MacIOSurfaceTextureSourceOGL(mCompositor, mSurface);
michael@0 32 }
michael@0 33 return true;
michael@0 34 }
michael@0 35
michael@0 36 void
michael@0 37 MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
michael@0 38 {
michael@0 39 CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
michael@0 40 mCompositor = glCompositor;
michael@0 41 if (mTextureSource) {
michael@0 42 mTextureSource->SetCompositor(glCompositor);
michael@0 43 }
michael@0 44 }
michael@0 45
michael@0 46 gfx::SurfaceFormat
michael@0 47 MacIOSurfaceTextureHostOGL::GetFormat() const {
michael@0 48 if (!mSurface) {
michael@0 49 return gfx::SurfaceFormat::UNKNOWN;
michael@0 50 }
michael@0 51 return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8X8;
michael@0 52 }
michael@0 53
michael@0 54 gfx::IntSize
michael@0 55 MacIOSurfaceTextureHostOGL::GetSize() const {
michael@0 56 if (!mSurface) {
michael@0 57 return gfx::IntSize();
michael@0 58 }
michael@0 59 return gfx::IntSize(mSurface->GetDevicePixelWidth(),
michael@0 60 mSurface->GetDevicePixelHeight());
michael@0 61 }
michael@0 62
michael@0 63 MacIOSurfaceTextureSourceOGL::MacIOSurfaceTextureSourceOGL(
michael@0 64 CompositorOGL* aCompositor,
michael@0 65 MacIOSurface* aSurface)
michael@0 66 : mCompositor(aCompositor)
michael@0 67 , mSurface(aSurface)
michael@0 68 {}
michael@0 69
michael@0 70 MacIOSurfaceTextureSourceOGL::~MacIOSurfaceTextureSourceOGL()
michael@0 71 {}
michael@0 72
michael@0 73 gfx::IntSize
michael@0 74 MacIOSurfaceTextureSourceOGL::GetSize() const
michael@0 75 {
michael@0 76 return gfx::IntSize(mSurface->GetDevicePixelWidth(),
michael@0 77 mSurface->GetDevicePixelHeight());
michael@0 78 }
michael@0 79
michael@0 80 gfx::SurfaceFormat
michael@0 81 MacIOSurfaceTextureSourceOGL::GetFormat() const
michael@0 82 {
michael@0 83 return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8X8;
michael@0 84 }
michael@0 85
michael@0 86 void
michael@0 87 MacIOSurfaceTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter)
michael@0 88 {
michael@0 89 if (!gl()) {
michael@0 90 NS_WARNING("Trying to bind a texture without a GLContext");
michael@0 91 return;
michael@0 92 }
michael@0 93 GLuint tex = mCompositor->GetTemporaryTexture(GetTextureTarget(), aTextureUnit);
michael@0 94
michael@0 95 gl()->fActiveTexture(aTextureUnit);
michael@0 96 gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, tex);
michael@0 97 mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(gl())->GetCGLContext());
michael@0 98 ApplyFilterToBoundTexture(gl(), aFilter, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
michael@0 99 }
michael@0 100
michael@0 101 void
michael@0 102 MacIOSurfaceTextureSourceOGL::SetCompositor(Compositor* aCompositor)
michael@0 103 {
michael@0 104 mCompositor = static_cast<CompositorOGL*>(aCompositor);
michael@0 105 }
michael@0 106
michael@0 107 gl::GLContext*
michael@0 108 MacIOSurfaceTextureSourceOGL::gl() const
michael@0 109 {
michael@0 110 return mCompositor ? mCompositor->gl() : nullptr;
michael@0 111 }
michael@0 112
michael@0 113 }
michael@0 114 }

mercurial