Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
6 #include "X11TextureSourceBasic.h"
7 #include "mozilla/layers/BasicCompositor.h"
8 #include "gfxXlibSurface.h"
9 #include "gfx2DGlue.h"
11 using namespace mozilla;
12 using namespace mozilla::layers;
13 using namespace mozilla::gfx;
15 X11TextureSourceBasic::X11TextureSourceBasic(BasicCompositor* aCompositor, gfxXlibSurface* aSurface)
16 : mCompositor(aCompositor),
17 mSurface(aSurface)
18 {
19 }
21 IntSize
22 X11TextureSourceBasic::GetSize() const
23 {
24 return ToIntSize(mSurface->GetSize());
25 }
27 SurfaceFormat
28 X11TextureSourceBasic::GetFormat() const
29 {
30 gfxContentType type = mSurface->GetContentType();
31 return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type);
32 }
34 SourceSurface*
35 X11TextureSourceBasic::GetSurface(DrawTarget* aTarget)
36 {
37 if (!mSourceSurface) {
38 NativeSurface surf;
39 surf.mFormat = GetFormat();
40 surf.mType = NativeSurfaceType::CAIRO_SURFACE;
41 surf.mSurface = mSurface->CairoSurface();
42 surf.mSize = GetSize();
43 mSourceSurface = aTarget->CreateSourceSurfaceFromNativeSurface(surf);
44 }
45 return mSourceSurface;
46 }
48 void
49 X11TextureSourceBasic::SetCompositor(Compositor* aCompositor)
50 {
51 MOZ_ASSERT(aCompositor->GetBackendType() == LayersBackend::LAYERS_BASIC);
52 BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
53 mCompositor = compositor;
54 }
56 SurfaceFormat
57 X11TextureSourceBasic::ContentTypeToSurfaceFormat(gfxContentType aType)
58 {
59 switch (aType) {
60 case gfxContentType::COLOR:
61 return SurfaceFormat::B8G8R8X8;
62 case gfxContentType::ALPHA:
63 return SurfaceFormat::A8;
64 case gfxContentType::COLOR_ALPHA:
65 return SurfaceFormat::B8G8R8A8;
66 default:
67 return SurfaceFormat::UNKNOWN;
68 }
69 }