| Index: webkit/tools/test_shell/simple_webpaintsurface_impl.cc
|
| ===================================================================
|
| --- webkit/tools/test_shell/simple_webpaintsurface_impl.cc (revision 0)
|
| +++ webkit/tools/test_shell/simple_webpaintsurface_impl.cc (revision 0)
|
| @@ -0,0 +1,126 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "webkit/tools/test_shell/simple_webpaintsurface_impl.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "gfx/blit.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPaintBuffer.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPaintSurfaceClient.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
|
| +#include "webkit/glue/webkit_glue.h"
|
| +
|
| +using WebKit::WebCanvas;
|
| +using WebKit::WebPaintBuffer;
|
| +using WebKit::WebPaintSurfaceClient;
|
| +using WebKit::WebPoint;
|
| +using WebKit::WebRect;
|
| +using WebKit::WebSize;
|
| +
|
| +namespace {
|
| +
|
| +class SimplePaintBuffer : public WebPaintBuffer {
|
| + public:
|
| + SimplePaintBuffer(const gfx::Size& size)
|
| + : canvas_(size.width(), size.height(), true) {
|
| + }
|
| +
|
| + virtual ~SimplePaintBuffer() {
|
| + }
|
| +
|
| + SkCanvas* skia_canvas() { return &canvas_; }
|
| +
|
| + // WebPaintBuffer methods:
|
| + virtual WebCanvas* canvas() { return webkit_glue::ToWebCanvas(&canvas_); }
|
| +
|
| + private:
|
| + skia::PlatformCanvas canvas_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +SimpleWebPaintSurfaceImpl::SimpleWebPaintSurfaceImpl(Delegate* delegate,
|
| + const gfx::Size& size)
|
| + : delegate_(delegate),
|
| + size_(size),
|
| + canvas_(size.width(), size.height(), true),
|
| + client_(NULL),
|
| + flushing_(false) {
|
| +}
|
| +
|
| +SimpleWebPaintSurfaceImpl::~SimpleWebPaintSurfaceImpl() {
|
| + flushing_ = false;
|
| + if (client_) {
|
| + client_->didReset();
|
| + client_->willDestroy();
|
| + }
|
| +}
|
| +
|
| +void SimpleWebPaintSurfaceImpl::DidCopyPaintSurface() {
|
| + if (flushing_) {
|
| + flushing_ = false;
|
| + if (client_)
|
| + client_->didFlush();
|
| + }
|
| +}
|
| +
|
| +void SimpleWebPaintSurfaceImpl::setClient(WebPaintSurfaceClient* client) {
|
| + client_ = client;
|
| +}
|
| +
|
| +WebPaintBuffer* SimpleWebPaintSurfaceImpl::createBuffer(const WebSize& size) {
|
| + return new SimplePaintBuffer(size);
|
| +}
|
| +
|
| +void SimpleWebPaintSurfaceImpl::paint(WebPaintBuffer* buffer,
|
| + const WebPoint& destination_point,
|
| + const WebRect& source_rect) {
|
| + DCHECK(!flushing_);
|
| +
|
| + SimplePaintBuffer* simple_buffer = static_cast<SimplePaintBuffer*>(buffer);
|
| + SkCanvas* canvas = simple_buffer->skia_canvas();
|
| +
|
| + const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false);
|
| +
|
| + SkPaint paint;
|
| + paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
| +
|
| + SkIRect src_irect = SkIRect::MakeXYWH(source_rect.x,
|
| + source_rect.y,
|
| + source_rect.width,
|
| + source_rect.height);
|
| + SkRect dest_rect = SkRect::MakeXYWH(SkIntToScalar(destination_point.x),
|
| + SkIntToScalar(destination_point.y),
|
| + SkIntToScalar(source_rect.width),
|
| + SkIntToScalar(source_rect.height));
|
| + canvas_.drawBitmapRect(bitmap, &src_irect, dest_rect, &paint);
|
| +
|
| + damage_bounds_ = damage_bounds_.Union(
|
| + gfx::Rect(destination_point.x,
|
| + destination_point.y,
|
| + source_rect.width,
|
| + source_rect.height));
|
| +}
|
| +
|
| +void SimpleWebPaintSurfaceImpl::scroll(const WebRect& clip_rect,
|
| + const WebPoint& scroll_delta) {
|
| + DCHECK(!flushing_);
|
| +
|
| + gfx::ScrollCanvas(&canvas_, clip_rect, scroll_delta);
|
| +
|
| + damage_bounds_ = damage_bounds_.Union(clip_rect);
|
| +}
|
| +
|
| +bool SimpleWebPaintSurfaceImpl::flush() {
|
| + DCHECK(!flushing_);
|
| +
|
| + gfx::Rect bounds = damage_bounds_;
|
| + damage_bounds_ = gfx::Rect();
|
| + flushing_ = true;
|
| +
|
| + delegate_->DidModifyPaintSurface(bounds);
|
| + return true;
|
| +}
|
|
|
| Property changes on: webkit\tools\test_shell\simple_webpaintsurface_impl.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|