summaryrefslogtreecommitdiffstats
path: root/cc/test/fake_web_compositor_output_surface.h
blob: 3cd5b80fa8559053d6228af4ca6c115d56e0cd99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_TEST_FAKE_WEB_COMPOSITOR_OUTPUT_SURFACE_H_
#define CC_TEST_FAKE_WEB_COMPOSITOR_OUTPUT_SURFACE_H_

#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "cc/test/fake_web_compositor_software_output_device.h"
#include <public/WebCompositorOutputSurface.h>
#include <public/WebGraphicsContext3D.h>

namespace WebKit {

class FakeWebCompositorOutputSurface : public WebCompositorOutputSurface {
public:
    static inline scoped_ptr<FakeWebCompositorOutputSurface> create(scoped_ptr<WebGraphicsContext3D> context3D)
    {
        return make_scoped_ptr(new FakeWebCompositorOutputSurface(context3D.Pass()));
    }

    static inline scoped_ptr<FakeWebCompositorOutputSurface> createSoftware(scoped_ptr<WebCompositorSoftwareOutputDevice> softwareDevice)
    {
        return make_scoped_ptr(new FakeWebCompositorOutputSurface(softwareDevice.Pass()));
    }

    virtual bool bindToClient(WebCompositorOutputSurfaceClient* client) OVERRIDE
    {
        if (!m_context3D)
            return true;
        DCHECK(client);
        if (!m_context3D->makeContextCurrent())
            return false;
        m_client = client;
        return true;
    }

    virtual const Capabilities& capabilities() const OVERRIDE
    {
        return m_capabilities;
    }

    virtual WebGraphicsContext3D* context3D() const OVERRIDE
    {
        return m_context3D.get();
    }
    virtual WebCompositorSoftwareOutputDevice* softwareDevice() const OVERRIDE
    {
        return m_softwareDevice.get();
    }

    virtual void sendFrameToParentCompositor(const WebCompositorFrame&) OVERRIDE
    {
    }

private:
    explicit FakeWebCompositorOutputSurface(scoped_ptr<WebGraphicsContext3D> context3D)
    {
        m_context3D = context3D.Pass();
    }

    explicit FakeWebCompositorOutputSurface(scoped_ptr<WebCompositorSoftwareOutputDevice> softwareDevice)
    {
        m_softwareDevice = softwareDevice.Pass();
    }

    scoped_ptr<WebGraphicsContext3D> m_context3D;
    scoped_ptr<WebCompositorSoftwareOutputDevice> m_softwareDevice;
    Capabilities m_capabilities;
    WebCompositorOutputSurfaceClient* m_client;
};

} // namespace WebKit

#endif  // CC_TEST_FAKE_WEB_COMPOSITOR_OUTPUT_SURFACE_H_