PixelDumpSupportEfl.cpp 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. * Copyright (C) 2012 Intel Corporation. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  18. * its contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  22. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  25. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  28. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "config.h"
  33. #include "DumpRenderTree.h"
  34. #include "DumpRenderTreeChrome.h"
  35. #include "IntRect.h"
  36. #include "PixelDumpSupportCairo.h"
  37. #include "RefPtrCairo.h"
  38. #include "WebCoreSupport/DumpRenderTreeSupportEfl.h"
  39. #include "ewk_view.h"
  40. PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool, bool, bool, bool drawSelectionRect)
  41. {
  42. Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(browser->mainView()));
  43. Ewk_View_Private_Data* privateData = static_cast<Ewk_View_Private_Data*>(smartData->_priv);
  44. const Evas_Object* mainFrame = browser->mainFrame();
  45. int x, y, width, height;
  46. evas_object_geometry_get(browser->mainFrame(), &x, &y, &width, &height);
  47. const Eina_Rectangle rect = { x, y, width, height };
  48. RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, rect.w, rect.h));
  49. RefPtr<cairo_t> context = adoptRef(cairo_create(surface.get()));
  50. if (!ewk_view_paint(privateData, context.get(), &rect))
  51. return 0;
  52. if (DumpRenderTreeSupportEfl::isTrackingRepaints(mainFrame)) {
  53. cairo_push_group(context.get());
  54. // Paint the gray mask over the original image.
  55. cairo_set_source_rgba(context.get(), 0, 0, 0, 0.66);
  56. cairo_paint(context.get());
  57. // Paint transparent rectangles over the mask to show the repainted regions.
  58. cairo_set_source_rgba(context.get(), 0, 0, 0, 0);
  59. cairo_set_operator(context.get(), CAIRO_OPERATOR_SOURCE);
  60. Eina_List* repaintRects = DumpRenderTreeSupportEfl::trackedRepaintRects(mainFrame);
  61. void* iter = 0;
  62. EINA_LIST_FREE(repaintRects, iter) {
  63. Eina_Rectangle* rect = static_cast<Eina_Rectangle*>(iter);
  64. cairo_rectangle(context.get(), rect->x, rect->y, rect->w, rect->h);
  65. cairo_fill(context.get());
  66. eina_rectangle_free(rect);
  67. }
  68. cairo_pop_group_to_source(context.get());
  69. cairo_paint(context.get());
  70. }
  71. if (drawSelectionRect) {
  72. const WebCore::IntRect selectionRect = DumpRenderTreeSupportEfl::selectionRectangle(mainFrame);
  73. if (!selectionRect.isEmpty()) {
  74. cairo_set_line_width(context.get(), 1.0);
  75. cairo_rectangle(context.get(), selectionRect.x(), selectionRect.y(), selectionRect.width(), selectionRect.height());
  76. cairo_set_source_rgba(context.get(), 1.0, 0.0, 0.0, 1.0);
  77. cairo_stroke(context.get());
  78. }
  79. }
  80. return BitmapContext::createByAdoptingBitmapAndContext(0, context.release().leakRef());
  81. }