blob: bdd6c83396e57e9fd0208740e99bb6dea7907838 [file] [log] [blame]
David Ghandehari9e5b5872016-07-28 09:50:04 -07001// Copyright 2016 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "starboard/blitter.h"
16#include "starboard/nplb/blitter_helpers.h"
17#include "starboard/window.h"
18#include "testing/gtest/include/gtest/gtest.h"
19
20#if SB_HAS(BLITTER)
21
22namespace starboard {
23namespace nplb {
24namespace {
25
26const int kWidth = 128;
27const int kHeight = 128;
28
29TEST(SbBlitterBlitRectToRectTiledTest, SunnyDay) {
30 ContextTestEnvironment env(kWidth, kHeight);
31
32 ASSERT_TRUE(SbBlitterSetRenderTarget(env.context(), env.render_target()));
33
34 SbBlitterSurface surface =
35 CreateArbitraryRenderTargetSurface(env.device(), kWidth, kHeight);
36
37 // Issue a blit command and flush a draw command.
38 EXPECT_TRUE(SbBlitterBlitRectToRectTiled(
39 env.context(), surface, SbBlitterMakeRect(0, 0, kWidth, kHeight),
40 SbBlitterMakeRect(0, 0, kWidth, kHeight)));
41
42 EXPECT_TRUE(SbBlitterFlushContext(env.context()));
43
44 EXPECT_TRUE(SbBlitterDestroySurface(surface));
45}
46
47TEST(SbBlitterBlitRectToRectTiledTest, RainyDayInvalidContext) {
48 ContextTestEnvironment env(kWidth, kHeight);
49
50 ASSERT_TRUE(SbBlitterSetRenderTarget(env.context(), env.render_target()));
51
52 SbBlitterSurface surface =
53 CreateArbitraryRenderTargetSurface(env.device(), kWidth, kHeight);
54
55 // Blitter commands will not succeed when the context is invalid.
56 EXPECT_FALSE(
57 SbBlitterBlitRectToRectTiled(kSbBlitterInvalidContext, surface,
58 SbBlitterMakeRect(0, 0, kWidth, kHeight),
59 SbBlitterMakeRect(0, 0, kWidth, kHeight)));
60
61 EXPECT_TRUE(SbBlitterDestroySurface(surface));
62}
63
64TEST(SbBlitterBlitRectToRectTiledTest, RainyDayNoRenderTarget) {
65 ContextTestEnvironment env(kWidth, kHeight);
66
67 SbBlitterSurface surface =
68 CreateArbitraryRenderTargetSurface(env.device(), kWidth, kHeight);
69
70 // Blit commands will not succeed when there is no render target specified
71 // on the context.
72 EXPECT_FALSE(SbBlitterBlitRectToRectTiled(
73 env.context(), surface, SbBlitterMakeRect(0, 0, kWidth, kHeight),
74 SbBlitterMakeRect(0, 0, kWidth, kHeight)));
75
76 EXPECT_TRUE(SbBlitterDestroySurface(surface));
77}
78
79TEST(SbBlitterBlitRectToRectTiledTest, RainyDayInvalidSourceSurface) {
80 ContextTestEnvironment env(kWidth, kHeight);
81
82 ASSERT_TRUE(SbBlitterSetRenderTarget(env.context(), env.render_target()));
83
84 // Blit commands will not succeed when the source surface is invalid.
85 EXPECT_FALSE(
86 SbBlitterBlitRectToRectTiled(env.context(), kSbBlitterInvalidSurface,
87 SbBlitterMakeRect(0, 0, kWidth, kHeight),
88 SbBlitterMakeRect(0, 0, kWidth, kHeight)));
89}
90
91TEST(SbBlitterBlitRectToRectTiledTest, RainyDayZeroAreaSourceRect) {
92 ContextTestEnvironment env(kWidth, kHeight);
93
94 ASSERT_TRUE(SbBlitterSetRenderTarget(env.context(), env.render_target()));
95
96 SbBlitterSurface surface =
97 CreateArbitraryRenderTargetSurface(env.device(), kWidth, kHeight);
98
99 // Blit commands will not succeed when the source rectangle has an area of 0.
100 EXPECT_FALSE(SbBlitterBlitRectToRectTiled(
101 env.context(), surface, SbBlitterMakeRect(0, 0, 0, 0),
102 SbBlitterMakeRect(0, 0, kWidth, kHeight)));
103
104 EXPECT_TRUE(SbBlitterDestroySurface(surface));
105}
106
107} // namespace
108} // namespace nplb
109} // namespace starboard
110
111#endif // SB_HAS(BLITTER)