forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompositing_recorder.cc
41 lines (33 loc) · 1.12 KB
/
compositing_recorder.cc
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
// Copyright 2015 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 "ui/compositor/compositing_recorder.h"
#include "cc/playback/compositing_display_item.h"
#include "cc/playback/display_item_list.h"
#include "ui/compositor/paint_context.h"
#include "ui/gfx/canvas.h"
namespace ui {
CompositingRecorder::CompositingRecorder(const PaintContext& context,
uint8_t alpha)
: context_(context), saved_(alpha < 255) {
if (!saved_)
return;
if (context_.canvas_) {
context_.canvas_->SaveLayerAlpha(alpha);
} else {
auto* item =
context_.list_->CreateAndAppendItem<cc::CompositingDisplayItem>();
item->SetNew(alpha, SkXfermode::kSrcOver_Mode, nullptr /* no bounds */,
skia::RefPtr<SkColorFilter>());
}
}
CompositingRecorder::~CompositingRecorder() {
if (!saved_)
return;
if (context_.canvas_) {
context_.canvas_->Restore();
} else {
context_.list_->CreateAndAppendItem<cc::EndCompositingDisplayItem>();
}
}
} // namespace ui