initial import
[vuplus_webkit] / Tools / DumpRenderTree / efl / PixelDumpSupportEfl.cpp
1 /*
2  * Copyright (C) 2009 Zan Dobersek <zandobersek@gmail.com>
3  * Copyright (C) 2010 Igalia S.L.
4  * Copyright (C) 2011 ProFUSION Embedded Systems
5  * Copyright (C) 2011 Samsung Electronics
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1.  Redistributions of source code must retain the above copyright
12  *     notice, this list of conditions and the following disclaimer.
13  * 2.  Redistributions in binary form must reproduce the above copyright
14  *     notice, this list of conditions and the following disclaimer in the
15  *     documentation and/or other materials provided with the distribution.
16  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17  *     its contributors may be used to endorse or promote products derived
18  *     from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #include "config.h"
33
34 #include "DumpRenderTree.h"
35 #include "PixelDumpSupportCairo.h"
36 #include "RefPtrCairo.h"
37 #include "ewk_private.h"
38
39 PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool, bool, bool, bool drawSelectionRect)
40 {
41     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(browser));
42     Ewk_View_Private_Data* privateData = static_cast<Ewk_View_Private_Data*>(smartData->_priv);
43
44     int width, height;
45     if (!ewk_frame_contents_size_get(mainFrame, &width, &height))
46         return 0;
47
48     RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height));
49     RefPtr<cairo_t> context = adoptRef(cairo_create(surface.get()));
50
51     const Eina_Rectangle rect = { 0, 0, width, height };
52     if (!ewk_view_paint_contents(privateData, context.get(), &rect))
53         return 0;
54
55     if (drawSelectionRect) {
56         int x, y, rectWidth, rectHeight;
57
58         if (ewk_frame_selection_rectangle_get(mainFrame, &x, &y, &rectWidth, &rectHeight)) {
59             cairo_set_line_width(context.get(), 1.0);
60             cairo_rectangle(context.get(), x, y, rectWidth, rectHeight);
61             cairo_set_source_rgba(context.get(), 1.0, 0.0, 0.0, 1.0);
62             cairo_stroke(context.get());
63         }
64     }
65
66     return BitmapContext::createByAdoptingBitmapAndContext(0, context.release().leakRef());
67 }