summaryrefslogtreecommitdiffstats
path: root/cc/software_output_device.cc
blob: 1e693e71b904548a9dcca2493d005600cabbce2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 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 "cc/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"

namespace cc {

SoftwareOutputDevice::SoftwareOutputDevice() {}

SoftwareOutputDevice::~SoftwareOutputDevice() {}

void SoftwareOutputDevice::Resize(const gfx::Size& viewport_size) {
  if (viewport_size_ == viewport_size)
    return;

  viewport_size_ = viewport_size;
  device_ = skia::AdoptRef(new SkDevice(SkBitmap::kARGB_8888_Config,
      viewport_size.width(), viewport_size.height(), true));
  canvas_ = skia::AdoptRef(new SkCanvas(device_.get()));
}

SkCanvas* SoftwareOutputDevice::BeginPaint(const gfx::Rect& damage_rect) {
  DCHECK(device_);
  damage_rect_ = damage_rect;
  return canvas_.get();
}

void SoftwareOutputDevice::EndPaint(SoftwareFrameData* frame_data) {
  DCHECK(device_);
  if (frame_data) {
    frame_data->damage_rect = damage_rect_;
    frame_data->content_dib = TransportDIB::DefaultHandleValue();
  }
}

void SoftwareOutputDevice::CopyToBitmap(
    const gfx::Rect& rect, SkBitmap* output) {
  DCHECK(device_);
  SkIRect invertRect = SkIRect::MakeXYWH(
      rect.x(), viewport_size_.height() - rect.bottom(),
      rect.width(), rect.height());
  const SkBitmap& bitmap = device_->accessBitmap(false);
  bitmap.extractSubset(output, invertRect);
}

void SoftwareOutputDevice::Scroll(
    const gfx::Vector2d& delta, const gfx::Rect& clip_rect) {
  NOTIMPLEMENTED();
}

void SoftwareOutputDevice::ReclaimDIB(TransportDIB::Handle handle) {
  NOTIMPLEMENTED();
}

}  // namespace cc