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