Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: content/renderer/gpu/compositor_software_output_device.cc

Issue 12340015: [CLOSED] Big patch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 "content/renderer/gpu/compositor_software_output_device.h"
6
7 #include "base/logging.h"
8 #include "cc/software_frame_data.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkDevice.h"
11 #include "third_party/skia/include/core/SkPixelRef.h"
12 #include "ui/gfx/skia_util.h"
13
14 namespace content {
15
16 namespace {
17
18 class CompareByHandle {
19 public:
20 CompareByHandle(TransportDIB::Handle handle)
21 : handle_(handle) {
22 }
23
24 bool operator()(const TransportDIB* dib) const {
25 return dib->handle() == handle_;
26 }
27
28 private:
29 TransportDIB::Handle handle_;
30 };
31
32 } // namespace
33
34 CompositorSoftwareOutputDevice::CompositorSoftwareOutputDevice()
35 : front_buffer_(0),
36 last_buffer_(-1),
37 num_free_buffers_(0),
38 sequence_num_(0) {
39 }
40
41 CompositorSoftwareOutputDevice::~CompositorSoftwareOutputDevice() {
42 }
43
44 void CompositorSoftwareOutputDevice::Resize(const gfx::Size& viewport_size) {
45 printf("\t\t%dCompositorSoftwareOutputDevice::Resize(%s)\n",
46 getpid(), viewport_size.ToString().c_str());
47 if (viewport_size_ == viewport_size)
48 return;
49
50 viewport_size_ = viewport_size;
51
52 // Reallocate dibs_ if necessary
53 if (dibs_.empty() || dibs_[0]->size() < ViewportSizeInBytes()) {
54 dibs_.clear();
55 for (int i = 0; i < kNumBuffers; i++)
56 dibs_.push_back(CreateDIB());
57 }
58
59 front_buffer_ = 0;
60 last_buffer_ = -1;
61 num_free_buffers_ = kNumBuffers;
62 printf("\t\t\t%dCompositorSoftwareOutputDevice::Resize(%s)\n",
63 getpid(), viewport_size.ToString().c_str());
64 }
65
66 SkCanvas* CompositorSoftwareOutputDevice::BeginPaint(
67 const gfx::Rect& damage_rect) {
68 printf("\t\t%dCompositorSoftwareOutputDevice::BeginPaint\n", getpid());
69 if (num_free_buffers_ == 0) {
70 dibs_.insert(dibs_.begin() + front_buffer_, CreateDIB());
71 num_free_buffers_++;
72 printf("\t\t\tInserting new buffer dibs.size(): %lu\n", dibs_.size());
73 }
74
75 TransportDIB* front_dib = dibs_[front_buffer_];
76 DCHECK(front_dib);
77 printf("\t\t\tRendering to handle: %d\n", front_dib->handle());
78
79 // Set up a canvas for the front_dib
80 bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
81 viewport_size_.width(),
82 viewport_size_.height());
83 bitmap_.setPixels(front_dib->memory());
84 device_ = skia::AdoptRef(new SkDevice(bitmap_));
85 canvas_ = skia::AdoptRef(new SkCanvas(device_.get()));
86
87 // Copy damage_rect_ from last_buffer_ to front_buffer_
88 if (last_buffer_ != -1 && !damage_rect.Contains(damage_rect_)) {
89 DCHECK_EQ(std::abs(front_buffer_ - last_buffer_) % dibs_.size(), 1u);
90
91 TransportDIB* last_dib = dibs_[last_buffer_];
92 SkBitmap back_bitmap;
93 back_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
94 viewport_size_.width(),
95 viewport_size_.height());
96 back_bitmap.setPixels(last_dib->memory());
97
98 SkRect last_damage = gfx::RectToSkRect(damage_rect_);
99 canvas_->drawBitmapRectToRect(back_bitmap, &last_damage, last_damage, NULL);
100 }
101 damage_rect_ = damage_rect;
102
103 return canvas_.get();
104 }
105
106 void CompositorSoftwareOutputDevice::EndPaint(
107 cc::SoftwareFrameData* frame_data) {
108 printf("\t\t%dCompositorSoftwareOutputDevice::EndPaint\n", getpid());
109 DCHECK_GE(int(dibs_.size()), kNumBuffers);
110 DCHECK_LE(0, front_buffer_);
111 DCHECK_LT(front_buffer_, int(dibs_.size()));
112
113 if (frame_data) {
114 frame_data->damage_rect = damage_rect_;
115 frame_data->content_dib = dibs_[front_buffer_]->handle();
116 }
117
118 last_buffer_ = front_buffer_;
119 front_buffer_ = (front_buffer_ + 1) % dibs_.size();
120 --num_free_buffers_;
121 DCHECK_GE(num_free_buffers_, 0);
122 }
123
124 void CompositorSoftwareOutputDevice::ReclaimDIB(
125 TransportDIB::Handle handle) {
126 printf("\t\t%dCompositorSoftwareOutputDevice::ReclaimDIB handle %d\n",
127 getpid(), handle);
128 // The reclaimed handle might not be among the currently
129 // active dibs if we got a resize event in the mean time.
130 ScopedVector<TransportDIB>::iterator it =
131 std::find_if(dibs_.begin(), dibs_.end(), CompareByHandle(handle));
132 if (it != dibs_.end())
133 ++num_free_buffers_;
134
135 DCHECK_LE(num_free_buffers_, int(dibs_.size()));
136 }
137
138 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gpu/compositor_software_output_device.h ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698