| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/layers/io_surface_layer_impl.h" | |
| 6 | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "cc/output/output_surface.h" | |
| 9 #include "cc/quads/io_surface_draw_quad.h" | |
| 10 #include "cc/trees/layer_tree_impl.h" | |
| 11 #include "cc/trees/occlusion.h" | |
| 12 | |
| 13 namespace cc { | |
| 14 | |
| 15 IOSurfaceLayerImpl::IOSurfaceLayerImpl(LayerTreeImpl* tree_impl, int id) | |
| 16 : LayerImpl(tree_impl, id), | |
| 17 io_surface_id_(0), | |
| 18 io_surface_changed_(false), | |
| 19 io_surface_resource_id_(0) {} | |
| 20 | |
| 21 IOSurfaceLayerImpl::~IOSurfaceLayerImpl() { | |
| 22 DestroyResource(); | |
| 23 } | |
| 24 | |
| 25 void IOSurfaceLayerImpl::DestroyResource() { | |
| 26 if (io_surface_resource_id_) { | |
| 27 ResourceProvider* resource_provider = | |
| 28 layer_tree_impl()->resource_provider(); | |
| 29 resource_provider->DeleteResource(io_surface_resource_id_); | |
| 30 io_surface_resource_id_ = 0; | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 std::unique_ptr<LayerImpl> IOSurfaceLayerImpl::CreateLayerImpl( | |
| 35 LayerTreeImpl* tree_impl) { | |
| 36 return IOSurfaceLayerImpl::Create(tree_impl, id()); | |
| 37 } | |
| 38 | |
| 39 void IOSurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) { | |
| 40 LayerImpl::PushPropertiesTo(layer); | |
| 41 | |
| 42 IOSurfaceLayerImpl* io_surface_layer = | |
| 43 static_cast<IOSurfaceLayerImpl*>(layer); | |
| 44 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_); | |
| 45 } | |
| 46 | |
| 47 bool IOSurfaceLayerImpl::WillDraw(DrawMode draw_mode, | |
| 48 ResourceProvider* resource_provider) { | |
| 49 if (draw_mode != DRAW_MODE_HARDWARE) | |
| 50 return false; | |
| 51 | |
| 52 if (io_surface_changed_) { | |
| 53 DestroyResource(); | |
| 54 io_surface_resource_id_ = resource_provider->CreateResourceFromIOSurface( | |
| 55 io_surface_size_, io_surface_id_); | |
| 56 io_surface_changed_ = false; | |
| 57 } | |
| 58 | |
| 59 return LayerImpl::WillDraw(draw_mode, resource_provider); | |
| 60 } | |
| 61 | |
| 62 void IOSurfaceLayerImpl::AppendQuads( | |
| 63 RenderPass* render_pass, | |
| 64 AppendQuadsData* append_quads_data) { | |
| 65 SharedQuadState* shared_quad_state = | |
| 66 render_pass->CreateAndAppendSharedQuadState(); | |
| 67 PopulateSharedQuadState(shared_quad_state); | |
| 68 | |
| 69 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state, | |
| 70 append_quads_data); | |
| 71 | |
| 72 gfx::Rect quad_rect(bounds()); | |
| 73 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); | |
| 74 gfx::Rect visible_quad_rect = | |
| 75 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
| 76 quad_rect); | |
| 77 if (visible_quad_rect.IsEmpty()) | |
| 78 return; | |
| 79 | |
| 80 IOSurfaceDrawQuad* quad = | |
| 81 render_pass->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>(); | |
| 82 quad->SetNew(shared_quad_state, quad_rect, opaque_rect, visible_quad_rect, | |
| 83 io_surface_size_, io_surface_resource_id_, | |
| 84 IOSurfaceDrawQuad::FLIPPED); | |
| 85 ValidateQuadResources(quad); | |
| 86 } | |
| 87 | |
| 88 void IOSurfaceLayerImpl::ReleaseResources() { | |
| 89 // We don't have a valid resource ID in the new context; however, | |
| 90 // the IOSurface is still valid. | |
| 91 DestroyResource(); | |
| 92 io_surface_changed_ = true; | |
| 93 } | |
| 94 | |
| 95 void IOSurfaceLayerImpl::SetIOSurfaceProperties(unsigned io_surface_id, | |
| 96 const gfx::Size& size) { | |
| 97 if (io_surface_id_ != io_surface_id) | |
| 98 io_surface_changed_ = true; | |
| 99 | |
| 100 io_surface_id_ = io_surface_id; | |
| 101 io_surface_size_ = size; | |
| 102 } | |
| 103 | |
| 104 const char* IOSurfaceLayerImpl::LayerTypeAsString() const { | |
| 105 return "cc::IOSurfaceLayerImpl"; | |
| 106 } | |
| 107 | |
| 108 } // namespace cc | |
| OLD | NEW |