Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / layers / io_surface_layer_impl.cc
blob902a73d65b07d107132fb8c33fc986c951019532
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.
5 #include "cc/layers/io_surface_layer_impl.h"
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"
13 namespace cc {
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) {}
21 IOSurfaceLayerImpl::~IOSurfaceLayerImpl() {
22 DestroyResource();
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;
34 scoped_ptr<LayerImpl> IOSurfaceLayerImpl::CreateLayerImpl(
35 LayerTreeImpl* tree_impl) {
36 return IOSurfaceLayerImpl::Create(tree_impl, id());
39 void IOSurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) {
40 LayerImpl::PushPropertiesTo(layer);
42 IOSurfaceLayerImpl* io_surface_layer =
43 static_cast<IOSurfaceLayerImpl*>(layer);
44 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_);
47 bool IOSurfaceLayerImpl::WillDraw(DrawMode draw_mode,
48 ResourceProvider* resource_provider) {
49 if (draw_mode != DRAW_MODE_HARDWARE)
50 return false;
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;
59 return LayerImpl::WillDraw(draw_mode, resource_provider);
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);
69 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
70 append_quads_data);
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;
80 IOSurfaceDrawQuad* quad =
81 render_pass->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
82 quad->SetNew(shared_quad_state,
83 quad_rect,
84 opaque_rect,
85 visible_quad_rect,
86 io_surface_size_,
87 io_surface_resource_id_,
88 IOSurfaceDrawQuad::FLIPPED,
89 false);
90 ValidateQuadResources(quad);
93 void IOSurfaceLayerImpl::ReleaseResources() {
94 // We don't have a valid resource ID in the new context; however,
95 // the IOSurface is still valid.
96 DestroyResource();
97 io_surface_changed_ = true;
100 void IOSurfaceLayerImpl::SetIOSurfaceProperties(unsigned io_surface_id,
101 const gfx::Size& size) {
102 if (io_surface_id_ != io_surface_id)
103 io_surface_changed_ = true;
105 io_surface_id_ = io_surface_id;
106 io_surface_size_ = size;
109 const char* IOSurfaceLayerImpl::LayerTypeAsString() const {
110 return "cc::IOSurfaceLayerImpl";
113 } // namespace cc