|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "MacIOSurfaceTextureHostOGL.h" |
|
7 #include "mozilla/gfx/MacIOSurface.h" |
|
8 #include "mozilla/layers/CompositorOGL.h" |
|
9 #include "GLContextCGL.h" |
|
10 |
|
11 namespace mozilla { |
|
12 namespace layers { |
|
13 |
|
14 MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(TextureFlags aFlags, |
|
15 const SurfaceDescriptorMacIOSurface& aDescriptor) |
|
16 : TextureHost(aFlags) |
|
17 { |
|
18 mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(), |
|
19 aDescriptor.scaleFactor(), |
|
20 aDescriptor.hasAlpha()); |
|
21 } |
|
22 |
|
23 bool |
|
24 MacIOSurfaceTextureHostOGL::Lock() |
|
25 { |
|
26 if (!mCompositor || !mSurface) { |
|
27 return false; |
|
28 } |
|
29 |
|
30 if (!mTextureSource) { |
|
31 mTextureSource = new MacIOSurfaceTextureSourceOGL(mCompositor, mSurface); |
|
32 } |
|
33 return true; |
|
34 } |
|
35 |
|
36 void |
|
37 MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor) |
|
38 { |
|
39 CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor); |
|
40 mCompositor = glCompositor; |
|
41 if (mTextureSource) { |
|
42 mTextureSource->SetCompositor(glCompositor); |
|
43 } |
|
44 } |
|
45 |
|
46 gfx::SurfaceFormat |
|
47 MacIOSurfaceTextureHostOGL::GetFormat() const { |
|
48 if (!mSurface) { |
|
49 return gfx::SurfaceFormat::UNKNOWN; |
|
50 } |
|
51 return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8X8; |
|
52 } |
|
53 |
|
54 gfx::IntSize |
|
55 MacIOSurfaceTextureHostOGL::GetSize() const { |
|
56 if (!mSurface) { |
|
57 return gfx::IntSize(); |
|
58 } |
|
59 return gfx::IntSize(mSurface->GetDevicePixelWidth(), |
|
60 mSurface->GetDevicePixelHeight()); |
|
61 } |
|
62 |
|
63 MacIOSurfaceTextureSourceOGL::MacIOSurfaceTextureSourceOGL( |
|
64 CompositorOGL* aCompositor, |
|
65 MacIOSurface* aSurface) |
|
66 : mCompositor(aCompositor) |
|
67 , mSurface(aSurface) |
|
68 {} |
|
69 |
|
70 MacIOSurfaceTextureSourceOGL::~MacIOSurfaceTextureSourceOGL() |
|
71 {} |
|
72 |
|
73 gfx::IntSize |
|
74 MacIOSurfaceTextureSourceOGL::GetSize() const |
|
75 { |
|
76 return gfx::IntSize(mSurface->GetDevicePixelWidth(), |
|
77 mSurface->GetDevicePixelHeight()); |
|
78 } |
|
79 |
|
80 gfx::SurfaceFormat |
|
81 MacIOSurfaceTextureSourceOGL::GetFormat() const |
|
82 { |
|
83 return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8X8; |
|
84 } |
|
85 |
|
86 void |
|
87 MacIOSurfaceTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) |
|
88 { |
|
89 if (!gl()) { |
|
90 NS_WARNING("Trying to bind a texture without a GLContext"); |
|
91 return; |
|
92 } |
|
93 GLuint tex = mCompositor->GetTemporaryTexture(GetTextureTarget(), aTextureUnit); |
|
94 |
|
95 gl()->fActiveTexture(aTextureUnit); |
|
96 gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, tex); |
|
97 mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(gl())->GetCGLContext()); |
|
98 ApplyFilterToBoundTexture(gl(), aFilter, LOCAL_GL_TEXTURE_RECTANGLE_ARB); |
|
99 } |
|
100 |
|
101 void |
|
102 MacIOSurfaceTextureSourceOGL::SetCompositor(Compositor* aCompositor) |
|
103 { |
|
104 mCompositor = static_cast<CompositorOGL*>(aCompositor); |
|
105 } |
|
106 |
|
107 gl::GLContext* |
|
108 MacIOSurfaceTextureSourceOGL::gl() const |
|
109 { |
|
110 return mCompositor ? mCompositor->gl() : nullptr; |
|
111 } |
|
112 |
|
113 } |
|
114 } |