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_gl.h" | |
10 #include "ui/gfx/rect.h" | |
11 #include "ui/gfx/transform.h" | |
12 | |
13 namespace { | |
14 | |
15 class AcceleratedSurfaceContainerLinuxGL | |
16 : public AcceleratedSurfaceContainerLinux, public ui::TextureGL { | |
17 public: | |
18 explicit AcceleratedSurfaceContainerLinuxGL(const gfx::Size& size) | |
19 : ui::TextureGL(size) { | |
20 } | |
21 | |
22 virtual ~AcceleratedSurfaceContainerLinuxGL() { } | |
23 virtual void AddRef() { ui::TextureGL::AddRef(); } | |
24 virtual void Release() { ui::TextureGL::Release(); } | |
25 | |
26 virtual bool Initialize(uint64* surface_handle) OVERRIDE { | |
27 ui::SharedResourcesGL* instance = ui::SharedResourcesGL::GetInstance(); | |
28 DCHECK(instance); | |
29 image_transport_client_.reset( | |
30 ImageTransportClient::Create(instance, size_)); | |
31 if (!image_transport_client_.get()) | |
32 return false; | |
33 | |
34 texture_id_ = image_transport_client_->Initialize(surface_handle); | |
35 if (!texture_id_) { | |
36 image_transport_client_.reset(); | |
37 return false; | |
38 } | |
39 return true; | |
40 } | |
41 | |
42 virtual const gfx::Size& GetSize() { | |
43 return ui::TextureGL::size(); | |
44 } | |
45 | |
46 // TextureGL implementation | |
47 virtual void SetCanvas(const SkCanvas& canvas, | |
48 const gfx::Point& origin, | |
49 const gfx::Size& overall_size) OVERRIDE { | |
50 NOTREACHED(); | |
51 } | |
52 | |
53 virtual void Draw(const ui::TextureDrawParams& params, | |
54 const gfx::Rect& clip_bounds_in_texture) OVERRIDE { | |
55 image_transport_client_->Acquire(); | |
56 | |
57 ui::TextureDrawParams modified_params = params; | |
58 if (image_transport_client_->Flipped()) | |
59 modified_params.vertically_flipped = true; | |
60 | |
61 ui::SharedResourcesGL* instance = ui::SharedResourcesGL::GetInstance(); | |
62 DrawInternal(*instance->program_no_swizzle(), | |
63 modified_params, | |
64 clip_bounds_in_texture); | |
65 | |
66 image_transport_client_->Release(); | |
67 } | |
68 | |
69 virtual TransportDIB::Handle Handle() const { | |
70 return image_transport_client_->Handle(); | |
71 } | |
72 | |
73 virtual ui::Texture* GetTexture() { return this; } | |
74 | |
75 private: | |
76 scoped_ptr<ImageTransportClient> image_transport_client_; | |
77 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerLinuxGL); | |
78 }; | |
79 | |
80 } // namespace | |
81 | |
82 // static | |
83 AcceleratedSurfaceContainerLinux* | |
84 AcceleratedSurfaceContainerLinux::Create(const gfx::Size& size) { | |
85 return new AcceleratedSurfaceContainerLinuxGL(size); | |
86 } | |
OLD | NEW |