1 // Copyright 2014 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.
5 #include "content/browser/compositor/no_transport_image_transport_factory.h"
7 #include "cc/output/context_provider.h"
8 #include "content/common/gpu/client/gl_helper.h"
9 #include "gpu/command_buffer/client/gles2_interface.h"
10 #include "ui/compositor/compositor.h"
16 class FakeTexture : public ui::Texture {
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),
23 context_provider_->ContextGL()->GenTextures(1, &texture_);
26 virtual unsigned int PrepareTexture() OVERRIDE { return texture_; }
28 virtual void Consume(const gpu::Mailbox& mailbox,
29 const gfx::Size& new_size) OVERRIDE {
34 virtual ~FakeTexture() {
35 context_provider_->ContextGL()->DeleteTextures(1, &texture_);
38 scoped_refptr<cc::ContextProvider> context_provider_;
40 DISALLOW_COPY_AND_ASSIGN(FakeTexture);
43 } // anonymous namespace
45 NoTransportImageTransportFactory::NoTransportImageTransportFactory(
46 scoped_ptr<ui::ContextFactory> context_factory)
47 : context_factory_(context_factory.Pass()) {}
49 NoTransportImageTransportFactory::~NoTransportImageTransportFactory() {}
51 ui::ContextFactory* NoTransportImageTransportFactory::AsContextFactory() {
52 return context_factory_.get();
56 NoTransportImageTransportFactory::GetSharedSurfaceHandle() {
57 return gfx::GLSurfaceHandle();
60 scoped_refptr<ui::Texture>
61 NoTransportImageTransportFactory::CreateTransportClient(
62 float device_scale_factor) {
63 return new FakeTexture(context_factory_->SharedMainThreadContextProvider(),
67 scoped_refptr<ui::Texture> NoTransportImageTransportFactory::CreateOwnedTexture(
68 const gfx::Size& size,
69 float device_scale_factor,
70 unsigned int texture_id) {
74 GLHelper* NoTransportImageTransportFactory::GetGLHelper() {
76 context_provider_ = context_factory_->SharedMainThreadContextProvider();
77 gl_helper_.reset(new GLHelper(context_provider_->ContextGL(),
78 context_provider_->ContextSupport()));
80 return gl_helper_.get();
83 // We don't generate lost context events, so we don't need to keep track of
85 void NoTransportImageTransportFactory::AddObserver(
86 ImageTransportFactoryObserver* observer) {}
88 void NoTransportImageTransportFactory::RemoveObserver(
89 ImageTransportFactoryObserver* observer) {}
91 } // namespace content