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. 4 5#include "cc/test/fake_content_layer_client.h" 6 7#include "third_party/skia/include/core/SkCanvas.h" 8#include "ui/gfx/skia_util.h" 9 10namespace cc { 11 12FakeContentLayerClient::FakeContentLayerClient() 13 : fill_with_nonsolid_color_(false), last_canvas_(NULL) { 14} 15 16FakeContentLayerClient::~FakeContentLayerClient() { 17} 18 19void FakeContentLayerClient::PaintContents( 20 SkCanvas* canvas, 21 const gfx::Rect& paint_rect, 22 ContentLayerClient::GraphicsContextStatus gc_status) { 23 last_canvas_ = canvas; 24 last_context_status_ = gc_status; 25 26 canvas->clipRect(gfx::RectToSkRect(paint_rect)); 27 for (RectPaintVector::const_iterator it = draw_rects_.begin(); 28 it != draw_rects_.end(); ++it) { 29 const gfx::RectF& draw_rect = it->first; 30 const SkPaint& paint = it->second; 31 canvas->drawRectCoords(draw_rect.x(), 32 draw_rect.y(), 33 draw_rect.right(), 34 draw_rect.bottom(), 35 paint); 36 } 37 38 for (BitmapVector::const_iterator it = draw_bitmaps_.begin(); 39 it != draw_bitmaps_.end(); ++it) { 40 canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint); 41 } 42 43 // Add a rectangle to the middle that doesn't fill |paint_rect| so that solid 44 // color analysis will fail. 45 if (fill_with_nonsolid_color_) { 46 gfx::RectF draw_rect = paint_rect; 47 draw_rect.Inset(draw_rect.width() / 4.0f, draw_rect.height() / 4.0f); 48 SkPaint paint; 49 canvas->drawRectCoords(draw_rect.x(), 50 draw_rect.y(), 51 draw_rect.right(), 52 draw_rect.bottom(), 53 paint); 54 } 55} 56 57bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } 58 59} // namespace cc 60