/src/mozilla-central/gfx/layers/composite/PaintCounter.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "mozilla/gfx/Point.h" // for IntSize, Point |
8 | | #include "mozilla/gfx/Rect.h" // for Rect |
9 | | #include "mozilla/gfx/Types.h" // for Color, SurfaceFormat |
10 | | #include "mozilla/layers/Compositor.h" // for Compositor |
11 | | #include "mozilla/layers/CompositorTypes.h" |
12 | | #include "mozilla/layers/Effects.h" // for Effect, EffectChain, etc |
13 | | #include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration |
14 | | #include "mozilla/Sprintf.h" |
15 | | |
16 | | #include "mozilla/gfx/HelpersSkia.h" |
17 | | #include "PaintCounter.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace layers { |
21 | | |
22 | | using namespace mozilla::gfx; |
23 | | |
24 | | // Positioned below the chrome UI |
25 | | IntRect PaintCounter::mRect = IntRect(0, 175, 300, 60); |
26 | | |
27 | | PaintCounter::PaintCounter() |
28 | 0 | { |
29 | 0 | mFormat = SurfaceFormat::B8G8R8A8; |
30 | 0 | mSurface = Factory::CreateDataSourceSurface(mRect.Size(), mFormat); |
31 | 0 | mMap.emplace(mSurface, DataSourceSurface::READ_WRITE); |
32 | 0 | mStride = mMap->GetStride(); |
33 | 0 |
|
34 | 0 | mCanvas = |
35 | 0 | SkCanvas::MakeRasterDirect(MakeSkiaImageInfo(mRect.Size(), mFormat), |
36 | 0 | mMap->GetData(), mStride); |
37 | 0 | mCanvas->clear(SK_ColorWHITE); |
38 | 0 | } |
39 | | |
40 | | PaintCounter::~PaintCounter() |
41 | 0 | { |
42 | 0 | mSurface = nullptr; |
43 | 0 | mTextureSource = nullptr; |
44 | 0 | mTexturedEffect = nullptr; |
45 | 0 | } |
46 | | |
47 | | void |
48 | 0 | PaintCounter::Draw(Compositor* aCompositor, TimeDuration aPaintTime, TimeDuration aCompositeTime) { |
49 | 0 | char buffer[48]; |
50 | 0 | SprintfLiteral(buffer, "P: %.2f C: %.2f", |
51 | 0 | aPaintTime.ToMilliseconds(), |
52 | 0 | aCompositeTime.ToMilliseconds()); |
53 | 0 |
|
54 | 0 | SkPaint paint; |
55 | 0 | paint.setTextSize(32); |
56 | 0 | paint.setColor(SkColorSetRGB(0, 255, 0)); |
57 | 0 | paint.setAntiAlias(true); |
58 | 0 |
|
59 | 0 | mCanvas->clear(SK_ColorTRANSPARENT); |
60 | 0 | mCanvas->drawText(buffer, strlen(buffer), 10, 30, paint); |
61 | 0 | mCanvas->flush(); |
62 | 0 |
|
63 | 0 | if (!mTextureSource) { |
64 | 0 | mTextureSource = aCompositor->CreateDataTextureSource(); |
65 | 0 | mTexturedEffect = CreateTexturedEffect(mFormat, mTextureSource, |
66 | 0 | SamplingFilter::POINT, true); |
67 | 0 | mTexturedEffect->mTextureCoords = Rect(0, 0, 1.0f, 1.0f); |
68 | 0 | } |
69 | 0 |
|
70 | 0 | mTextureSource->Update(mSurface); |
71 | 0 |
|
72 | 0 | EffectChain effectChain; |
73 | 0 | effectChain.mPrimaryEffect = mTexturedEffect; |
74 | 0 |
|
75 | 0 | gfx::Matrix4x4 identity; |
76 | 0 | Rect rect(mRect.X(), mRect.Y(), mRect.Width(), mRect.Height()); |
77 | 0 | aCompositor->DrawQuad(rect, mRect, effectChain, 1.0, identity); |
78 | 0 | } |
79 | | |
80 | | } // end namespace layers |
81 | | } // end namespace mozilla |