190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef CC_OUTPUT_COPY_OUTPUT_REQUEST_H_ 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define CC_OUTPUT_COPY_OUTPUT_REQUEST_H_ 790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/callback.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "cc/base/cc_export.h" 11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "cc/resources/texture_mailbox.h" 12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/gfx/rect.h" 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class SkBitmap; 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace cc { 177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class CopyOutputResult; 18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class SingleReleaseCallback; 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CC_EXPORT CopyOutputRequest { 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) typedef base::Callback<void(scoped_ptr<CopyOutputResult> result)> 237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CopyOutputRequestCallback; 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static scoped_ptr<CopyOutputRequest> CreateEmptyRequest() { 267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return make_scoped_ptr(new CopyOutputRequest); 277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static scoped_ptr<CopyOutputRequest> CreateRequest( 297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const CopyOutputRequestCallback& result_callback) { 307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return make_scoped_ptr(new CopyOutputRequest(false, result_callback)); 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static scoped_ptr<CopyOutputRequest> CreateBitmapRequest( 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const CopyOutputRequestCallback& result_callback) { 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return make_scoped_ptr(new CopyOutputRequest(true, result_callback)); 357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static scoped_ptr<CopyOutputRequest> CreateRelayRequest( 377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const CopyOutputRequest& original_request, 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const CopyOutputRequestCallback& result_callback); 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ~CopyOutputRequest(); 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool IsEmpty() const { return result_callback_.is_null(); } 43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool force_bitmap_result() const { return force_bitmap_result_; } 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 46eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // By default copy requests copy the entire layer's subtree output. If an 47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // area is given, then the intersection of this rect (in layer space) with 48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // the layer's subtree output will be returned. 49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void set_area(gfx::Rect area) { 50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch has_area_ = true; 51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch area_ = area; 52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool has_area() const { return has_area_; } 54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch gfx::Rect area() const { return area_; } 55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // By default copy requests create a new TextureMailbox to return contents 57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // in. This allows a client to provide a TextureMailbox, and the compositor 58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // will place the result inside the TextureMailbox. 59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void SetTextureMailbox(const TextureMailbox& texture_mailbox); 60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool has_texture_mailbox() const { return has_texture_mailbox_; } 61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const TextureMailbox& texture_mailbox() const { return texture_mailbox_; } 62a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void SendEmptyResult(); 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void SendBitmapResult(scoped_ptr<SkBitmap> bitmap); 657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void SendTextureResult(gfx::Size size, 66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const TextureMailbox& texture_mailbox, 67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) scoped_ptr<SingleReleaseCallback> release_callback); 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void SendResult(scoped_ptr<CopyOutputResult> result); 707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CopyOutputRequest(); 73a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CopyOutputRequest(bool force_bitmap_result, 74a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const CopyOutputRequestCallback& result_callback); 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool force_bitmap_result_; 77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool has_area_; 78a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool has_texture_mailbox_; 79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch gfx::Rect area_; 80a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) TextureMailbox texture_mailbox_; 817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CopyOutputRequestCallback result_callback_; 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace cc 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // CC_OUTPUT_COPY_OUTPUT_REQUEST_H_ 87