OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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/renderer_host/accelerated_surface_container_linux.h" | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "content/browser/renderer_host/image_transport_client.h" | |
9 #include "ui/gfx/compositor/compositor_cc.h" | |
10 #include "ui/gfx/gl/gl_bindings.h" | |
11 #include "ui/gfx/gl/scoped_make_current.h" | |
12 #include "ui/gfx/rect.h" | |
13 #include "ui/gfx/transform.h" | |
14 | |
15 namespace { | |
16 | |
17 class AcceleratedSurfaceContainerLinuxCC | |
18 : public AcceleratedSurfaceContainerLinux, public ui::TextureCC { | |
19 public: | |
20 explicit AcceleratedSurfaceContainerLinuxCC(const gfx::Size& size) | |
21 : acquired_(false) { | |
22 size_ = size; | |
23 } | |
24 | |
25 virtual ~AcceleratedSurfaceContainerLinuxCC() { | |
26 if (texture_id_) { | |
27 ui::SharedResourcesCC* instance = ui::SharedResourcesCC::GetInstance(); | |
28 DCHECK(instance); | |
29 scoped_ptr<gfx::ScopedMakeCurrent> bind(instance->GetScopedMakeCurrent()); | |
30 glDeleteTextures(1, &texture_id_); | |
31 } | |
32 | |
33 if (image_transport_client_.get()) | |
34 image_transport_client_->Release(); | |
35 } | |
36 | |
37 virtual void AddRef() { ui::TextureCC::AddRef(); } | |
38 virtual void Release() { ui::TextureCC::Release(); } | |
39 | |
40 virtual bool Initialize(uint64* surface_handle) OVERRIDE { | |
41 ui::SharedResourcesCC* instance = ui::SharedResourcesCC::GetInstance(); | |
42 DCHECK(instance); | |
43 image_transport_client_.reset( | |
44 ImageTransportClient::Create(instance, size_)); | |
45 if (!image_transport_client_.get()) | |
46 return false; | |
47 | |
48 texture_id_ = image_transport_client_->Initialize(surface_handle); | |
49 if (!texture_id_) { | |
50 image_transport_client_.reset(); | |
51 return false; | |
52 } | |
53 flipped_ = image_transport_client_->Flipped(); | |
54 return true; | |
55 } | |
56 | |
57 virtual const gfx::Size& GetSize() { | |
58 return ui::TextureCC::size(); | |
59 } | |
60 | |
61 // TextureCC implementation | |
62 virtual void Update() OVERRIDE { | |
63 ui::SharedResourcesCC* instance = ui::SharedResourcesCC::GetInstance(); | |
64 DCHECK(instance); | |
65 scoped_ptr<gfx::ScopedMakeCurrent> bind(instance->GetScopedMakeCurrent()); | |
66 if (acquired_) | |
67 image_transport_client_->Release(); | |
68 else | |
69 acquired_ = true; | |
70 image_transport_client_->Acquire(); | |
71 } | |
72 | |
73 virtual TransportDIB::Handle Handle() const { | |
74 return image_transport_client_->Handle(); | |
75 } | |
76 | |
77 virtual ui::Texture* GetTexture() { return this; } | |
78 | |
79 private: | |
80 scoped_ptr<ImageTransportClient> image_transport_client_; | |
81 bool acquired_; | |
82 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerLinuxCC); | |
83 }; | |
84 | |
85 } // namespace | |
86 | |
87 // static | |
88 AcceleratedSurfaceContainerLinux* | |
89 AcceleratedSurfaceContainerLinux::Create(const gfx::Size& size) { | |
90 return new AcceleratedSurfaceContainerLinuxCC(size); | |
91 } | |
OLD | NEW |