Line data Source code
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 "X11BasicCompositor.h"
7 : #include "gfxPlatform.h"
8 : #include "gfx2DGlue.h"
9 : #include "gfxXlibSurface.h"
10 : #include "gfxImageSurface.h"
11 : #include "mozilla/X11Util.h"
12 :
13 : namespace mozilla {
14 : using namespace mozilla::gfx;
15 :
16 : namespace layers {
17 :
18 : bool
19 0 : X11DataTextureSourceBasic::Update(gfx::DataSourceSurface* aSurface,
20 : nsIntRegion* aDestRegion,
21 : gfx::IntPoint* aSrcOffset)
22 : {
23 : // Reallocate our internal X11 surface if we don't have a DrawTarget yet,
24 : // or if we changed surface size or format since last update.
25 0 : if (!mBufferDrawTarget ||
26 0 : (aSurface->GetSize() != mBufferDrawTarget->GetSize()) ||
27 0 : (aSurface->GetFormat() != mBufferDrawTarget->GetFormat())) {
28 :
29 0 : RefPtr<gfxASurface> surf;
30 0 : gfxImageFormat imageFormat = SurfaceFormatToImageFormat(aSurface->GetFormat());
31 0 : Display *display = DefaultXDisplay();
32 0 : Screen *screen = DefaultScreenOfDisplay(display);
33 : XRenderPictFormat *xrenderFormat =
34 0 : gfxXlibSurface::FindRenderFormat(display, imageFormat);
35 :
36 0 : if (xrenderFormat) {
37 0 : surf = gfxXlibSurface::Create(screen, xrenderFormat,
38 0 : aSurface->GetSize());
39 : }
40 :
41 0 : if (!surf) {
42 0 : NS_WARNING("Couldn't create native surface, fallback to image surface");
43 0 : surf = new gfxImageSurface(aSurface->GetSize(), imageFormat);
44 : }
45 :
46 0 : mBufferDrawTarget = gfxPlatform::GetPlatform()->
47 0 : CreateDrawTargetForSurface(surf, aSurface->GetSize());
48 : }
49 :
50 : // Image contents have changed, upload to our DrawTarget
51 : // If aDestRegion is null, means we're updating the whole surface
52 : // Note : Incremental update with a source offset is only used on Mac.
53 0 : NS_ASSERTION(!aSrcOffset, "SrcOffset should not be used with linux OMTC basic");
54 :
55 0 : if (aDestRegion) {
56 0 : for (auto iter = aDestRegion->RectIter(); !iter.Done(); iter.Next()) {
57 0 : const IntRect& rect = iter.Get();
58 0 : IntRect srcRect(rect.x, rect.y, rect.width, rect.height);
59 0 : IntPoint dstPoint(rect.x, rect.y);
60 :
61 : // We're uploading regions to our buffer, so let's just copy contents over
62 0 : mBufferDrawTarget->CopySurface(aSurface, srcRect, dstPoint);
63 : }
64 : } else {
65 : // We're uploading the whole buffer, so let's just copy the full surface
66 0 : IntSize size = aSurface->GetSize();
67 0 : mBufferDrawTarget->CopySurface(aSurface, IntRect(0, 0, size.width, size.height),
68 0 : IntPoint(0, 0));
69 : }
70 :
71 0 : return true;
72 : }
73 :
74 : TextureSourceBasic*
75 0 : X11DataTextureSourceBasic::AsSourceBasic()
76 : {
77 0 : return this;
78 : }
79 :
80 : IntSize
81 0 : X11DataTextureSourceBasic::GetSize() const
82 : {
83 0 : if (!mBufferDrawTarget) {
84 0 : NS_WARNING("Trying to query the size of an uninitialized TextureSource");
85 0 : return IntSize(0, 0);
86 : }
87 0 : return mBufferDrawTarget->GetSize();
88 : }
89 :
90 : gfx::SurfaceFormat
91 0 : X11DataTextureSourceBasic::GetFormat() const
92 : {
93 0 : if (!mBufferDrawTarget) {
94 0 : NS_WARNING("Trying to query the format of an uninitialized TextureSource");
95 0 : return gfx::SurfaceFormat::UNKNOWN;
96 : }
97 0 : return mBufferDrawTarget->GetFormat();
98 : }
99 :
100 : SourceSurface*
101 0 : X11DataTextureSourceBasic::GetSurface(DrawTarget* aTarget)
102 : {
103 0 : RefPtr<gfx::SourceSurface> surface;
104 0 : if (mBufferDrawTarget) {
105 0 : surface = mBufferDrawTarget->Snapshot();
106 0 : return surface.get();
107 : }
108 0 : return nullptr;
109 : }
110 :
111 : void
112 0 : X11DataTextureSourceBasic::DeallocateDeviceData()
113 : {
114 0 : mBufferDrawTarget = nullptr;
115 0 : }
116 :
117 : already_AddRefed<DataTextureSource>
118 0 : X11BasicCompositor::CreateDataTextureSource(TextureFlags aFlags)
119 : {
120 : RefPtr<DataTextureSource> result =
121 0 : new X11DataTextureSourceBasic();
122 0 : return result.forget();
123 : }
124 :
125 : void
126 0 : X11BasicCompositor::EndFrame()
127 : {
128 0 : BasicCompositor::EndFrame();
129 0 : XFlush(DefaultXDisplay());
130 0 : }
131 :
132 : } // namespace layers
133 : } // namespace mozilla
|