- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / aura / no_transport_image_transport_factory.cc
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/aura/no_transport_image_transport_factory.h"
6
7 #include "cc/output/context_provider.h"
8 #include "content/common/gpu/client/gl_helper.h"
9 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
10 #include "ui/compositor/compositor.h"
11
12 namespace content {
13
14 namespace {
15
16 class FakeTexture : public ui::Texture {
17  public:
18   FakeTexture(scoped_refptr<cc::ContextProvider> context_provider,
19               float device_scale_factor)
20       : ui::Texture(false, gfx::Size(), device_scale_factor),
21         context_provider_(context_provider),
22         texture_(context_provider_->Context3d()->createTexture()) {}
23
24   virtual unsigned int PrepareTexture() OVERRIDE { return texture_; }
25   virtual WebKit::WebGraphicsContext3D* HostContext3D() OVERRIDE {
26     return context_provider_->Context3d();
27   }
28
29   virtual void Consume(const std::string& mailbox_name,
30                        const gfx::Size& new_size) OVERRIDE {
31     size_ = new_size;
32   }
33
34  private:
35   virtual ~FakeTexture() {
36     context_provider_->Context3d()->deleteTexture(texture_);
37   }
38
39   scoped_refptr<cc::ContextProvider> context_provider_;
40   unsigned texture_;
41   DISALLOW_COPY_AND_ASSIGN(FakeTexture);
42 };
43
44 }  // anonymous namespace
45
46 NoTransportImageTransportFactory::NoTransportImageTransportFactory(
47     scoped_ptr<ui::ContextFactory> context_factory)
48     : context_factory_(context_factory.Pass()) {}
49
50 NoTransportImageTransportFactory::~NoTransportImageTransportFactory() {}
51
52 ui::ContextFactory* NoTransportImageTransportFactory::AsContextFactory() {
53   return context_factory_.get();
54 }
55
56 gfx::GLSurfaceHandle
57 NoTransportImageTransportFactory::CreateSharedSurfaceHandle() {
58   return gfx::GLSurfaceHandle();
59 }
60
61 void NoTransportImageTransportFactory::DestroySharedSurfaceHandle(
62     gfx::GLSurfaceHandle surface) {}
63
64 scoped_refptr<ui::Texture>
65 NoTransportImageTransportFactory::CreateTransportClient(
66     float device_scale_factor) {
67   return new FakeTexture(context_factory_->SharedMainThreadContextProvider(),
68                          device_scale_factor);
69 }
70
71 scoped_refptr<ui::Texture> NoTransportImageTransportFactory::CreateOwnedTexture(
72     const gfx::Size& size,
73     float device_scale_factor,
74     unsigned int texture_id) {
75   return NULL;
76 }
77
78 GLHelper* NoTransportImageTransportFactory::GetGLHelper() {
79   if (!gl_helper_) {
80     context_provider_ = context_factory_->SharedMainThreadContextProvider();
81     gl_helper_.reset(new GLHelper(context_provider_->Context3d(),
82                                   context_provider_->ContextSupport()));
83   }
84   return gl_helper_.get();
85 }
86
87 uint32 NoTransportImageTransportFactory::InsertSyncPoint() { return 0; }
88
89 void NoTransportImageTransportFactory::WaitSyncPoint(uint32 sync_point) {}
90
91 // We don't generate lost context events, so we don't need to keep track of
92 // observers
93 void NoTransportImageTransportFactory::AddObserver(
94     ImageTransportFactoryObserver* observer) {}
95
96 void NoTransportImageTransportFactory::RemoveObserver(
97     ImageTransportFactoryObserver* observer) {}
98
99 }  // namespace content