| Index: content/renderer/gpu/compositor_software_output_device.cc
|
| diff --git a/content/renderer/gpu/compositor_software_output_device.cc b/content/renderer/gpu/compositor_software_output_device.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7b151d4ef42af01f496756db8cb16ac0cfc687df
|
| --- /dev/null
|
| +++ b/content/renderer/gpu/compositor_software_output_device.cc
|
| @@ -0,0 +1,138 @@
|
| +// Copyright (c) 2013 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 "content/renderer/gpu/compositor_software_output_device.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "cc/software_frame_data.h"
|
| +#include "third_party/skia/include/core/SkCanvas.h"
|
| +#include "third_party/skia/include/core/SkDevice.h"
|
| +#include "third_party/skia/include/core/SkPixelRef.h"
|
| +#include "ui/gfx/skia_util.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +class CompareByHandle {
|
| + public:
|
| + CompareByHandle(TransportDIB::Handle handle)
|
| + : handle_(handle) {
|
| + }
|
| +
|
| + bool operator()(const TransportDIB* dib) const {
|
| + return dib->handle() == handle_;
|
| + }
|
| +
|
| + private:
|
| + TransportDIB::Handle handle_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +CompositorSoftwareOutputDevice::CompositorSoftwareOutputDevice()
|
| + : front_buffer_(0),
|
| + last_buffer_(-1),
|
| + num_free_buffers_(0),
|
| + sequence_num_(0) {
|
| +}
|
| +
|
| +CompositorSoftwareOutputDevice::~CompositorSoftwareOutputDevice() {
|
| +}
|
| +
|
| +void CompositorSoftwareOutputDevice::Resize(const gfx::Size& viewport_size) {
|
| + printf("\t\t%dCompositorSoftwareOutputDevice::Resize(%s)\n",
|
| + getpid(), viewport_size.ToString().c_str());
|
| + if (viewport_size_ == viewport_size)
|
| + return;
|
| +
|
| + viewport_size_ = viewport_size;
|
| +
|
| + // Reallocate dibs_ if necessary
|
| + if (dibs_.empty() || dibs_[0]->size() < ViewportSizeInBytes()) {
|
| + dibs_.clear();
|
| + for (int i = 0; i < kNumBuffers; i++)
|
| + dibs_.push_back(CreateDIB());
|
| + }
|
| +
|
| + front_buffer_ = 0;
|
| + last_buffer_ = -1;
|
| + num_free_buffers_ = kNumBuffers;
|
| + printf("\t\t\t%dCompositorSoftwareOutputDevice::Resize(%s)\n",
|
| + getpid(), viewport_size.ToString().c_str());
|
| +}
|
| +
|
| +SkCanvas* CompositorSoftwareOutputDevice::BeginPaint(
|
| + const gfx::Rect& damage_rect) {
|
| + printf("\t\t%dCompositorSoftwareOutputDevice::BeginPaint\n", getpid());
|
| + if (num_free_buffers_ == 0) {
|
| + dibs_.insert(dibs_.begin() + front_buffer_, CreateDIB());
|
| + num_free_buffers_++;
|
| + printf("\t\t\tInserting new buffer dibs.size(): %lu\n", dibs_.size());
|
| + }
|
| +
|
| + TransportDIB* front_dib = dibs_[front_buffer_];
|
| + DCHECK(front_dib);
|
| + printf("\t\t\tRendering to handle: %d\n", front_dib->handle());
|
| +
|
| + // Set up a canvas for the front_dib
|
| + bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
|
| + viewport_size_.width(),
|
| + viewport_size_.height());
|
| + bitmap_.setPixels(front_dib->memory());
|
| + device_ = skia::AdoptRef(new SkDevice(bitmap_));
|
| + canvas_ = skia::AdoptRef(new SkCanvas(device_.get()));
|
| +
|
| + // Copy damage_rect_ from last_buffer_ to front_buffer_
|
| + if (last_buffer_ != -1 && !damage_rect.Contains(damage_rect_)) {
|
| + DCHECK_EQ(std::abs(front_buffer_ - last_buffer_) % dibs_.size(), 1u);
|
| +
|
| + TransportDIB* last_dib = dibs_[last_buffer_];
|
| + SkBitmap back_bitmap;
|
| + back_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
|
| + viewport_size_.width(),
|
| + viewport_size_.height());
|
| + back_bitmap.setPixels(last_dib->memory());
|
| +
|
| + SkRect last_damage = gfx::RectToSkRect(damage_rect_);
|
| + canvas_->drawBitmapRectToRect(back_bitmap, &last_damage, last_damage, NULL);
|
| + }
|
| + damage_rect_ = damage_rect;
|
| +
|
| + return canvas_.get();
|
| +}
|
| +
|
| +void CompositorSoftwareOutputDevice::EndPaint(
|
| + cc::SoftwareFrameData* frame_data) {
|
| + printf("\t\t%dCompositorSoftwareOutputDevice::EndPaint\n", getpid());
|
| + DCHECK_GE(int(dibs_.size()), kNumBuffers);
|
| + DCHECK_LE(0, front_buffer_);
|
| + DCHECK_LT(front_buffer_, int(dibs_.size()));
|
| +
|
| + if (frame_data) {
|
| + frame_data->damage_rect = damage_rect_;
|
| + frame_data->content_dib = dibs_[front_buffer_]->handle();
|
| + }
|
| +
|
| + last_buffer_ = front_buffer_;
|
| + front_buffer_ = (front_buffer_ + 1) % dibs_.size();
|
| + --num_free_buffers_;
|
| + DCHECK_GE(num_free_buffers_, 0);
|
| +}
|
| +
|
| +void CompositorSoftwareOutputDevice::ReclaimDIB(
|
| + TransportDIB::Handle handle) {
|
| + printf("\t\t%dCompositorSoftwareOutputDevice::ReclaimDIB handle %d\n",
|
| + getpid(), handle);
|
| + // The reclaimed handle might not be among the currently
|
| + // active dibs if we got a resize event in the mean time.
|
| + ScopedVector<TransportDIB>::iterator it =
|
| + std::find_if(dibs_.begin(), dibs_.end(), CompareByHandle(handle));
|
| + if (it != dibs_.end())
|
| + ++num_free_buffers_;
|
| +
|
| + DCHECK_LE(num_free_buffers_, int(dibs_.size()));
|
| +}
|
| +
|
| +} // namespace content
|
|
|