OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/io_surface_layer_impl.h" | 5 #include "cc/layers/io_surface_layer_impl.h" |
6 | 6 |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "cc/layers/quad_sink.h" | 8 #include "cc/layers/quad_sink.h" |
9 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 9 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
10 #include "cc/output/output_surface.h" | 10 #include "cc/output/output_surface.h" |
11 #include "cc/quads/io_surface_draw_quad.h" | 11 #include "cc/quads/io_surface_draw_quad.h" |
12 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
13 #include "gpu/GLES2/gl2extchromium.h" | 13 #include "gpu/GLES2/gl2extchromium.h" |
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
15 #include "third_party/khronos/GLES2/gl2.h" | 15 #include "third_party/khronos/GLES2/gl2.h" |
16 #include "third_party/khronos/GLES2/gl2ext.h" | 16 #include "third_party/khronos/GLES2/gl2ext.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 IOSurfaceLayerImpl::IOSurfaceLayerImpl(LayerTreeImpl* tree_impl, int id) | 20 IOSurfaceLayerImpl::IOSurfaceLayerImpl(LayerTreeImpl* tree_impl, int id) |
21 : LayerImpl(tree_impl, id), | 21 : LayerImpl(tree_impl, id), |
22 io_surface_id_(0), | 22 io_surface_id_(0), |
23 io_surface_changed_(false), | 23 io_surface_changed_(false), |
24 io_surface_texture_id_(0) {} | 24 io_surface_texture_id_(0) {} |
25 | 25 |
26 IOSurfaceLayerImpl::~IOSurfaceLayerImpl() { | 26 IOSurfaceLayerImpl::~IOSurfaceLayerImpl() { |
27 if (!io_surface_texture_id_) | 27 if (!io_surface_texture_id_) |
28 return; | 28 return; |
29 | 29 |
30 OutputSurface* output_surface = layer_tree_impl()->output_surface(); | 30 DestroyTexture(); |
31 // FIXME: Implement this path for software compositing. | 31 } |
32 WebKit::WebGraphicsContext3D* context3d = output_surface->context3d(); | 32 |
33 if (context3d) | 33 void IOSurfaceLayerImpl::DestroyTexture() { |
34 context3d->deleteTexture(io_surface_texture_id_); | 34 if (io_surface_resource_id_) { |
| 35 ResourceProvider* resource_provider = |
| 36 layer_tree_impl()->resource_provider(); |
| 37 resource_provider->DeleteResource(io_surface_resource_id_); |
| 38 io_surface_resource_id_ = 0; |
| 39 } |
| 40 |
| 41 if (io_surface_texture_id_) { |
| 42 OutputSurface* output_surface = layer_tree_impl()->output_surface(); |
| 43 // FIXME: Implement this path for software compositing. |
| 44 WebKit::WebGraphicsContext3D* context3d = output_surface->context3d(); |
| 45 if (context3d) |
| 46 context3d->deleteTexture(io_surface_texture_id_); |
| 47 io_surface_texture_id_ = 0; |
| 48 } |
35 } | 49 } |
36 | 50 |
37 scoped_ptr<LayerImpl> IOSurfaceLayerImpl::CreateLayerImpl( | 51 scoped_ptr<LayerImpl> IOSurfaceLayerImpl::CreateLayerImpl( |
38 LayerTreeImpl* tree_impl) { | 52 LayerTreeImpl* tree_impl) { |
39 return IOSurfaceLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 53 return IOSurfaceLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
40 } | 54 } |
41 | 55 |
42 void IOSurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 56 void IOSurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
43 LayerImpl::PushPropertiesTo(layer); | 57 LayerImpl::PushPropertiesTo(layer); |
44 | 58 |
45 IOSurfaceLayerImpl* io_surface_layer = | 59 IOSurfaceLayerImpl* io_surface_layer = |
46 static_cast<IOSurfaceLayerImpl*>(layer); | 60 static_cast<IOSurfaceLayerImpl*>(layer); |
47 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_); | 61 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_); |
48 } | 62 } |
49 | 63 |
50 void IOSurfaceLayerImpl::WillDraw(ResourceProvider* resource_provider) { | 64 void IOSurfaceLayerImpl::WillDraw(ResourceProvider* resource_provider) { |
51 LayerImpl::WillDraw(resource_provider); | 65 LayerImpl::WillDraw(resource_provider); |
52 | 66 |
53 if (io_surface_changed_) { | 67 if (io_surface_changed_) { |
54 WebKit::WebGraphicsContext3D* context3d = | 68 WebKit::WebGraphicsContext3D* context3d = |
55 resource_provider->GraphicsContext3D(); | 69 resource_provider->GraphicsContext3D(); |
56 if (!context3d) { | 70 if (!context3d) { |
57 // FIXME: Implement this path for software compositing. | 71 // FIXME: Implement this path for software compositing. |
58 return; | 72 return; |
59 } | 73 } |
60 | 74 |
61 // FIXME: Do this in a way that we can track memory usage. | 75 // FIXME: Do this in a way that we can track memory usage. |
62 if (!io_surface_texture_id_) | 76 if (!io_surface_texture_id_) { |
63 io_surface_texture_id_ = context3d->createTexture(); | 77 io_surface_texture_id_ = context3d->createTexture(); |
| 78 io_surface_resource_id_ = |
| 79 resource_provider->CreateResourceFromExternalTexture( |
| 80 io_surface_texture_id_); |
| 81 } |
64 | 82 |
65 GLC(context3d, context3d->activeTexture(GL_TEXTURE0)); | 83 GLC(context3d, context3d->activeTexture(GL_TEXTURE0)); |
66 GLC(context3d, | 84 GLC(context3d, |
67 context3d->bindTexture(GL_TEXTURE_RECTANGLE_ARB, | 85 context3d->bindTexture(GL_TEXTURE_RECTANGLE_ARB, |
68 io_surface_texture_id_)); | 86 io_surface_texture_id_)); |
69 GLC(context3d, | 87 GLC(context3d, |
70 context3d->texParameteri( | 88 context3d->texParameteri( |
71 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 89 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
72 GLC(context3d, | 90 GLC(context3d, |
73 context3d->texParameteri( | 91 context3d->texParameteri( |
(...skipping 26 matching lines...) Expand all Loading... |
100 quad_sink->UseSharedQuadState(CreateSharedQuadState()); | 118 quad_sink->UseSharedQuadState(CreateSharedQuadState()); |
101 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); | 119 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); |
102 | 120 |
103 gfx::Rect quad_rect(content_bounds()); | 121 gfx::Rect quad_rect(content_bounds()); |
104 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); | 122 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); |
105 scoped_ptr<IOSurfaceDrawQuad> quad = IOSurfaceDrawQuad::Create(); | 123 scoped_ptr<IOSurfaceDrawQuad> quad = IOSurfaceDrawQuad::Create(); |
106 quad->SetNew(shared_quad_state, | 124 quad->SetNew(shared_quad_state, |
107 quad_rect, | 125 quad_rect, |
108 opaque_rect, | 126 opaque_rect, |
109 io_surface_size_, | 127 io_surface_size_, |
110 io_surface_texture_id_, | 128 io_surface_resource_id_, |
111 IOSurfaceDrawQuad::FLIPPED); | 129 IOSurfaceDrawQuad::FLIPPED); |
112 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 130 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); |
113 } | 131 } |
114 | 132 |
115 void IOSurfaceLayerImpl::DumpLayerProperties(std::string* str, | 133 void IOSurfaceLayerImpl::DumpLayerProperties(std::string* str, |
116 int indent) const { | 134 int indent) const { |
117 str->append(IndentString(indent)); | 135 str->append(IndentString(indent)); |
118 base::StringAppendF(str, | 136 base::StringAppendF(str, |
119 "iosurface id: %u texture id: %u\n", | 137 "iosurface id: %u texture id: %u\n", |
120 io_surface_id_, | 138 io_surface_id_, |
121 io_surface_texture_id_); | 139 io_surface_texture_id_); |
122 LayerImpl::DumpLayerProperties(str, indent); | 140 LayerImpl::DumpLayerProperties(str, indent); |
123 } | 141 } |
124 | 142 |
125 void IOSurfaceLayerImpl::DidLoseOutputSurface() { | 143 void IOSurfaceLayerImpl::DidLoseOutputSurface() { |
126 // We don't have a valid texture ID in the new context; however, | 144 // We don't have a valid texture ID in the new context; however, |
127 // the IOSurface is still valid. | 145 // the IOSurface is still valid. |
128 io_surface_texture_id_ = 0; | 146 DestroyTexture(); |
129 io_surface_changed_ = true; | 147 io_surface_changed_ = true; |
130 } | 148 } |
131 | 149 |
132 void IOSurfaceLayerImpl::SetIOSurfaceProperties(unsigned io_surface_id, | 150 void IOSurfaceLayerImpl::SetIOSurfaceProperties(unsigned io_surface_id, |
133 gfx::Size size) { | 151 gfx::Size size) { |
134 if (io_surface_id_ != io_surface_id) | 152 if (io_surface_id_ != io_surface_id) |
135 io_surface_changed_ = true; | 153 io_surface_changed_ = true; |
136 | 154 |
137 io_surface_id_ = io_surface_id; | 155 io_surface_id_ = io_surface_id; |
138 io_surface_size_ = size; | 156 io_surface_size_ = size; |
139 } | 157 } |
140 | 158 |
141 const char* IOSurfaceLayerImpl::LayerTypeAsString() const { | 159 const char* IOSurfaceLayerImpl::LayerTypeAsString() const { |
142 return "IOSurfaceLayer"; | 160 return "IOSurfaceLayer"; |
143 } | 161 } |
144 | 162 |
145 } // namespace cc | 163 } // namespace cc |
OLD | NEW |