[Do not revert] Roll-back V8 to version 4.4.63.
[chromium-blink-merge.git] / cc / layers / io_surface_layer_impl.cc
bloba7da986859d5eca6ef391cb55b50cf3efd42c149
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(
70 render_pass, content_bounds(), shared_quad_state, append_quads_data);
72 gfx::Rect quad_rect(content_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 ValidateQuadResources(quad);
92 void IOSurfaceLayerImpl::ReleaseResources() {
93 // We don't have a valid resource ID in the new context; however,
94 // the IOSurface is still valid.
95 DestroyResource();
96 io_surface_changed_ = true;
99 void IOSurfaceLayerImpl::SetIOSurfaceProperties(unsigned io_surface_id,
100 const gfx::Size& size) {
101 if (io_surface_id_ != io_surface_id)
102 io_surface_changed_ = true;
104 io_surface_id_ = io_surface_id;
105 io_surface_size_ = size;
108 const char* IOSurfaceLayerImpl::LayerTypeAsString() const {
109 return "cc::IOSurfaceLayerImpl";
112 } // namespace cc